text drawing is working ok under OpenGL

This commit is contained in:
Vadim Lopatin 2014-03-11 21:48:54 +04:00
parent 6786e29b17
commit e4f27b1966
3 changed files with 67 additions and 62 deletions

View File

@ -59,6 +59,16 @@ class GLDrawBuf : DrawBuf {
/// draw 8bit alpha image - usually font glyph using specified color (clipping is applied) /// draw 8bit alpha image - usually font glyph using specified color (clipping is applied)
override void drawGlyph(int x, int y, Glyph * glyph, uint color) { override void drawGlyph(int x, int y, Glyph * glyph, uint color) {
assert(_scene !is null); assert(_scene !is null);
Rect dstrect = Rect(x,y, x + glyph.blackBoxX, y + glyph.blackBoxY);
Rect srcrect = Rect(0, 0, glyph.blackBoxX, glyph.blackBoxY);
//Log.v("GLDrawBuf.frawFragment dst=", dstrect, " src=", srcrect);
if (applyClipping(dstrect, srcrect)) {
GLGlyphCacheItem item = glGlyphCache.get(glyph.id);
if (item is null)
item = glGlyphCache.set(glyph);
// TODO: clipping
_scene.add(new GlyphSceneItem(glyph.id, dstrect, srcrect, color, null));
}
} }
/// draw source buffer rectangle contents to destination buffer /// draw source buffer rectangle contents to destination buffer
override void drawFragment(int x, int y, DrawBuf src, Rect srcrect) { override void drawFragment(int x, int y, DrawBuf src, Rect srcrect) {
@ -113,18 +123,6 @@ class Scene {
} }
} }
class SolidRectSceneItem : SceneItem {
Rect _rc;
uint _color;
this(Rect rc, uint color) {
_rc = rc;
_color = color;
}
override void draw() {
drawSolidFillRect(_rc, _color, _color, _color, _color);
}
}
private __gshared int activeSceneCount = 0; private __gshared int activeSceneCount = 0;
bool hasActiveScene() { bool hasActiveScene() {
return activeSceneCount > 0; return activeSceneCount > 0;
@ -147,15 +145,23 @@ void onObjectDestroyedCallback(uint pobject) {
glImageCache.onCachedObjectDeleted(pobject); glImageCache.onCachedObjectDeleted(pobject);
} }
/// object deletion listener callback function type
void onGlyphDestroyedCallback(uint pobject) {
glGlyphCache.onCachedObjectDeleted(pobject);
}
private __gshared GLImageCache glImageCache; private __gshared GLImageCache glImageCache;
private __gshared GLGlyphCache glGlyphCache;
shared static this() { shared static this() {
glImageCache = new GLImageCache(); glImageCache = new GLImageCache();
glGlyphCache = new GLGlyphCache();
} }
void LVGLClearImageCache() { void LVGLClearImageCache() {
glImageCache.clear(); glImageCache.clear();
glGlyphCache.clear();
} }
private class GLImageCacheItem { private class GLImageCacheItem {
@ -549,10 +555,10 @@ public:
_map.clear(); _map.clear();
} }
/// draw cached item /// draw cached item
void drawItem(uint objectId, Rect dstrc, Rect srcrc, uint color, int options, Rect * clip, int rotationAngle) { void drawItem(uint objectId, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
if (objectId in _map) { if (objectId in _map) {
GLGlyphCacheItem item = _map[objectId]; GLGlyphCacheItem item = _map[objectId];
item.page.drawItem(item, dstrc, srcrc, color, options, clip, rotationAngle); item.page.drawItem(item, dstrc, srcrc, color, clip);
} }
} }
/// handle cached object deletion, mark as deleted /// handle cached object deletion, mark as deleted
@ -684,7 +690,7 @@ public:
_needUpdateTexture = true; _needUpdateTexture = true;
return cacheItem; return cacheItem;
} }
void drawItem(GLGlyphCacheItem item, Rect dstrc, Rect srcrc, uint color, uint options, Rect * clip, int rotationAngle) { void drawItem(GLGlyphCacheItem item, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
//CRLog::trace("drawing item at %d,%d %dx%d <= %d,%d %dx%d ", x, y, dx, dy, srcx, srcy, srcdx, srcdy); //CRLog::trace("drawing item at %d,%d %dx%d <= %d,%d %dx%d ", x, y, dx, dy, srcx, srcy, srcdx, srcdy);
if (_needUpdateTexture) if (_needUpdateTexture)
updateTexture(); updateTexture();
@ -693,13 +699,6 @@ public:
Log.e("Invalid texture ", _textureId); Log.e("Invalid texture ", _textureId);
return; return;
} }
//rotationAngle = 0;
int rx = dstrc.middlex;
int ry = dstrc.middley;
if (rotationAngle) {
//rotationAngle = 0;
//setRotation(rx, ry, rotationAngle);
}
// convert coordinates to cached texture // convert coordinates to cached texture
srcrc.offset(item._rc.left, item._rc.top); srcrc.offset(item._rc.left, item._rc.top);
if (clip) { if (clip) {
@ -721,16 +720,7 @@ public:
dstrc.bottom -= clip.bottom; dstrc.bottom -= clip.bottom;
} }
if (!dstrc.empty) if (!dstrc.empty)
drawColorAndTextureRect(_textureId, _tdx, _tdy, srcrc, dstrc, color, srcrc.width() != dstrc.width() || srcrc.height() != dstrc.height()); drawColorAndTextureRect(_textureId, _tdx, _tdy, srcrc, dstrc, color, false);
//drawColorAndTextureRect(vertices, texcoords, color, _textureId);
if (rotationAngle) {
// unset rotation
setRotation(rx, ry, 0);
// glMatrixMode(GL_PROJECTION);
// glPopMatrix();
// checkError("pop matrix");
}
} }
} }
@ -740,3 +730,46 @@ public:
updateTexture(); updateTexture();
} }
}; };
class SolidRectSceneItem : SceneItem {
Rect _rc;
uint _color;
this(Rect rc, uint color) {
_rc = rc;
_color = color;
}
override void draw() {
drawSolidFillRect(_rc, _color, _color, _color, _color);
}
}
private class GlyphSceneItem : SceneItem {
uint objectId;
Rect dstrc;
Rect srcrc;
uint color;
Rect * clip;
public:
override void draw() {
if (glGlyphCache)
glGlyphCache.drawItem(objectId, dstrc, srcrc, color, clip);
}
this(uint _objectId, Rect _dstrc, Rect _srcrc, uint _color, Rect * _clip)
{
objectId = _objectId;
dstrc = _dstrc;
srcrc = _srcrc;
color = _color;
clip = _clip;
}
~this() {
}
};

View File

@ -317,40 +317,10 @@ void QMatrix4x4_ortho(float left, float right, float bottom, float top, float ne
qtmatrix[y * 4 + x] = m[y][x]; qtmatrix[y * 4 + x] = m[y][x];
} }
/*
void myGlOrtho(float left, float right, float bottom, float top,
float zNearPlane, float zFarPlane)
{
float r_l = 1.0f / (right - left);
float t_b = 1.0f / (top - bottom);
float f_n = 1.0f / (zFarPlane - zNearPlane);
foreach(ref float item; matrix)
item = 0;
//memset(m, 0, sizeof(m));
matrix[0] = 2.0f * r_l;
matrix[5] = 2.0f * t_b;
matrix[10] = -2.0f * f_n;
matrix[12] = (-(right + left)) * r_l;
matrix[13] = (-(top + bottom)) * t_b;
matrix[14] = (-(zFarPlane + zNearPlane)) * f_n;
}
*/
void setOrthoProjection(int dx, int dy) { void setOrthoProjection(int dx, int dy) {
//myGlOrtho(0, dx, 0, dy, -1.0f, 5.0f);
bufferDx = dx; bufferDx = dx;
bufferDy = dy; bufferDy = dy;
//myGlOrtho(0, dx, 0, dy, -0.1f, 5.0f);
//Log.d("Ortho ", dx, "x", dy);
//m = mat4.orthographic(0, dx, 0, dy, 0.5f, 50.0f);
//myGlOrtho(0, dx, 0, dy, 0.5f, 50.0f);
QMatrix4x4_ortho(0, dx, 0, dy, 0.5f, 50.0f); QMatrix4x4_ortho(0, dx, 0, dy, 0.5f, 50.0f);
//Log.d("Matrix: ", m);
//Log.d("myMatrix: ", matrix);
//Log.d("qtMatrix: ", qtmatrix);
glViewport(0, 0, dx, dy); glViewport(0, 0, dx, dy);
checkError("glViewport"); checkError("glViewport");
} }

View File

@ -3,6 +3,7 @@ module dlangui.platforms.common.platform;
import dlangui.widgets.widget; import dlangui.widgets.widget;
import dlangui.graphics.drawbuf; import dlangui.graphics.drawbuf;
import std.file; import std.file;
private import dlangui.graphics.gldrawbuf;
public class Window { public class Window {
int _dx; int _dx;
@ -56,6 +57,7 @@ private __gshared bool _OPENGL_ENABLED = false;
/// call on app initialization if OpenGL support is detected /// call on app initialization if OpenGL support is detected
void setOpenglEnabled() { void setOpenglEnabled() {
_OPENGL_ENABLED = true; _OPENGL_ENABLED = true;
glyphDestroyCallback = &onGlyphDestroyedCallback;
} }
version (Windows) { version (Windows) {