Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 CS::SubRectangles::SubRect* 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
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 bool multiTexText;
00078
00079 bool afpText;
00080
00081 bool intensityBlendText;
00082 GLuint textProgram;
00083
00084 struct CacheTexture
00085 {
00086 GLuint handle;
00087 GLuint mirrorHandle;
00088 CS::SubRectangles* 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 CS::SubRectangles (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, csArrayElementHandler<float>,
00127 CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow<256> > verts2d;
00128 csDirtyAccessArray<float, csArrayElementHandler<float>,
00129 CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow<256> > texcoords;
00130
00131 TextJob& GetJob (int fg, int bg, GLuint texture, GLuint mirrorTexture,
00132 size_t bgOffset);
00133
00134 inline void FlushArrays ();
00135 void BeginText ();
00136 protected:
00137 void Report (int severity, const char* msg, ...);
00138
00139 virtual GlyphCacheData* InternalCacheGlyph (KnownFont* font,
00140 utf32_char glyph, uint flags);
00141 virtual void InternalUncacheGlyph (GlyphCacheData* cacheData);
00142
00143 void CopyGlyphData (iFont* font, utf32_char glyph, size_t tex,
00144 const csBitmapMetrics& bmetrics, const csRect& texRect,
00145 iDataBuffer* bitmapDataBuf, iDataBuffer* alphaDataBuf);
00146 public:
00147 csGLFontCache (csGraphics2DGLCommon* G2D);
00148 virtual ~csGLFontCache ();
00149
00151 void Setup();
00152
00156 virtual void WriteString (iFont *font, int pen_x, int pen_y,
00157 int fg, int bg, const void* text, bool isWide, uint flags);
00158
00165 void FlushText ();
00166
00170 void DumpFontCache (csRefArray<iImage>& pages);
00171 };
00172
00175 #endif // __CS_CANVAS_OPENGLCOMMON_GLFONTCACHE_H__