CrystalSpace

Public API Reference

csplugincommon/opengl/glfontcache.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2003 by Jorrit Tyberghein
00003               (C) 2003 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__
00021 #define __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__
00022 
00027 #include "csextern_gl.h"
00028 #include "csgeom/subrec.h"
00029 #include "csgeom/vector2.h"
00030 #include "csutil/dirtyaccessarray.h"
00031 #include "csutil/refarr.h"
00032 #include "csplugincommon/canvas/fontcache.h"
00033 
00034 class csGLStateCache;
00035 
00036 class csGraphics2DGLCommon;
00037 
00044 class CS_CSPLUGINCOMMON_GL_EXPORT csGLFontCache : public csFontCache
00045 {
00046   struct GLGlyphCacheData : public csFontCache::GlyphCacheData
00047   {
00048     csSubRect* subrect;
00049     float tx1, ty1, tx2, ty2;
00050     size_t texNum;
00051     csBitmapMetrics bmetrics;
00052   };
00053 
00054   csGraphics2DGLCommon* G2D;
00055   csGLStateCache* statecache;
00056 
00057   int texSize;
00058   size_t maxTxts;
00059   size_t usedTexs;
00060   int glyphAlign;
00061   GLuint texWhite;
00062   /* There are currently 3 ways to draw text:
00063      1) Using a special multitexture setup that blends the FG and BG color.
00064         Preferred, as we save the texture environment switch.
00065         Obviously requires MT.
00066      2) Using ARB_fragment_program.
00067         This is a workaround for a bug in some ATI drivers that seem to garble
00068         text drawing under certain circumstances, which is avoided by using an
00069         AFP instead of a multitexturing setup.
00070      3) Using "Blend" environment which has the same effect as (1).
00071         Not all HW properly supports this.
00072      4) Most ugly: separate passes for FG and BG - needs two textures (one 
00073         with background, one with foreground transparency), and doesn't always 
00074         look right with AA! (We ignore that until someone complains.)
00075    */
00076   // Whether to use method 1.
00077   bool multiTexText;
00078   // Whether to use method 2.
00079   bool afpText;
00080   // Whether to use method 3.
00081   bool intensityBlendText;
00082   GLuint textProgram;
00083 
00084   struct CacheTexture
00085   {
00086     GLuint handle;
00087     GLuint mirrorHandle;
00088     csSubRectangles* glyphRects;
00089 
00090     CacheTexture () 
00091     { 
00092       glyphRects = 0; 
00093     }
00094     ~CacheTexture () 
00095     { 
00096       delete glyphRects; 
00097     }
00098     void InitRects (int size) 
00099     { 
00100       glyphRects = new csSubRectangles (csRect (0, 0, size, size));
00101     }
00102   };
00103   csArray<CacheTexture> textures;
00104   csBlockAllocator<GLGlyphCacheData> cacheDataAlloc;
00105 
00106   struct TextJob
00107   {
00108     GLuint texture;
00109     GLuint mirrorTexture;
00110     int fg, bg;
00111     size_t vertOffset, vertCount, bgVertOffset, bgVertCount;
00112 
00113     void ClearRanges()
00114     {
00115       vertOffset = vertCount = bgVertOffset = bgVertCount = 0;
00116     }
00117   };
00118   csArray<TextJob> jobs;
00119   size_t jobCount;
00120   bool textWriting;
00121   bool needStates;
00122   int envColor;
00123   size_t numFloats;
00124   size_t maxFloats;
00125   bool tcaEnabled, vaEnabled, caEnabled;
00126   csDirtyAccessArray<float> verts2d;
00127   csDirtyAccessArray<float> texcoords;
00128 
00129   TextJob& GetJob (int fg, int bg, GLuint texture, GLuint mirrorTexture, 
00130     size_t bgOffset);
00131 
00132   inline void FlushArrays ();
00133   void BeginText ();
00134 protected:
00135   void Report (int severity, const char* msg, ...);
00136 
00137   virtual GlyphCacheData* InternalCacheGlyph (KnownFont* font,
00138     utf32_char glyph, uint flags);
00139   virtual void InternalUncacheGlyph (GlyphCacheData* cacheData);
00140 
00141   void CopyGlyphData (iFont* font, utf32_char glyph, size_t tex, 
00142     const csBitmapMetrics& bmetrics, const csRect& texRect, 
00143     iDataBuffer* bitmapDataBuf, iDataBuffer* alphaDataBuf);
00144 public:
00145   csGLFontCache (csGraphics2DGLCommon* G2D);
00146   virtual ~csGLFontCache ();
00147 
00149   void Setup();
00150 
00154   virtual void WriteString (iFont *font, int pen_x, int pen_y, 
00155     int fg, int bg, const void* text, bool isWide, uint flags);
00156 
00163   void FlushText ();
00164 
00168   void DumpFontCache (csRefArray<iImage>& pages);
00169 };
00170 
00173 #endif // __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__

Generated for Crystal Space by doxygen 1.4.7