CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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.h"
00029 #include "csutil/scf.h"
00030 #include "csplugincommon/canvas/graph2d.h"
00031 #include "glfontcache.h"
00032 #include "iutil/event.h"
00033 #include "glstates.h"
00034 #include "glextmanager.h"
00035 #include "glss.h"
00036 #include "driverdb.h"
00037 
00038 class OpenGLTextureCache;
00039 class GLFontCache;
00040 
00052 class CS_CSPLUGINCOMMON_OGL_EXPORT csGraphics2DGLCommon : public csGraphics2D, 
00053                                                            public iEventPlug
00054 {
00055 public:
00056   enum GLPixelFormatValue
00057   {
00058     glpfvColorBits = 0,
00059     glpfvAlphaBits,
00060     glpfvDepthBits,
00061     glpfvStencilBits,
00062     glpfvAccumColorBits,
00063     glpfvAccumAlphaBits,
00064     glpfvMultiSamples,
00065 
00066     glpfvValueCount
00067   };
00068   typedef int GLPixelFormat[glpfvValueCount];
00069 protected:
00070   friend class csGLScreenShot;
00071   friend class csGLFontCache;
00072   
00073   class CS_CSPLUGINCOMMON_OGL_EXPORT csGLPixelFormatPicker
00074   {
00075     csGraphics2DGLCommon* parent;
00076 
00077     GLPixelFormat currentValues;
00078     size_t nextValueIndices[glpfvValueCount];
00079     csArray<int> values[glpfvValueCount];
00080     bool currentValid;
00081 
00082     char* order;
00083     size_t orderPos;
00084     size_t orderNum;
00085 
00086     void ReadStartValues ();
00087     void ReadPickerValues ();
00088     void ReadPickerValue (const char* valuesStr, csArray<int>& values);
00089     void SetInitialIndices ();
00090     bool PickNextFormat ();
00091   public:
00092     csGLPixelFormatPicker (csGraphics2DGLCommon* parent);
00093     ~csGLPixelFormatPicker ();
00094 
00095     void Reset();
00096     bool GetNextFormat (GLPixelFormat& format);
00097   };
00098   friend class csGLPixelFormatPicker;
00099 
00101   csGLStateCache* statecache;
00102   csGLStateCacheContext *statecontext;
00103 
00104   bool hasRenderTarget;
00105 
00107   void DecomposeColor (int iColor, GLubyte &oR, GLubyte &oG, GLubyte &oB, GLubyte &oA);
00109   void DecomposeColor (int iColor, float &oR, float &oG, float &oB, float &oA);
00111   void setGLColorfromint (int color);
00112 
00113   uint8 *screen_shot;
00114 
00115   csGLScreenShot* ssPool;
00116 
00117   csGLScreenShot* GetScreenShot ();
00118   void RecycleScreenShot (csGLScreenShot* shot);
00119 
00121   csGLExtensionManager ext;
00123   //int multiSamples;
00125   bool multiFavorQuality;
00127   //int depthBits;
00128   GLPixelFormat currentFormat;
00130   csGLDriverDatabase driverdb;
00131   bool useCombineTE;
00132 
00133   void GetPixelFormatString (const GLPixelFormat& format, csString& str);
00134 public:
00135   virtual const char* GetRendererString (const char* str);
00136   virtual const char* GetVersionString (const char* ver);
00137 
00138   SCF_DECLARE_IBASE_EXT(csGraphics2D);
00139 
00141   csRef<iEventOutlet> EventOutlet;
00142 
00147   csGraphics2DGLCommon (iBase *iParent);
00148 
00150   virtual ~csGraphics2DGLCommon ();
00151 
00152   /*
00153    * You must supply all the functions not supplied here, such as
00154    * SetMouseCursor etc. Note also that even though Initialize, Open,
00155    * and Close are supplied here, you must still override these functions
00156    * for your own subclass to make system-specific calls for creating and
00157    * showing windows, etc.
00158    */
00159 
00161   virtual bool Initialize (iObjectRegistry *object_reg);
00162 
00168   virtual bool Open ();
00169 
00170   virtual void Close ();
00171 
00172   virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax);
00173 
00178   virtual bool BeginDraw ();
00180   virtual void FinishDraw ();
00181 
00183   virtual bool Resize (int width, int height);
00184 
00185 
00186   /*
00187    * the remaining functions here do not need to be overridden when
00188    * inheriting from this class
00189    */
00190 
00192   virtual void Clear (int color);
00193 
00195   virtual void SetRGB (int i, int r, int g, int b);
00196   virtual int FindRGB (int r, int g, int b, int a = 255)
00197   {
00198     if (r < 0) r = 0; else if (r > 255) r = 255;
00199     if (g < 0) g = 0; else if (g > 255) g = 255;
00200     if (b < 0) b = 0; else if (b > 255) b = 255;
00201     if (a < 0) a = 0; else if (a > 255) a = 255;
00202     return ((255 - a) << 24) | (r << 16) | (g << 8) | b;
00203     /* Alpha is "inverted" so '-1' can be decomposed to a 
00204        transparent color. (But alpha not be inverted, '-1'
00205        would be "opaque white". However, -1 is the color
00206        index for "transparent text background". */
00207   }
00208   virtual void GetRGB (int color, int& r, int& g, int& b)
00209   {
00210     r = (color >> 16) & 0xff;
00211     g = (color >> 8) & 0xff;
00212     b = color & 0xff;
00213   }
00214   virtual void GetRGB (int color, int& r, int& g, int& b, int& a)
00215   {
00216     a = 255 - (color >> 24);
00217     GetRGB (color, r, g, b);
00218   }
00219 
00221   virtual void DrawLine (float x1, float y1, float x2, float y2, int color);
00223   virtual void DrawBox (int x, int y, int w, int h, int color);
00225   virtual void DrawPixel (int x, int y, int color);
00227   virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels,
00228     int color);
00230   virtual void Blit (int x, int y, int w, int h, unsigned char const* data);
00231 
00237   virtual unsigned char *GetPixelAt (int x, int y);
00238 
00240   virtual csPtr<iImage> ScreenShot ();
00241 
00247   virtual csImageArea *SaveArea (int x, int y, int w, int h);
00249   virtual void RestoreArea (csImageArea *Area, bool Free = true);
00250 
00252   virtual bool GetDoubleBufferState ()
00253   { return false; }
00255   virtual bool DoubleBuffer (bool Enable)
00256   { return !Enable; }
00257 
00259   virtual bool PerformExtensionV (char const* command, va_list);
00260 
00262   virtual bool DebugCommand (const char* cmd);
00263 
00264   //------------------------ iEventPlug interface ---------------------------//
00265 
00266   virtual unsigned GetPotentiallyConflictingEvents ()
00267   { return CSEVTYPE_Keyboard | CSEVTYPE_Mouse; }
00268   virtual unsigned QueryEventPriority (unsigned /*iType*/)
00269   { return 150; }
00270 };
00271 
00272 #endif // __CS_GLCOMMON2D_H__

Generated for Crystal Space by doxygen 1.3.9.1