Android opengl debug callback, Android device properties, fix texture internal format

This commit is contained in:
2017-04-02 11:35:11 +01:00
parent b1a3cb0309
commit 0dfb458c71
9 changed files with 135 additions and 35 deletions

View File

@@ -459,16 +459,17 @@ void App::init()
{ GL_DEBUG_SEVERITY_MEDIUM, FOREGROUND_GREEN | FOREGROUND_INTENSITY },
{ GL_DEBUG_SEVERITY_HIGH, FOREGROUND_RED | FOREGROUND_INTENSITY },
};
if (severity == GL_DEBUG_SEVERITY_MEDIUM || severity == GL_DEBUG_SEVERITY_HIGH)
if (severity == GL_DEBUG_SEVERITY_MEDIUM || severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_LOW)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors[severity]);
LOG("%.*s", length, message);
LOG("OPENGL: %.*s", length, message);
FlushConsoleInputBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), info.wAttributes);
__debugbreak();
// __debugbreak();
}
}, nullptr);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
#endif
//int n;
@@ -550,7 +551,7 @@ bool App::mouse_down(int button, float x, float y)
e.m_type = button ? kEventType::MouseDownR : kEventType::MouseDownL;
e.m_pos = { x / zoom, y / zoom };
auto ret = layout[main_id]->on_event(&e);
LOG("mouse click button%d pos %f %f", button, x, y);
//LOG("mouse click button%d pos %f %f", button, x, y);
// if (popup)
// {
@@ -584,7 +585,7 @@ bool App::mouse_up(int button, float x, float y)
e.m_pos = { x / zoom, y / zoom };
auto ret = layout[main_id]->on_event(&e);
layout[main_id]->update();
LOG("mouse up button%d pos %f %f", button, x, y);
//LOG("mouse up button%d pos %f %f", button, x, y);
return ret == kEventResult::Consumed;
}
bool App::key_down(int key)
@@ -594,7 +595,7 @@ bool App::key_down(int key)
e.m_key = key;
auto ret = layout[main_id]->on_event(&e);
layout[main_id]->update();
LOG("key down %d '%c'", key, key);
//LOG("key down %d '%c'", key, key);
return ret == kEventResult::Consumed;
}
bool App::key_up(int key)
@@ -604,7 +605,7 @@ bool App::key_up(int key)
e.m_key = key;
auto ret = layout[main_id]->on_event(&e);
layout[main_id]->update();
LOG("key up %d '%c'", key, key);
//LOG("key up %d '%c'", key, key);
return ret == kEventResult::Consumed;
}
bool App::key_char(int key)
@@ -614,6 +615,6 @@ bool App::key_char(int key)
e.m_key = key;
auto ret = layout[main_id]->on_event(&e);
layout[main_id]->update();
LOG("key up %d '%c'", key, key);
//LOG("key up %d '%c'", key, key);
return ret == kEventResult::Consumed;
}

View File

@@ -7,7 +7,7 @@ AAssetManager* Asset::m_am;
bool Asset::open(const char* path)
{
LOG("Asset::open %s", path);
//LOG("Asset::open %s", path);
m_current_path = path;
#ifdef __ANDROID__
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))

View File

@@ -16,7 +16,7 @@ bool Font::load(const char* ttf, int font_size)
auto bitmap = std::make_unique<uint8_t[]>(w*h);
chars.resize(num_chars);
int ret = stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size, bitmap.get(), w, h, start_char, num_chars, chars.data());
font_tex.create(w, h, GL_RED, bitmap.get());
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
file.close();
return true;
}

View File

@@ -1529,11 +1529,11 @@ public:
::FindClose(hFind);
}
#elif __ANDROID__
LOG("listing brushes");
//LOG("listing brushes");
AAssetDir* dir = AAssetManager_openDir(Asset::m_am, "data/Icons");
while (const char* name = AAssetDir_getNextFileName(dir))
{
LOG("asset: %s", name);
//LOG("asset: %s", name);
names.push_back(name);
}
AAssetDir_close(dir);

View File

@@ -13,6 +13,7 @@
#elif __ANDROID__
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES3/gl3.h>
#include <sys/stat.h>

View File

@@ -14,9 +14,9 @@ bool TextureManager::load(const char* path)
return true;
}
void TextureManager::assign(uint16_t id, GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint format/* = GL_RGBA*/)
void TextureManager::assign(uint16_t id, GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/)
{
m_textures[id].assign(tex, w, h, format);
m_textures[id].assign(tex, w, h, internal_format, format);
}
Texture2D& TextureManager::get(uint16_t id)
@@ -24,29 +24,32 @@ Texture2D& TextureManager::get(uint16_t id)
return m_textures[id];
}
bool Texture2D::create(int width, int height, GLint format, const uint8_t* data)
bool Texture2D::create(int width, int height, GLint internal_format, GLint format, const uint8_t* data)
{
m_width = width;
m_height = height;
m_format = format;
m_iformat = internal_format;
glGenTextures(1, &m_tex);
bind();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
unbind();
return true;
}
bool Texture2D::create(const ui::Image& img)
{
static GLint formats[] = { GL_RED, GL_RG, GL_RGB, GL_RGBA };
return create(img.width, img.height, formats[img.comp - 1], img.data());
static GLint iformats[] = { GL_R8, GL_RG8, GL_RGB8, GL_RGBA8 };
return create(img.width, img.height, iformats[img.comp - 1], formats[img.comp - 1], img.data());
}
void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint format/* = GL_RGBA*/)
void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/)
{
m_tex = tex;
m_width = w;
m_height = h;
m_format = format;
m_iformat = internal_format;
}
bool Texture2D::load(std::string filename)

View File

@@ -7,10 +7,11 @@ class Texture2D
int m_width;
int m_height;
GLint m_format;
GLint m_iformat;
public:
bool create(int width, int height, GLint format = GL_RGBA, const uint8_t* data = nullptr);
bool create(int width, int height, GLint internal_format, GLint format = GL_RGBA, const uint8_t* data = nullptr);
bool create(const ui::Image& img);
void assign(GLuint tex, int w = -1, int h = -1, GLuint format = GL_RGBA);
void assign(GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA);
bool load(std::string filename);
void destroy() { glDeleteTextures(1, &m_tex); }
void bind() const { glBindTexture(GL_TEXTURE_2D, m_tex); }
@@ -37,6 +38,6 @@ class TextureManager
public:
static std::map<uint16_t, Texture2D> m_textures;
static bool load(const char* path);
static void assign(uint16_t id, GLuint tex, int w = -1, int h = -1, GLuint format = GL_RGBA);
static void assign(uint16_t id, GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA);
static Texture2D& get(uint16_t id);
};

View File

@@ -12,14 +12,7 @@ glm::vec4 rand_color();
glm::vec3 convert_hsv2rgb(const glm::vec3 c);
glm::vec3 convert_rgb2hsv(const glm::vec3 c);
//void check_OpenGLError(const char* stmt, const char* fname, int line)
//{
// GLenum err;
// while ((err = glGetError()) != GL_NO_ERROR)
// {
// //LOG("OpenGL error %08x (%s), at %s:%i - for %s", err, gluErrorString(err), fname, line, stmt);
// }
//}
void check_OpenGLError(const char* stmt, const char* fname, int line);
template<typename T, int N> struct cbuffer
{