| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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
    00134   bool hasRenderTarget;
    00135
    00137   void DecomposeColor (int iColor, GLubyte &oR, GLubyte &oG, GLubyte &oB, GLubyte &oA);
    00139   void DecomposeColor (int iColor, float &oR, float &oG, float &oB, float &oA);
    00141   void setGLColorfromint (int color);
    00142
    00143   uint8 *screen_shot;
    00144
    00145   csGLScreenShot* ssPool;
    00146
    00147   csGLScreenShot* GetScreenShot ();
    00148   void RecycleScreenShot (csGLScreenShot* shot);
    00149
    00151   csGLExtensionManager ext;
    00153   //int multiSamples;
    00155   bool multiFavorQuality;
    00157   //int depthBits;
    00158   GLPixelFormat currentFormat;
    00160   csGLDriverDatabase driverdb;
    00161   bool useCombineTE;
    00162
    00163   void GetPixelFormatString (const GLPixelFormat& format, csString& str);
    00164
    00166   void OpenDriverDB (const char* phase = 0);
    00167
    00168   void Report (int severity, const char* msg, ...);
    00169 public:
    00170   virtual const char* GetRendererString (const char* str);
    00171   virtual const char* GetVersionString (const char* ver);
    00172
    00174   csRef<iEventOutlet> EventOutlet;
    00175
    00180   csGraphics2DGLCommon (iBase *iParent);
    00181
    00183   virtual ~csGraphics2DGLCommon ();
    00184
    00185   /*
    00186    * You must supply all the functions not supplied here, such as
    00187    * SetMouseCursor etc. Note also that even though Initialize, Open,
    00188    * and Close are supplied here, you must still override these functions
    00189    * for your own subclass to make system-specific calls for creating and
    00190    * showing windows, etc.
    00191    */
    00192
    00194   virtual bool Initialize (iObjectRegistry *object_reg);
    00195
    00201   virtual bool Open ();
    00202
    00203   virtual void Close ();
    00204
    00205   virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax);
    00206
    00211   virtual bool BeginDraw ();
    00213   virtual void FinishDraw ();
    00214
    00216   virtual bool Resize (int width, int height);
    00217
    00218
    00219   /*
    00220    * the remaining functions here do not need to be overridden when
    00221    * inheriting from this class
    00222    */
    00223
    00225   virtual void Clear (int color);
    00226
    00228   virtual void SetRGB (int i, int r, int g, int b);
    00229   virtual int FindRGB (int r, int g, int b, int a = 255)
    00230   {
    00231     if (r < 0) r = 0; else if (r > 255) r = 255;
    00232     if (g < 0) g = 0; else if (g > 255) g = 255;
    00233     if (b < 0) b = 0; else if (b > 255) b = 255;
    00234     if (a < 0) a = 0; else if (a > 255) a = 255;
    00235     return ((255 - a) << 24) | (r << 16) | (g << 8) | b;
    00236     /* Alpha is "inverted" so '-1' can be decomposed to a
    00237        transparent color. (But alpha not be inverted, '-1'
    00238        would be "opaque white". However, -1 is the color
    00239        index for "transparent text background". */
    00240   }
    00241   virtual void GetRGB (int color, int& r, int& g, int& b)
    00242   {
    00243     r = (color >> 16) & 0xff;
    00244     g = (color >> 8) & 0xff;
    00245     b = color & 0xff;
    00246   }
    00247   virtual void GetRGB (int color, int& r, int& g, int& b, int& a)
    00248   {
    00249     a = 255 - (color >> 24);
    00250     GetRGB (color, r, g, b);
    00251   }
    00252
    00254   virtual void DrawLine (float x1, float y1, float x2, float y2, int color);
    00256   virtual void DrawBox (int x, int y, int w, int h, int color);
    00258   virtual void DrawPixel (int x, int y, int color);
    00260   virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels,
    00261     int color);
    00263   virtual void Blit (int x, int y, int w, int h, unsigned char const* data);
    00264
    00270   virtual unsigned char *GetPixelAt (int x, int y);
    00271
    00273   virtual csPtr<iImage> ScreenShot ();
    00274
    00280   virtual csImageArea *SaveArea (int x, int y, int w, int h);
    00282   virtual void RestoreArea (csImageArea *Area, bool Free = true);
    00283
    00285   virtual bool GetDoubleBufferState ()
    00286   { return false; }
    00288   virtual bool DoubleBuffer (bool Enable)
    00289   { return !Enable; }
    00290
    00292   virtual bool PerformExtensionV (char const* command, va_list);
    00293
    00295   virtual bool DebugCommand (const char* cmd);
    00296
    00299   virtual unsigned GetPotentiallyConflictingEvents ()
    00300   { return CSEVTYPE_Keyboard | CSEVTYPE_Mouse; }
    00301   virtual unsigned QueryEventPriority (unsigned /*iType*/)
    00302   { return 150; }
    00307   void ReadDatabase (iDocumentNode* dbRoot,
    00308     int configPriority = iConfigManager::ConfigPriorityPlugin + 20,
    00309     const char* phase = 0)
    00310   {
    00311     driverdb.Open (this, dbRoot, phase, configPriority);
    00312   }
    00314 };
    00315
    00318 #endif // __CS_GLCOMMON2D_H__