From 110f640ca8dbcdf290037512e6c716f93351a659 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 23 Aug 2014 00:34:55 -0700 Subject: [PATCH] Fix Linux/Android compilation. --- Android.mk | 2 ++ gfx_es2/draw_text.cpp | 20 +++++++++----------- gfx_es2/draw_text.h | 4 ---- thin3d/thin3d_gl.cpp | 23 +++++++++++++++++------ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Android.mk b/Android.mk index 4098bf4253..8bc0fb1a02 100644 --- a/Android.mk +++ b/Android.mk @@ -88,6 +88,8 @@ LOCAL_SRC_FILES :=\ image/zim_load.cpp \ image/zim_save.cpp \ image/png_load.cpp \ + thin3d/thin3d.cpp \ + thin3d/thin3d_gl.cpp \ ui/view.cpp \ ui/viewgroup.cpp \ ui/ui.cpp \ diff --git a/gfx_es2/draw_text.cpp b/gfx_es2/draw_text.cpp index 53baf045c9..c01988dc1c 100644 --- a/gfx_es2/draw_text.cpp +++ b/gfx_es2/draw_text.cpp @@ -199,14 +199,14 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float #else -TextDrawer::TextDrawer() { +TextDrawer::TextDrawer(Thin3DContext *thin3d) : thin3d_(thin3d), ctx_(NULL) { fontScaleX_ = 1.0f; fontScaleY_ = 1.0f; } TextDrawer::~TextDrawer() { for (auto iter = cache_.begin(); iter != cache_.end(); ++iter) { - glDeleteTextures(1, &iter->second->textureHandle); + iter->second->texture->Release(); delete iter->second; } cache_.clear(); @@ -254,6 +254,9 @@ void TextDrawer::MeasureString(const char *str, float *w, float *h) { } void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) { + if (!strlen(str)) + return; + #ifdef USING_QT_UI uint32_t stringHash = hash::Fletcher((const uint8_t *)str, strlen(str)); uint32_t entryHash = stringHash ^ fontHash_; @@ -266,7 +269,7 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float if (iter != cache_.end()) { entry = iter->second; entry->lastUsedFrame = frameCount_; - glBindTexture(GL_TEXTURE_2D, entry->textureHandle); + thin3d_->SetTexture(0, entry->texture); } else { QFont *font = fontMap_.find(fontHash_)->second; QFontMetrics fm(*font); @@ -285,11 +288,10 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float painter.end(); entry = new TextStringEntry(); - glGenTextures(1, &entry->textureHandle); - glBindTexture(GL_TEXTURE_2D, entry->textureHandle); entry->bmWidth = entry->width = image.width(); entry->bmHeight = entry->height = image.height(); entry->lastUsedFrame = frameCount_; + entry->texture = thin3d_->CreateTexture(LINEAR2D, RGBA4444, entry->bmWidth, entry->bmHeight, 1, 0); uint16_t *bitmapData = new uint16_t[entry->bmWidth * entry->bmHeight]; for (int x = 0; x < entry->bmWidth; x++) { @@ -297,12 +299,8 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float bitmapData[entry->bmWidth * y + x] = 0xfff0 | image.pixel(x, y) >> 28; } } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, entry->bmWidth, entry->bmHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, bitmapData); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + entry->texture->SetImageData(0, 0, 0, entry->bmWidth, entry->bmHeight, 1, 0, entry->bmWidth * 2, (const uint8_t *)bitmapData); + entry->texture->Finalize(0); delete [] bitmapData; diff --git a/gfx_es2/draw_text.h b/gfx_es2/draw_text.h index 3d94a0528e..bd1f1d8248 100644 --- a/gfx_es2/draw_text.h +++ b/gfx_es2/draw_text.h @@ -24,11 +24,7 @@ class Thin3DTexture; #endif struct TextStringEntry { -#if defined(_WIN32) && !defined(USING_QT_UI) Thin3DTexture *texture; -#else - GLuint textureHandle; -#endif int width; int height; int bmWidth; diff --git a/thin3d/thin3d_gl.cpp b/thin3d/thin3d_gl.cpp index f179b6135f..eaa7cd17a1 100644 --- a/thin3d/thin3d_gl.cpp +++ b/thin3d/thin3d_gl.cpp @@ -315,11 +315,15 @@ Thin3DVertexFormat *Thin3DGLContext::CreateVertexFormat(const std::vector