csplugincommon/opengl/glcommon2d.h
Go to the documentation of this file.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 00026 #if defined(CS_OPENGL_PATH) 00027 #include CS_HEADER_GLOBAL(CS_OPENGL_PATH,gl.h) 00028 #else 00029 #include <GL/gl.h> 00030 #endif 00031 00032 #include "csextern_gl.h" 00033 #include "csutil/scf.h" 00034 #include "csplugincommon/canvas/graph2d.h" 00035 #include "csplugincommon/iopengl/driverdb.h" 00036 #include "glfontcache.h" 00037 #include "iutil/event.h" 00038 #include "glstates.h" 00039 #include "glextmanager.h" 00040 #include "glss.h" 00041 #include "driverdb.h" 00042 00043 class OpenGLTextureCache; 00044 class GLFontCache; 00045 00059 class CS_CSPLUGINCOMMON_GL_EXPORT csGraphics2DGLCommon : 00060 public scfImplementationExt2<csGraphics2DGLCommon, 00061 csGraphics2D, 00062 iEventPlug, 00063 iOpenGLDriverDatabase> 00064 { 00065 public: 00066 enum GLPixelFormatValue 00067 { 00068 glpfvColorBits = 0, 00069 glpfvAlphaBits, 00070 glpfvDepthBits, 00071 glpfvStencilBits, 00072 glpfvAccumColorBits, 00073 glpfvAccumAlphaBits, 00074 glpfvMultiSamples, 00075 00076 glpfvValueCount 00077 }; 00078 typedef int GLPixelFormat[glpfvValueCount]; 00079 protected: 00080 friend class csGLScreenShot; 00081 friend class csGLFontCache; 00082 00083 class CS_CSPLUGINCOMMON_GL_EXPORT csGLPixelFormatPicker 00084 { 00085 csGraphics2DGLCommon* parent; 00086 00087 GLPixelFormat currentValues; 00088 size_t nextValueIndices[glpfvValueCount]; 00089 csArray<int> values[glpfvValueCount]; 00090 bool currentValid; 00091 00092 char* order; 00093 size_t orderPos; 00094 size_t orderNum; 00095 00096 void ReadStartValues (); 00097 void ReadPickerValues (); 00098 void ReadPickerValue (const char* valuesStr, csArray<int>& values); 00099 void SetInitialIndices (); 00100 bool PickNextFormat (); 00101 public: 00102 csGLPixelFormatPicker (csGraphics2DGLCommon* parent); 00103 ~csGLPixelFormatPicker (); 00104 00105 void Reset(); 00106 bool GetNextFormat (GLPixelFormat& format); 00107 }; 00108 friend class csGLPixelFormatPicker; 00109 00111 csGLStateCache* statecache; 00112 csGLStateCacheContext *statecontext; 00113 00114 bool hasRenderTarget; 00115 00117 void DecomposeColor (int iColor, GLubyte &oR, GLubyte &oG, GLubyte &oB, GLubyte &oA); 00119 void DecomposeColor (int iColor, float &oR, float &oG, float &oB, float &oA); 00121 void setGLColorfromint (int color); 00122 00123 uint8 *screen_shot; 00124 00125 csGLScreenShot* ssPool; 00126 00127 csGLScreenShot* GetScreenShot (); 00128 void RecycleScreenShot (csGLScreenShot* shot); 00129 00131 csGLExtensionManager ext; 00133 //int multiSamples; 00135 bool multiFavorQuality; 00137 //int depthBits; 00138 GLPixelFormat currentFormat; 00140 csGLDriverDatabase driverdb; 00141 bool useCombineTE; 00142 00143 void GetPixelFormatString (const GLPixelFormat& format, csString& str); 00144 00146 void OpenDriverDB (const char* phase = 0); 00147 00148 void Report (int severity, const char* msg, ...); 00149 public: 00150 virtual const char* GetRendererString (const char* str); 00151 virtual const char* GetVersionString (const char* ver); 00152 00154 csRef<iEventOutlet> EventOutlet; 00155 00160 csGraphics2DGLCommon (iBase *iParent); 00161 00163 virtual ~csGraphics2DGLCommon (); 00164 00165 /* 00166 * You must supply all the functions not supplied here, such as 00167 * SetMouseCursor etc. Note also that even though Initialize, Open, 00168 * and Close are supplied here, you must still override these functions 00169 * for your own subclass to make system-specific calls for creating and 00170 * showing windows, etc. 00171 */ 00172 00174 virtual bool Initialize (iObjectRegistry *object_reg); 00175 00181 virtual bool Open (); 00182 00183 virtual void Close (); 00184 00185 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00186 00191 virtual bool BeginDraw (); 00193 virtual void FinishDraw (); 00194 00196 virtual bool Resize (int width, int height); 00197 00198 00199 /* 00200 * the remaining functions here do not need to be overridden when 00201 * inheriting from this class 00202 */ 00203 00205 virtual void Clear (int color); 00206 00208 virtual void SetRGB (int i, int r, int g, int b); 00209 virtual int FindRGB (int r, int g, int b, int a = 255) 00210 { 00211 if (r < 0) r = 0; else if (r > 255) r = 255; 00212 if (g < 0) g = 0; else if (g > 255) g = 255; 00213 if (b < 0) b = 0; else if (b > 255) b = 255; 00214 if (a < 0) a = 0; else if (a > 255) a = 255; 00215 return ((255 - a) << 24) | (r << 16) | (g << 8) | b; 00216 /* Alpha is "inverted" so '-1' can be decomposed to a 00217 transparent color. (But alpha not be inverted, '-1' 00218 would be "opaque white". However, -1 is the color 00219 index for "transparent text background". */ 00220 } 00221 virtual void GetRGB (int color, int& r, int& g, int& b) 00222 { 00223 r = (color >> 16) & 0xff; 00224 g = (color >> 8) & 0xff; 00225 b = color & 0xff; 00226 } 00227 virtual void GetRGB (int color, int& r, int& g, int& b, int& a) 00228 { 00229 a = 255 - (color >> 24); 00230 GetRGB (color, r, g, b); 00231 } 00232 00234 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00236 virtual void DrawBox (int x, int y, int w, int h, int color); 00238 virtual void DrawPixel (int x, int y, int color); 00240 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00241 int color); 00243 virtual void Blit (int x, int y, int w, int h, unsigned char const* data); 00244 00250 virtual unsigned char *GetPixelAt (int x, int y); 00251 00253 virtual csPtr<iImage> ScreenShot (); 00254 00260 virtual csImageArea *SaveArea (int x, int y, int w, int h); 00262 virtual void RestoreArea (csImageArea *Area, bool Free = true); 00263 00265 virtual bool GetDoubleBufferState () 00266 { return false; } 00268 virtual bool DoubleBuffer (bool Enable) 00269 { return !Enable; } 00270 00272 virtual bool PerformExtensionV (char const* command, va_list); 00273 00275 virtual bool DebugCommand (const char* cmd); 00276 00279 virtual unsigned GetPotentiallyConflictingEvents () 00280 { return CSEVTYPE_Keyboard | CSEVTYPE_Mouse; } 00281 virtual unsigned QueryEventPriority (unsigned /*iType*/) 00282 { return 150; } 00287 void ReadDatabase (iDocumentNode* dbRoot, 00288 int configPriority = iConfigManager::ConfigPriorityPlugin + 20, 00289 const char* phase = 0) 00290 { 00291 driverdb.Open (this, dbRoot, phase, configPriority); 00292 } 00294 }; 00295 00298 #endif // __CS_GLCOMMON2D_H__
Generated for Crystal Space by doxygen 1.4.6