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 namespace CS 00037 { 00038 namespace PluginCommon 00039 { 00040 namespace GL 00041 { 00042 class Graphics2DCommon; 00043 } 00044 } 00045 } 00046 00053 class CS_CSPLUGINCOMMON_GL_EXPORT csGLFontCache : public csFontCache 00054 { 00055 struct GLGlyphCacheData : public csFontCache::GlyphCacheData 00056 { 00057 CS::SubRectangles::SubRect* subrect; 00058 float tx1, ty1, tx2, ty2; 00059 size_t texNum; 00060 csBitmapMetrics bmetrics; 00061 }; 00062 00063 CS::PluginCommon::GL::Graphics2DCommon* G2D; 00064 csGLStateCache* statecache; 00065 00066 int texSize; 00067 size_t maxTxts; 00068 size_t usedTexs; 00069 int glyphAlign; 00070 GLuint texWhite; 00071 /* There are currently 3 ways to draw text: 00072 1) Using a special multitexture setup that blends the FG and BG color. 00073 Preferred, as we save the texture environment switch. 00074 Obviously requires MT. 00075 2) Using ARB_fragment_program. 00076 This is a workaround for a bug in some ATI drivers that seem to garble 00077 text drawing under certain circumstances, which is avoided by using an 00078 AFP instead of a multitexturing setup. 00079 3) Using "Blend" environment which has the same effect as (1). 00080 Not all HW properly supports this. 00081 4) Most ugly: separate passes for FG and BG - needs two textures (one 00082 with background, one with foreground transparency), and doesn't always 00083 look right with AA! (We ignore that until someone complains.) 00084 */ 00085 // Whether to use method 1. 00086 bool multiTexText; 00087 // Whether to use method 2. 00088 bool afpText; 00089 // Whether to use method 3. 00090 bool intensityBlendText; 00091 GLuint textProgram; 00092 00093 struct CacheTexture 00094 { 00095 GLuint handle; 00096 GLuint mirrorHandle; 00097 CS::SubRectangles* glyphRects; 00098 00099 CacheTexture () 00100 { 00101 glyphRects = 0; 00102 } 00103 ~CacheTexture () 00104 { 00105 delete glyphRects; 00106 } 00107 void InitRects (int size) 00108 { 00109 glyphRects = new CS::SubRectangles (csRect (0, 0, size, size)); 00110 } 00111 }; 00112 csArray<CacheTexture> textures; 00113 csBlockAllocator<GLGlyphCacheData> cacheDataAlloc; 00114 00115 struct TextJob 00116 { 00117 GLuint texture; 00118 GLuint mirrorTexture; 00119 int fg, bg; 00120 size_t vertOffset, vertCount, bgVertOffset, bgVertCount; 00121 00122 void ClearRanges() 00123 { 00124 vertOffset = vertCount = bgVertOffset = bgVertCount = 0; 00125 } 00126 }; 00127 csArray<TextJob> jobs; 00128 size_t jobCount; 00129 bool textWriting; 00130 bool needStates; 00131 int envColor; 00132 size_t numFloats; 00133 size_t maxFloats; 00134 bool tcaEnabled, vaEnabled, caEnabled; 00135 csDirtyAccessArray<float, csArrayElementHandler<float>, 00136 CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow<256> > verts2d; 00137 csDirtyAccessArray<float, csArrayElementHandler<float>, 00138 CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow<256> > texcoords; 00139 00140 TextJob& GetJob (int fg, int bg, GLuint texture, GLuint mirrorTexture, 00141 size_t bgOffset); 00142 00143 inline void FlushArrays (); 00144 void BeginText (); 00145 protected: 00146 void Report (int severity, const char* msg, ...); 00147 00148 virtual GlyphCacheData* InternalCacheGlyph (KnownFont* font, 00149 utf32_char glyph, uint flags); 00150 virtual void InternalUncacheGlyph (GlyphCacheData* cacheData); 00151 00152 void CopyGlyphData (iFont* font, utf32_char glyph, size_t tex, 00153 const csBitmapMetrics& bmetrics, const csRect& texRect, 00154 iDataBuffer* bitmapDataBuf, iDataBuffer* alphaDataBuf); 00155 public: 00156 csGLFontCache (CS::PluginCommon::GL::Graphics2DCommon* G2D); 00157 virtual ~csGLFontCache (); 00158 00160 void Setup(); 00161 00165 virtual void WriteString (iFont *font, int pen_x, int pen_y, 00166 int fg, int bg, const void* text, bool isWide, uint flags); 00167 00174 void FlushText (); 00175 00179 void DumpFontCache (csRefArray<iImage>& pages); 00180 }; 00181 00184 #endif // __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__
Generated for Crystal Space 2.1 by doxygen 1.6.1
