00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00089
00090
00091
00092
00093
00094
00095
00096
00097 struct PixelFormatPropertySet
00098 {
00099 GLPixelFormatValue valueType;
00100 size_t nextIndex;
00101 size_t firstIndex;
00102 csArray<int> possibleValues;
00103 };
00104
00105
00106
00107 PixelFormatPropertySet pixelFormats[glpfvValueCount];
00108
00109
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
00156 bool multiFavorQuality;
00158
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
00198
00199
00200
00201
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
00232
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 )
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__