diff --git a/android/Android.mk b/android/Android.mk index bc4fe1670..88f9e67f6 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -143,7 +143,8 @@ LOCAL_PATH := . LOCAL_CPP_FEATURES += rtti LOCAL_SRC_FILES := $(wildcard ../lib/graphics_engine/src/*.c) \ $(wildcard ../lib/graphics_engine/src/*.cpp) -LOCAL_CFLAGS := -I../lib/graphics_engine/include +LOCAL_CFLAGS := -I../lib/graphics_engine/include \ + -I../lib/irrlicht/include/ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) diff --git a/lib/graphics_engine/include/ge_gl_utils.hpp b/lib/graphics_engine/include/ge_gl_utils.hpp new file mode 100644 index 000000000..c92dba2b1 --- /dev/null +++ b/lib/graphics_engine/include/ge_gl_utils.hpp @@ -0,0 +1,47 @@ +#ifndef HEADER_GE_GL_UTILS_HPP +#define HEADER_GE_GL_UTILS_HPP + +#include +#include +#include +#include + +namespace GE +{ +inline bool hasGLExtension(const std::string& extension) +{ + if (glGetStringi) + { + int num = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &num); + for (int i = 0; i < num; i++) + { + char* ext = (char*)glGetStringi(GL_EXTENSIONS, i); + if (ext && extension == ext) + return true; + } + return false; + } + static std::set extensions; + if (extensions.empty()) + { + char* all_ext = (char*)glGetString(GL_EXTENSIONS); + if (all_ext) + { + std::stringstream ss(all_ext); + while (true) + { + std::string ext; + if (ss >> ext) + extensions.insert(ext); + else + break; + } + } + } + return extensions.find(extension) != extensions.end(); +} // hasGLExtension + +} + +#endif diff --git a/lib/graphics_engine/include/ge_texture.hpp b/lib/graphics_engine/include/ge_texture.hpp index 9556c4e4e..9425ef13b 100644 --- a/lib/graphics_engine/include/ge_texture.hpp +++ b/lib/graphics_engine/include/ge_texture.hpp @@ -8,7 +8,8 @@ namespace GE { -irr::video::ITexture* createFontTexture(const std::string& name); +irr::video::ITexture* createFontTexture(const std::string& name, + unsigned size, bool single_channel); irr::video::ITexture* createTexture(irr::video::IImage* img, const std::string& name); irr::video::IImage* getResizedImage(const std::string& path, diff --git a/lib/graphics_engine/src/ge_gl_texture.cpp b/lib/graphics_engine/src/ge_gl_texture.cpp index 6af2522d7..31b0fcb35 100644 --- a/lib/graphics_engine/src/ge_gl_texture.cpp +++ b/lib/graphics_engine/src/ge_gl_texture.cpp @@ -1,7 +1,10 @@ #include "ge_gl_texture.hpp" +#include "ge_gl_utils.hpp" #include "ge_main.hpp" #include "ge_texture.hpp" +#include + namespace GE { GEGLTexture::GEGLTexture(const std::string& path, @@ -29,6 +32,39 @@ GEGLTexture::GEGLTexture(video::IImage* img, const std::string& name) img->drop(); } // GEGLTexture +// ---------------------------------------------------------------------------- +GEGLTexture::GEGLTexture(const std::string& name, unsigned int size, + bool single_channel) + : video::ITexture(name.c_str()), m_image_mani(nullptr), + m_single_channel(false), m_texture_name(0), m_texture_size(0), + m_driver_type(GE::getDriver()->getDriverType()), + m_disable_reload(true) +{ + glGenTextures(1, &m_texture_name); + m_orig_size.Width = size; + m_orig_size.Height = size; + m_size = m_orig_size; + + bool texture_swizzle = false; + if (m_driver_type == video::EDT_OGLES2) + { + int gl_major_version = 0; + glGetIntegerv(GL_MAJOR_VERSION, &gl_major_version); + if (gl_major_version >=3) + texture_swizzle = true; + else + texture_swizzle = false; + } + else + texture_swizzle = GE::hasGLExtension("GL_ARB_texture_swizzle"); + + if (single_channel && texture_swizzle) + m_single_channel = true; + std::vector data; + data.resize(size * size * (single_channel ? 1 : 4), 0); + upload(data.data()); +} // GEGLTexture + // ---------------------------------------------------------------------------- GEGLTexture::~GEGLTexture() { @@ -97,6 +133,8 @@ void* GEGLTexture::lock(video::E_TEXTURE_LOCK_MODE mode, u32 mipmap_level) if (m_driver_type == video::EDT_OGLES2 || !glGetTexImage) { video::IImage* img = getResizedImage(NamedPath.getPtr()); + if (!img) + return NULL; img->setDeleteMemory(false); void* data = img->lock(); img->drop(); diff --git a/lib/graphics_engine/src/ge_gl_texture.hpp b/lib/graphics_engine/src/ge_gl_texture.hpp index 34f6181c0..d9313dc7a 100644 --- a/lib/graphics_engine/src/ge_gl_texture.hpp +++ b/lib/graphics_engine/src/ge_gl_texture.hpp @@ -41,6 +41,9 @@ public: // ------------------------------------------------------------------------ GEGLTexture(video::IImage* img, const std::string& name); // ------------------------------------------------------------------------ + GEGLTexture(const std::string& name, unsigned int size, + bool single_channel); + // ------------------------------------------------------------------------ virtual ~GEGLTexture(); // ------------------------------------------------------------------------ virtual void* lock(video::E_TEXTURE_LOCK_MODE mode = diff --git a/lib/graphics_engine/src/ge_texture.cpp b/lib/graphics_engine/src/ge_texture.cpp index 3ba285548..1956186ec 100644 --- a/lib/graphics_engine/src/ge_texture.cpp +++ b/lib/graphics_engine/src/ge_texture.cpp @@ -74,4 +74,18 @@ irr::video::ITexture* createTexture(video::IImage* img, } } // createTexture +// ---------------------------------------------------------------------------- +irr::video::ITexture* createFontTexture(const std::string& name, + unsigned size, bool single_channel) +{ + switch (GE::getDriver()->getDriverType()) + { + case video::EDT_OPENGL: + case video::EDT_OGLES2: + return new GEGLTexture(name, size, single_channel); + default: + return NULL; + } +} // createFontTexture + } diff --git a/src/font/font_with_face.cpp b/src/font/font_with_face.cpp index 6c38f0269..f8f3073a1 100644 --- a/src/font/font_with_face.cpp +++ b/src/font/font_with_face.cpp @@ -26,7 +26,6 @@ #include "graphics/2dutils.hpp" #include "graphics/central_settings.hpp" #include "graphics/irr_driver.hpp" -#include "graphics/stk_texture.hpp" #include "graphics/stk_tex_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/skin.hpp" @@ -35,6 +34,9 @@ #include "GlyphLayout.h" #include +#ifndef SERVER_ONLY +#include +#endif #include "../lib/irrlicht/source/Irrlicht/CGUISpriteBank.h" @@ -70,7 +72,7 @@ FontWithFace::~FontWithFace() for (unsigned int i = 0; i < m_spritebank->getTextureCount(); i++) { STKTexManager::getInstance()->removeTexture( - static_cast(m_spritebank->getTexture(i))); + m_spritebank->getTexture(i)); } m_spritebank->drop(); @@ -124,7 +126,7 @@ void FontWithFace::reset() for (unsigned int i = 0; i < m_spritebank->getTextureCount(); i++) { STKTexManager::getInstance()->removeTexture( - static_cast(m_spritebank->getTexture(i))); + m_spritebank->getTexture(i)); } m_spritebank->clear(); m_face_ttf->reset(); @@ -159,25 +161,15 @@ void FontWithFace::createNewGlyphPage() #ifndef SERVER_ONLY if (GUIEngine::isNoGraphics()) return; - - uint8_t* data = new uint8_t[getGlyphPageSize() * getGlyphPageSize() * - (CVS->isARBTextureSwizzleUsable() && !useColorGlyphPage() ? 1 : 4)](); -#else - uint8_t* data = NULL; -#endif m_current_height = 0; m_used_width = 0; m_used_height = 0; - STKTexture* stkt = new STKTexture(data, typeid(*this).name() + + video::ITexture* font_texture = GE::createFontTexture(typeid(*this).name() + StringUtils::toString(m_spritebank->getTextureCount()), - getGlyphPageSize(), -#ifndef SERVER_ONLY - CVS->isARBTextureSwizzleUsable() && !useColorGlyphPage() -#else - false + getGlyphPageSize(), !useColorGlyphPage()); + m_spritebank->addTexture(STKTexManager::getInstance()->addTexture( + font_texture)); #endif - ); - m_spritebank->addTexture(STKTexManager::getInstance()->addTexture(stkt)); } // createNewGlyphPage // ---------------------------------------------------------------------------- @@ -406,6 +398,8 @@ void FontWithFace::dumpGlyphPage(const std::string& name) core::dimension2d size = tex->getSize(); video::ECOLOR_FORMAT col_format = tex->getColorFormat(); void* data = tex->lock(); + if (!data) + continue; video::IImage* image = irr_driver->getVideoDriver() ->createImageFromData(col_format, size, data, true/*ownForeignMemory*/); diff --git a/src/graphics/central_settings.cpp b/src/graphics/central_settings.cpp index 91ab40369..c64f4ace5 100644 --- a/src/graphics/central_settings.cpp +++ b/src/graphics/central_settings.cpp @@ -25,7 +25,9 @@ #include "graphics/graphics_restrictions.hpp" #include "guiengine/engine.hpp" #include +#include +using namespace GE; bool CentralVideoSettings::m_supports_sp = true; CentralVideoSettings *CVS = new CentralVideoSettings(); diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 8d6349a6e..9470e4a85 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef DEBUG #if !defined(__APPLE__) && !defined(ANDROID) @@ -157,7 +158,7 @@ void initGL() glDebugMessageCallback((GLDEBUGPROCARB)debugCallback, NULL); #endif - if (SP::sp_apitrace && hasGLExtension("GL_KHR_debug")) + if (SP::sp_apitrace && GE::hasGLExtension("GL_KHR_debug")) { if (glDebugMessageControl) glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); @@ -258,43 +259,6 @@ void draw3DLine(const core::vector3df& start, glGetError(); } -bool hasGLExtension(const char* extension) -{ -#if !defined(USE_GLES2) - if (glGetStringi != NULL) - { - GLint numExtensions = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - for (GLint i = 0; i < numExtensions; i++) - { - const char* foundExtension = - (const char*) glGetStringi(GL_EXTENSIONS, i); - if (foundExtension && strcmp(foundExtension, extension) == 0) - { - return true; - } - } - } - else -#endif - { - const char* extensions = (const char*) glGetString(GL_EXTENSIONS); - static std::vector all_extensions; - if (all_extensions.empty()) - { - all_extensions = StringUtils::split(std::string(extensions), ' '); - } - for (unsigned i = 0; i < all_extensions.size(); i++) - { - if (all_extensions[i] == extension) - { - return true; - } - } - } - return false; -} // hasGLExtension - // ---------------------------------------------------------------------------- /** Returns a space-separated list of all GL extensions. Used for hardware * reporting. diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 99dfe0665..6f80f31c7 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -152,7 +152,6 @@ public: void draw3DLine(const core::vector3df& start, const core::vector3df& end, irr::video::SColor color); -bool hasGLExtension(const char* extension); const std::string getGLExtensions(); void getGLLimits(HardwareStats::Json *json); bool checkGLError();