22 #ifndef STLL_LAYOUTER_OPEN_GL
23 #define STLL_LAYOUTER_OPEN_GL
32 #include "internal/glyphAtlas.h"
33 #include "internal/gamma.h"
34 #include "internal/openGL_internal.h"
66 template <
int V,
class G =
internal::Gamma_c<>>
70 internal::GlyphAtlas_c cache;
73 GLuint glTextureId = 0;
74 uint32_t uploadVersion = 0;
84 using DrawCache_c =
typename internal::openGL_internals<V>::DrawCacheInternal_c;
94 showOpenGL(uint32_t cStart = 256, uint32_t cMax = 1024) : cache(cStart, cStart), cacheMax(cMax)
96 glActiveTexture(GL_TEXTURE0);
97 glGenTextures(1, &glTextureId);
98 glBindTexture(GL_TEXTURE_2D, glTextureId);
99 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
103 glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
106 internal::openGL_internals<V>::setup();
111 glDeleteTextures(1, &glTextureId);
112 internal::openGL_internals<V>::cleanup();
119 virtual void draw(int32_t x, int32_t y, uint32_t w, uint32_t h,
const std::string & url) = 0;
140 glActiveTexture(GL_TEXTURE0);
141 glBindTexture( GL_TEXTURE_2D, glTextureId );
144 if (dc && dc->atlasId == atlasId)
146 internal::openGL_internals<V>::drawCache(*dc, sp, sx, sy, cache.width());
150 const auto & dat = l.
getData();
152 bool cleared =
false;
154 while (i < dat.size())
162 while (j < dat.size())
172 found &= (bool)cache.getGlyph(ii.font, ii.glyphIndex, sp, ii.blurr);
176 found &= (bool)cache.getRect(ii.w, ii.h, sp, ii.blurr);
188 if (cache.width() < cacheMax)
205 if (cache.getVersion() != uploadVersion)
207 uploadVersion = cache.getVersion();
208 internal::openGL_internals<V>::updateTexture(cache.getData(), cache.width());
211 typename internal::openGL_internals<V>::CreateInternal_c vb(dat.size());
218 if (dc && !cleared && j == dat.size())
220 internal::openGL_internals<V>::startCachePreparation(*dc);
224 internal::openGL_internals<V>::startPreparation(sx, sy);
235 auto pos = cache.getGlyph(ii.font, ii.glyphIndex, sp, ii.blurr).value();
240 internal::openGL_internals<V>::drawSubpGlyph(vb, sp, ii, pos, c, cache.width());
244 internal::openGL_internals<V>::drawNormalGlyph(vb, ii, pos, c, cache.width());
255 auto pos = cache.getRect(640, 640,
SUBP_NONE, 0).value();
256 internal::openGL_internals<V>::drawRectangle(vb, ii, pos, c, cache.width());
260 auto pos = cache.getRect(ii.w, ii.h, sp, ii.blurr).value();
261 internal::openGL_internals<V>::drawSmoothRectangle(vb, ii, pos, c, cache.width());
268 images->draw(ii.x+sx, ii.y+sy, ii.w, ii.h, ii.imageURL);
277 if (dc && !cleared && j == dat.size())
279 internal::openGL_internals<V>::endCachePreparation(*dc, vb, sp, sx, sy, atlasId, cache.width());
283 internal::openGL_internals<V>::endPreparation(vb, sp, sx, sy, cache.width());
307 internal::openGL_internals<V>::setupProjection(width, height);
314 const uint8_t *
getData(
void)
const {
return cache.getData(); }
showOpenGL(uint32_t cStart=256, uint32_t cMax=1024)
constructor
Definition: output_OpenGL.h:94
a little class representing an RGBA colour value, an a value of 255 is assumed to be opaque ...
Definition: color.h:36
const std::vector< CommandData_c > getData(void) const
get the command vector
Definition: layouter.h:121
void setGamma(uint8_t gamma=22)
update the gamma value used for output
Definition: output_OpenGL.h:326
helper class used to draw images
Definition: output_OpenGL.h:116
use horizontal RGB
Definition: layouterFont.h:62
typename internal::openGL_internals< V >::DrawCacheInternal_c DrawCache_c
type to keep the caching information for redrawing layouts extra fast. You dont't need to know anythi...
Definition: output_OpenGL.h:84
SubPixelArrangement
define, which sub-pixel arrangement you want to use for sub-pixel output
Definition: layouterFont.h:59
use horizontal BGR
Definition: layouterFont.h:63
const uint8_t * getData(void) const
get a pointer to the texture atlas with all the glyphs
Definition: output_OpenGL.h:314
draw a rectangle
Definition: layouter.h:55
The namespace for the library. Every function and class is within this namespace. ...
Definition: color.h:31
encapsulates a finished layout.
Definition: layouter.h:105
this file contains just a little helper class for a 4-value colour
uint32_t cacheWidth(void) const
Definition: output_OpenGL.h:316
void setupMatrixes(int width, int height)
helper function to setup the projection matrices for the showLayout function. It will change the view...
Definition: output_OpenGL.h:305
don't use sub-pixel output (e.g. non LCD)
Definition: layouterFont.h:61
~showOpenGL(void)
Definition: output_OpenGL.h:109
virtual void draw(int32_t x, int32_t y, uint32_t w, uint32_t h, const std::string &url)=0
uint32_t cacheHeight(void) const
Definition: output_OpenGL.h:317
draw an image
Definition: layouter.h:56
draw a glyph from a font
Definition: layouter.h:54
void clear(void)
clear the glyph cache. This might be useful when you change the fonts that you use for output...
Definition: output_OpenGL.h:335
a class to output layouts using OpenGL
Definition: output_OpenGL.h:67
void showLayout(const TextLayout_c &l, int sx, int sy, SubPixelArrangement sp, imageDrawer_c *images=nullptr, DrawCache_c *dc=nullptr)
paint the layout
Definition: output_OpenGL.h:137