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 /* 00088 size_t nextValueIndices[glpfvValueCount]; 00089 csArray<int> values[glpfvValueCount]; 00090 00091 00092 char* order; 00093 size_t orderPos; 00094 size_t orderNum;*/ 00095 00096 // Hold properties for a single pixelformat property 00097 struct PixelFormatPropertySet 00098 { 00099 GLPixelFormatValue valueType; 00100 size_t nextIndex; 00101 size_t firstIndex; 00102 csArray<int> possibleValues; 00103 }; 00104 00105 /* Pixel format properties, however this is _not_ indexed by 00106 GLPixelFormatValue but sorted by order */ 00107 PixelFormatPropertySet pixelFormats[glpfvValueCount]; 00108 00109 // Remapping table from real GLPixelFormatValue to index in table above 00110 size_t pixelFormatIndexTable[glpfvValueCount]; 00111 00112 GLPixelFormat currentValues; 00113 bool currentValid; 00114 00115 void ReadStartValues (); 00116 void ReadPickerValues (); 00117 void ReadPickerValue (const char* valuesStr, csArray<int>& values); 00118 void SetInitialIndices (); 00119 void SetupIndexTable (const char* orderStr); 00120 bool PickNextFormat (); 00121 public: 00122 csGLPixelFormatPicker (csGraphics2DGLCommon* parent); 00123 ~csGLPixelFormatPicker (); 00124 00125 void Reset(); 00126 bool GetNextFormat (GLPixelFormat& format); 00127 }; 00128 friend class csGLPixelFormatPicker; 00129 00131 csGLStateCache* statecache; 00132 csGLStateCacheContext *statecontext; 00133 00135 bool openComplete; 00136 00137 bool hasRenderTarget; 00138 00140 void DecomposeColor (int iColor, GLubyte &oR, GLubyte &oG, GLubyte &oB, GLubyte &oA); 00142 void DecomposeColor (int iColor, float &oR, float &oG, float &oB, float &oA); 00144 void setGLColorfromint (int color); 00145 00146 csGLScreenShot* ssPool; 00147 00148 csGLScreenShot* GetScreenShot (); 00149 void RecycleScreenShot (csGLScreenShot* shot); 00150 00152 csGLExtensionManager ext; 00154 //int multiSamples; 00156 bool multiFavorQuality; 00158 //int depthBits; 00159 GLPixelFormat currentFormat; 00161 csGLDriverDatabase driverdb; 00162 bool useCombineTE; 00163 00164 void GetPixelFormatString (const GLPixelFormat& format, csString& str); 00165 00167 void OpenDriverDB (const char* phase = 0); 00168 00173 bool DrawLineNearClip (csVector3 & v1, csVector3 & v2); 00174 00175 void Report (int severity, const char* msg, ...); 00176 public: 00177 virtual const char* GetRendererString (const char* str); 00178 virtual const char* GetVersionString (const char* ver); 00179 00180 virtual const char* GetHWRenderer(); 00181 virtual const char* GetHWGLVersion(); 00182 virtual const char* GetHWVendor(); 00183 00185 csRef<iEventOutlet> EventOutlet; 00186 00191 csGraphics2DGLCommon (iBase *iParent); 00192 00194 virtual ~csGraphics2DGLCommon (); 00195 00196 /* 00197 * You must supply all the functions not supplied here, such as 00198 * SetMouseCursor etc. Note also that even though Initialize, Open, 00199 * and Close are supplied here, you must still override these functions 00200 * for your own subclass to make system-specific calls for creating and 00201 * showing windows, etc. 00202 */ 00203 00205 virtual bool Initialize (iObjectRegistry *object_reg); 00206 00212 virtual bool Open (); 00213 00214 virtual void Close (); 00215 00216 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00217 00222 virtual bool BeginDraw (); 00224 virtual void FinishDraw (); 00225 00227 virtual bool Resize (int width, int height); 00228 00229 00230 /* 00231 * the remaining functions here do not need to be overridden when 00232 * inheriting from this class 00233 */ 00234 00236 virtual void Clear (int color); 00237 00239 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00241 virtual void DrawLineProjected (const csVector3& v1, const csVector3& v2, 00242 float fov, int color); 00244 virtual void DrawLineProjected (const csVector3& v1, const csVector3& v2, 00245 const CS::Math::Matrix4& projection, int color); 00247 virtual void DrawBox (int x, int y, int w, int h, int color); 00249 virtual void DrawPixel (int x, int y, int color); 00251 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00252 int color); 00254 virtual void Blit (int x, int y, int w, int h, unsigned char const* data); 00255 00257 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB); 00259 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA); 00260 00262 virtual csPtr<iImage> ScreenShot (); 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 00277 void SetViewport (int left, int top, int width, int height); 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, phase, configPriority); 00294 } 00296 }; 00297 00300 #endif // __CS_GLCOMMON2D_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1
