Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
glfontcache.h
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 00023 #include "csextern.h" 00024 #include "csgeom/subrec2.h" 00025 #include "csgeom/vector2.h" 00026 #include "csutil/dirtyaccessarray.h" 00027 00028 #include "csplugincommon/canvas/fontcache.h" 00029 00030 class csGLStateCache; 00031 00032 class csGraphics2DGLCommon; 00033 00034 class CS_CSPLUGINCOMMON_OGL_EXPORT csGLFontCache : public csFontCache 00035 { 00036 struct GLGlyphCacheData : public csFontCache::GlyphCacheData 00037 { 00038 csSubRect2* subrect; 00039 float tx1, ty1, tx2, ty2; 00040 size_t texNum; 00041 csBitmapMetrics bmetrics; 00042 }; 00043 00044 csGraphics2DGLCommon* G2D; 00045 csGLStateCache* statecache; 00046 00047 int texSize; 00048 size_t maxTxts; 00049 size_t usedTexs; 00050 int glyphAlign; 00051 GLuint texWhite; 00052 /* There are currently 3 ways to draw text: 00053 1) Using a special multitexture setup that blends the FG and BG color. 00054 Preferred, as we save the texture environment switch. 00055 Obviously requires MT. 00056 2) Using "Blend" environment which has the same effect as (1). 00057 Not all HW properly supports this. 00058 3) Most ugly: separate passes for FG and BG - needs two textures (one 00059 with background, one with foreground transparency), and doesn't always 00060 look right with AA! (We ignore that until someone complains.) 00061 */ 00062 // Whether to use method 1. 00063 bool multiTexText; 00064 // Whether to use method 2. 00065 bool intensityBlendText; 00066 00067 struct CacheTexture 00068 { 00069 GLuint handle; 00070 GLuint mirrorHandle; 00071 csSubRectangles2* glyphRects; 00072 00073 CacheTexture () 00074 { 00075 glyphRects = 0; 00076 } 00077 ~CacheTexture () 00078 { 00079 delete glyphRects; 00080 } 00081 void InitRects (int size) 00082 { 00083 glyphRects = new csSubRectangles2 (csRect (0, 0, size, size)); 00084 } 00085 }; 00086 csArray<CacheTexture> textures; 00087 csBlockAllocator<GLGlyphCacheData> cacheDataAlloc; 00088 00089 struct TextJob 00090 { 00091 GLuint texture; 00092 GLuint mirrorTexture; 00093 int fg, bg; 00094 size_t vertOffset, vertCount, bgVertOffset, bgVertCount; 00095 00096 void ClearRanges() 00097 { 00098 vertOffset = vertCount = bgVertOffset = bgVertCount = 0; 00099 } 00100 }; 00101 csArray<TextJob> jobs; 00102 size_t jobCount; 00103 bool textWriting; 00104 bool needStates; 00105 int envColor; 00106 size_t numFloats; 00107 size_t maxFloats; 00108 bool tcaEnabled, vaEnabled, caEnabled; 00109 csDirtyAccessArray<float> verts2d; 00110 csDirtyAccessArray<float> texcoords; 00111 00112 TextJob& GetJob (int fg, int bg, GLuint texture, GLuint mirrorTexture, 00113 size_t bgOffset); 00114 00115 inline void FlushArrays (); 00116 void BeginText (); 00117 protected: 00118 virtual GlyphCacheData* InternalCacheGlyph (KnownFont* font, 00119 utf32_char glyph, uint flags); 00120 virtual void InternalUncacheGlyph (GlyphCacheData* cacheData); 00121 00122 void CopyGlyphData (iFont* font, utf32_char glyph, size_t tex, 00123 const csBitmapMetrics& bmetrics, const csRect& texRect, 00124 iDataBuffer* bitmapDataBuf, iDataBuffer* alphaDataBuf); 00125 public: 00126 csGLFontCache (csGraphics2DGLCommon* G2D); 00127 virtual ~csGLFontCache (); 00128 00130 void Setup(); 00131 00135 virtual void WriteString (iFont *font, int pen_x, int pen_y, 00136 int fg, int bg, const utf8_char* text, uint flags); 00137 00144 void FlushText (); 00145 00149 void DumpFontCache (csRefArray<iImage>& pages); 00150 }; 00151 00152 #endif // __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__
Generated for Crystal Space by doxygen 1.3.9.1