aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/video.cpp
diff options
context:
space:
mode:
authordhewg2011-02-19 17:30:30 +0100
committerdhewg2011-02-19 20:15:51 +0100
commitadf2225eb414b04a0e58f1fad221cdef27017391 (patch)
tree57b56e98bf8391d95ed898c73942ecf0b8c85e43 /backends/platform/android/video.cpp
parent229e3ca5bf4bbc91b6bf85a5fe6dd9356a97a5ef (diff)
downloadscummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.tar.gz
scummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.tar.bz2
scummvm-rg350-adf2225eb414b04a0e58f1fad221cdef27017391.zip
ANDROID: Move helper defines in a new header file
- added a few macros for convinience - use them - replaced CHECK_GL_ERROR with GLCALL - spam GLCALL
Diffstat (limited to 'backends/platform/android/video.cpp')
-rw-r--r--backends/platform/android/video.cpp133
1 files changed, 44 insertions, 89 deletions
diff --git a/backends/platform/android/video.cpp b/backends/platform/android/video.cpp
index f5ec0b45d9..f8427c2ac8 100644
--- a/backends/platform/android/video.cpp
+++ b/backends/platform/android/video.cpp
@@ -28,55 +28,17 @@
#include "base/main.h"
#include "graphics/surface.h"
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-#include <android/log.h>
-
#include "common/rect.h"
#include "common/array.h"
#include "common/util.h"
#include "common/tokenizer.h"
+#include "backends/platform/android/android.h"
#include "backends/platform/android/video.h"
// Unfortunately, Android devices are too varied to make broad assumptions :/
#define TEXSUBIMAGE_IS_EXPENSIVE 0
-#undef LOG_TAG
-#define LOG_TAG "ScummVM"
-
-#if 0
-#define ENTER(args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args)
-#else
-#define ENTER(args...) /**/
-#endif
-
-#if 0
-#define CHECK_GL_ERROR() checkGlError(__FILE__, __LINE__)
-static const char *getGlErrStr(GLenum error) {
- switch (error) {
- case GL_NO_ERROR: return "GL_NO_ERROR";
- case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
- case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
- case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
- case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
- case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
- }
-
- static char buf[40];
- snprintf(buf, sizeof(buf), "(Unknown GL error code 0x%x)", error);
- return buf;
-}
-static void checkGlError(const char *file, int line) {
- GLenum error = glGetError();
- if (error != GL_NO_ERROR)
- warning("%s:%d: GL error: %s", file, line, getGlErrStr(error));
-}
-#else
-#define CHECK_GL_ERROR() do {} while (false)
-#endif
-
// Supported GL extensions
static bool npot_supported = false;
#ifdef GL_OES_draw_texture
@@ -104,8 +66,7 @@ void GLESTexture::initGLExtensions() {
const char *ext_string =
reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
- __android_log_print(ANDROID_LOG_INFO, LOG_TAG,
- "Extensions: %s", ext_string);
+ LOGI("Extensions: %s", ext_string);
Common::StringTokenizer tokenizer(ext_string, " ");
while (!tokenizer.empty()) {
@@ -126,7 +87,7 @@ GLESTexture::GLESTexture() :
_texture_height(0),
_all_dirty(true)
{
- glGenTextures(1, &_texture_name);
+ GLCALL(glGenTextures(1, &_texture_name));
// This all gets reset later in allocBuffer:
_surface.w = 0;
@@ -138,12 +99,12 @@ GLESTexture::GLESTexture() :
GLESTexture::~GLESTexture() {
debug("Destroying texture %u", _texture_name);
- glDeleteTextures(1, &_texture_name);
+ GLCALL(glDeleteTextures(1, &_texture_name));
}
void GLESTexture::reinitGL() {
- glDeleteTextures(1, &_texture_name);
- glGenTextures(1, &_texture_name);
+ GLCALL(glDeleteTextures(1, &_texture_name));
+ GLCALL(glGenTextures(1, &_texture_name));
// bypass allocBuffer() shortcut to reinit the texture properly
_texture_width = 0;
@@ -154,7 +115,6 @@ void GLESTexture::reinitGL() {
}
void GLESTexture::allocBuffer(GLuint w, GLuint h) {
- CHECK_GL_ERROR();
int bpp = bytesPerPixel();
_surface.w = w;
_surface.h = h;
@@ -176,33 +136,29 @@ void GLESTexture::allocBuffer(GLuint w, GLuint h) {
// Allocate room for the texture now, but pixel data gets uploaded
// later (perhaps with multiple TexSubImage2D operations).
- CHECK_GL_ERROR();
- glBindTexture(GL_TEXTURE_2D, _texture_name);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- CHECK_GL_ERROR();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- CHECK_GL_ERROR();
- glTexImage2D(GL_TEXTURE_2D, 0, glFormat(),
- _texture_width, _texture_height,
- 0, glFormat(), glType(), 0);
- CHECK_GL_ERROR();
+ GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
+ GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
+ GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, glFormat(),
+ _texture_width, _texture_height,
+ 0, glFormat(), glType(), 0));
}
void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
const void *buf, int pitch) {
- ENTER("updateBuffer(%u, %u, %u, %u, %p, %d)", x, y, w, h, buf, pitch);
+ ENTER("%u, %u, %u, %u, %p, %d", x, y, w, h, buf, pitch);
- glBindTexture(GL_TEXTURE_2D, _texture_name);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
+ GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
setDirtyRect(Common::Rect(x, y, x+w, y+h));
if (static_cast<int>(w) * bytesPerPixel() == pitch) {
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
- glFormat(), glType(), buf);
+ GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
+ glFormat(), glType(), buf));
} else {
// GLES removed the ability to specify pitch, so we
// have to do this ourselves.
@@ -221,15 +177,15 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
src += pitch;
} while (--count);
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
- glFormat(), glType(), tmpbuf);
+ GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
+ glFormat(), glType(), tmpbuf));
#else
// This version avoids the intermediate copy at the expense of
// repeat glTexSubImage2D calls. On some devices this is worse.
const byte *src = static_cast<const byte *>(buf);
do {
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
- w, 1, glFormat(), glType(), src);
+ GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
+ w, 1, glFormat(), glType(), src));
++y;
src += pitch;
} while (--h);
@@ -245,21 +201,21 @@ void GLESTexture::fillBuffer(byte x) {
}
void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
- glBindTexture(GL_TEXTURE_2D, _texture_name);
+ GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
#ifdef GL_OES_draw_texture
// Great extension, but only works under specific conditions.
// Still a work-in-progress - disabled for now.
if (false && draw_tex_supported && paletteSize() == 0) {
- //glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ //GLCALL(glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));
const GLint crop[4] = { 0, _surface.h, _surface.w, -_surface.h };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+ GLCALL(glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop));
// Android GLES bug?
- glColor4ub(0xff, 0xff, 0xff, 0xff);
+ GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff));
- glDrawTexiOES(x, y, 0, w, h);
+ GLCALL(glDrawTexiOES(x, y, 0, w, h));
} else
#endif
{
@@ -272,7 +228,7 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
tex_width, tex_height,
};
- glTexCoordPointer(2, GL_FIXED, 0, texcoords);
+ GLCALL(glTexCoordPointer(2, GL_FIXED, 0, texcoords));
const GLshort vertices[] = {
x, y,
@@ -281,10 +237,10 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
x + w, y + h,
};
- glVertexPointer(2, GL_SHORT, 0, vertices);
+ GLCALL(glVertexPointer(2, GL_SHORT, 0, vertices));
assert(ARRAYSIZE(vertices) == ARRAYSIZE(texcoords));
- glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2);
+ GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2));
}
_all_dirty = false;
@@ -302,7 +258,6 @@ GLESPaletteTexture::~GLESPaletteTexture() {
}
void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
- CHECK_GL_ERROR();
int bpp = bytesPerPixel();
_surface.w = w;
_surface.h = h;
@@ -360,22 +315,22 @@ void GLESPaletteTexture::uploadTexture() const {
const size_t texture_size =
paletteSize() + _texture_width * _texture_height * bytesPerPixel();
- glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(),
- _texture_width, _texture_height,
- 0, texture_size, _texture);
- CHECK_GL_ERROR();
+ GLCALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, glType(),
+ _texture_width, _texture_height,
+ 0, texture_size, _texture));
}
void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
if (_all_dirty) {
- glBindTexture(GL_TEXTURE_2D, _texture_name);
- CHECK_GL_ERROR();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- CHECK_GL_ERROR();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- CHECK_GL_ERROR();
+ GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE));
+ GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE));
uploadTexture();
_all_dirty = false;
}