Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
glcommon2d.h
00001 /* 00002 Copyright (C) 1998 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_GLCOMMON2D_H__ 00020 #define __CS_GLCOMMON2D_H__ 00021 00022 #if defined(CS_OPENGL_PATH) 00023 #include CS_HEADER_GLOBAL(CS_OPENGL_PATH,gl.h) 00024 #else 00025 #include <GL/gl.h> 00026 #endif 00027 00028 #include "csextern_gl.h" 00029 #include "csutil/scf.h" 00030 #include "csplugincommon/canvas/graph2d.h" 00031 #include "csplugincommon/iopengl/driverdb.h" 00032 #include "glfontcache.h" 00033 #include "iutil/event.h" 00034 #include "glstates.h" 00035 #include "glextmanager.h" 00036 #include "glss.h" 00037 #include "driverdb.h" 00038 00039 class OpenGLTextureCache; 00040 class GLFontCache; 00041 00053 class CS_CSPLUGINCOMMON_GL_EXPORT csGraphics2DGLCommon : 00054 public scfImplementationExt2<csGraphics2DGLCommon, 00055 csGraphics2D, 00056 iEventPlug, 00057 iGLDriverDatabase> 00058 { 00059 public: 00060 enum GLPixelFormatValue 00061 { 00062 glpfvColorBits = 0, 00063 glpfvAlphaBits, 00064 glpfvDepthBits, 00065 glpfvStencilBits, 00066 glpfvAccumColorBits, 00067 glpfvAccumAlphaBits, 00068 glpfvMultiSamples, 00069 00070 glpfvValueCount 00071 }; 00072 typedef int GLPixelFormat[glpfvValueCount]; 00073 protected: 00074 friend class csGLScreenShot; 00075 friend class csGLFontCache; 00076 00077 class CS_CSPLUGINCOMMON_GL_EXPORT csGLPixelFormatPicker 00078 { 00079 csGraphics2DGLCommon* parent; 00080 00081 GLPixelFormat currentValues; 00082 size_t nextValueIndices[glpfvValueCount]; 00083 csArray<int> values[glpfvValueCount]; 00084 bool currentValid; 00085 00086 char* order; 00087 size_t orderPos; 00088 size_t orderNum; 00089 00090 void ReadStartValues (); 00091 void ReadPickerValues (); 00092 void ReadPickerValue (const char* valuesStr, csArray<int>& values); 00093 void SetInitialIndices (); 00094 bool PickNextFormat (); 00095 public: 00096 csGLPixelFormatPicker (csGraphics2DGLCommon* parent); 00097 ~csGLPixelFormatPicker (); 00098 00099 void Reset(); 00100 bool GetNextFormat (GLPixelFormat& format); 00101 }; 00102 friend class csGLPixelFormatPicker; 00103 00105 csGLStateCache* statecache; 00106 csGLStateCacheContext *statecontext; 00107 00108 bool hasRenderTarget; 00109 00111 void DecomposeColor (int iColor, GLubyte &oR, GLubyte &oG, GLubyte &oB, GLubyte &oA); 00113 void DecomposeColor (int iColor, float &oR, float &oG, float &oB, float &oA); 00115 void setGLColorfromint (int color); 00116 00117 uint8 *screen_shot; 00118 00119 csGLScreenShot* ssPool; 00120 00121 csGLScreenShot* GetScreenShot (); 00122 void RecycleScreenShot (csGLScreenShot* shot); 00123 00125 csGLExtensionManager ext; 00127 //int multiSamples; 00129 bool multiFavorQuality; 00131 //int depthBits; 00132 GLPixelFormat currentFormat; 00134 csGLDriverDatabase driverdb; 00135 bool useCombineTE; 00136 00137 int vpWidth, vpHeight; 00138 bool vpSet; 00139 00140 void GetPixelFormatString (const GLPixelFormat& format, csString& str); 00141 00143 void OpenDriverDB (const char* phase = 0); 00144 00145 void Report (int severity, const char* msg, ...); 00146 public: 00147 virtual const char* GetRendererString (const char* str); 00148 virtual const char* GetVersionString (const char* ver); 00149 00151 csRef<iEventOutlet> EventOutlet; 00152 00157 csGraphics2DGLCommon (iBase *iParent); 00158 00160 virtual ~csGraphics2DGLCommon (); 00161 00162 /* 00163 * You must supply all the functions not supplied here, such as 00164 * SetMouseCursor etc. Note also that even though Initialize, Open, 00165 * and Close are supplied here, you must still override these functions 00166 * for your own subclass to make system-specific calls for creating and 00167 * showing windows, etc. 00168 */ 00169 00171 virtual bool Initialize (iObjectRegistry *object_reg); 00172 00178 virtual bool Open (); 00179 00180 virtual void Close (); 00181 00182 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00183 00188 virtual bool BeginDraw (); 00190 virtual void FinishDraw (); 00191 00193 virtual bool Resize (int width, int height); 00194 00195 00196 /* 00197 * the remaining functions here do not need to be overridden when 00198 * inheriting from this class 00199 */ 00200 00202 virtual void Clear (int color); 00203 00205 virtual void SetRGB (int i, int r, int g, int b); 00206 virtual int FindRGB (int r, int g, int b, int a = 255) 00207 { 00208 if (r < 0) r = 0; else if (r > 255) r = 255; 00209 if (g < 0) g = 0; else if (g > 255) g = 255; 00210 if (b < 0) b = 0; else if (b > 255) b = 255; 00211 if (a < 0) a = 0; else if (a > 255) a = 255; 00212 return ((255 - a) << 24) | (r << 16) | (g << 8) | b; 00213 /* Alpha is "inverted" so '-1' can be decomposed to a 00214 transparent color. (But alpha not be inverted, '-1' 00215 would be "opaque white". However, -1 is the color 00216 index for "transparent text background". */ 00217 } 00218 virtual void GetRGB (int color, int& r, int& g, int& b) 00219 { 00220 r = (color >> 16) & 0xff; 00221 g = (color >> 8) & 0xff; 00222 b = color & 0xff; 00223 } 00224 virtual void GetRGB (int color, int& r, int& g, int& b, int& a) 00225 { 00226 a = 255 - (color >> 24); 00227 GetRGB (color, r, g, b); 00228 } 00229 00231 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00233 virtual void DrawBox (int x, int y, int w, int h, int color); 00235 virtual void DrawPixel (int x, int y, int color); 00237 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00238 int color); 00240 virtual void Blit (int x, int y, int w, int h, unsigned char const* data); 00241 00242 virtual int GetWidth () 00243 { return vpSet ? vpWidth : Width; } 00244 virtual int GetHeight () 00245 { return vpSet ? vpHeight : Height; } 00246 00252 virtual unsigned char *GetPixelAt (int x, int y); 00253 00255 virtual csPtr<iImage> ScreenShot (); 00256 00262 virtual csImageArea *SaveArea (int x, int y, int w, int h); 00264 virtual void RestoreArea (csImageArea *Area, bool Free = true); 00265 00267 virtual bool GetDoubleBufferState () 00268 { return false; } 00270 virtual bool DoubleBuffer (bool Enable) 00271 { return !Enable; } 00272 00274 virtual bool PerformExtensionV (char const* command, va_list); 00275 00277 virtual bool DebugCommand (const char* cmd); 00278 00281 virtual unsigned GetPotentiallyConflictingEvents () 00282 { return CSEVTYPE_Keyboard | CSEVTYPE_Mouse; } 00283 virtual unsigned QueryEventPriority (unsigned /*iType*/) 00284 { return 150; } 00289 void ReadDatabase (iDocumentNode* dbRoot, 00290 int configPriority = iConfigManager::ConfigPriorityPlugin + 20, 00291 const char* phase = 0) 00292 { 00293 driverdb.Open (this, dbRoot, 0, configPriority); 00294 } 00296 }; 00297 00298 #endif // __CS_GLCOMMON2D_H__
Generated for Crystal Space by doxygen 1.4.4