Permalink
Browse files

added module hack struct to be able to control gles rendering

implemented quick downscale of rgba images for cut the rope before uploading to the gpu
added gles extension initialization
  • Loading branch information...
1 parent c75d4af commit 545e26ea313712bdec0aa65bed51e9044c88f500 @crowriot committed Jan 24, 2013
Showing with 190 additions and 71 deletions.
  1. +6 −2 apkenv.c
  2. +4 −1 apkenv.cbp
  3. +7 −1 apkenv.h
  4. +127 −25 compat/gles_wrappers.c
  5. +7 −0 compat/gles_wrappers.h
  6. +38 −6 modules/cuttherope.c
  7. +1 −0 modules/fruitninja.cbp
  8. +0 −36 modules/unity.depend
View
@@ -46,6 +46,7 @@
/* Global application state */
struct GlobalState global;
+struct ModuleHacks global_module_hacks;
void *
lookup_symbol_impl(const char *method)
@@ -303,6 +304,8 @@ int system_init()
return 0;
}
+ gles_extensions_init();
+
SDL_ShowCursor(0);
return 1;
@@ -333,7 +336,6 @@ int main(int argc, char **argv)
printf("%s\n%s\n\n", global.apkenv_headline, global.apkenv_copyright);
-#if 0
switch (argc) {
case 2:
/* One argument - the .apk (continue below) */
@@ -346,13 +348,15 @@ int main(int argc, char **argv)
/* Wrong number of arguments */
usage();
}
-#endif
+
+ memset(&global_module_hacks,0,sizeof(global_module_hacks));
global.lookup_symbol = lookup_symbol_impl;
global.lookup_lib_symbol = lookup_lib_symbol_impl;
global.foreach_file = foreach_file_impl;
global.read_file = read_file_impl;
global.recursive_mkdir = recursive_mkdir;
+ global.module_hacks = &global_module_hacks;
jnienv_init(&global);
javavm_init(&global);
View
@@ -13,9 +13,10 @@
<Option compiler="pandora_compiler" />
<Compiler>
<Add option="-g" />
+ <Add option="-rdynamic" />
<Add option="-DDEBUG=1" />
<Add option="-DLINKER_DEBUG=2" />
- <Add option="-DAPKENV_DEBUGx" />
+ <Add option="-DAPKENV_DEBUG" />
<Add option="-DAPKENV_GLES" />
</Compiler>
<Linker>
@@ -160,9 +161,11 @@
<Option compile="0" />
<Option link="0" />
</Unit>
+ <Unit filename="pandora/compatibility.txt" />
<Unit filename="pandora/platform.c">
<Option compilerVar="CC" />
</Unit>
+ <Unit filename="pandora/sdlkeys.txt" />
<Unit filename="platform.h" />
<Extensions>
<code_completion />
View
@@ -42,6 +42,11 @@
struct GlobalState;
struct SupportModulePriv;
+struct ModuleHacks {
+ int gles_landscape_to_portrait;
+ int gles_downscale_images;
+};
+
struct SupportModule {
struct GlobalState *global;
struct SupportModulePriv *priv;
@@ -95,6 +100,7 @@ struct GlobalState {
struct SupportModule *support_modules;
struct SupportModule *active_module;
+ struct ModuleHacks *module_hacks;
lookup_symbol_t lookup_symbol;
lookup_lib_symbol_t lookup_lib_symbol;
@@ -130,6 +136,6 @@ void *android_dlsym(void *handle, const char *symbol);
typedef int (*apkenv_module_init_t)(int version, struct SupportModule *module);
#define APKENV_MODULE_INIT "apkenv_module_init"
#define APKENV_MODULE_SUFFIX ".apkenv.so"
-#define APKENV_MODULE_VERSION 0x010000
+#define APKENV_MODULE_VERSION 0x010001
#endif /* APKENV_H */
View
@@ -8,6 +8,52 @@
# define WRAPPERS_DEBUG_PRINTF(...)
# define GL_TEST_ERROR
#endif
+
+
+extern struct ModuleHacks global_module_hacks;
+
+struct gles_extensions {
+ PFNGLISRENDERBUFFEROESPROC glIsRenderbufferOES;
+ PFNGLBINDRENDERBUFFEROESPROC glBindRenderbufferOES;
+ PFNGLDELETERENDERBUFFERSOESPROC glDeleteRenderbuffersOES;
+ PFNGLGENRENDERBUFFERSOESPROC glGenRenderbuffersOES;
+ PFNGLRENDERBUFFERSTORAGEOESPROC glRenderbufferStorageOES;
+ PFNGLGETRENDERBUFFERPARAMETERIVOESPROC glGetRenderbufferParameterivOES;
+ PFNGLISFRAMEBUFFEROESPROC glIsFramebufferOES;
+ PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
+ PFNGLDELETEFRAMEBUFFERSOESPROC glDeleteFramebuffersOES;
+ PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOES;
+ PFNGLCHECKFRAMEBUFFERSTATUSOESPROC glCheckFramebufferStatusOES;
+ PFNGLFRAMEBUFFERRENDERBUFFEROESPROC glFramebufferRenderbufferOES;
+ PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
+ PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOESPROC glGetFramebufferAttachmentParameterivOES;
+ PFNGLGENERATEMIPMAPOESPROC glGenerateMipmapOES;
+};
+static struct gles_extensions extensions;
+
+#define init_extension(ext) \
+ extensions . ext = eglGetProcAddress(#ext); \
+ WRAPPERS_DEBUG_PRINTF("%s is at 0x%x\n", #ext, extensions . ext)
+
+void gles_extensions_init()
+{
+ init_extension(glIsRenderbufferOES);
+ init_extension(glBindRenderbufferOES);
+ init_extension(glDeleteRenderbuffersOES);
+ init_extension(glGenRenderbuffersOES);
+ init_extension(glRenderbufferStorageOES);
+ init_extension(glGetRenderbufferParameterivOES);
+ init_extension(glIsFramebufferOES);
+ init_extension(glBindFramebufferOES);
+ init_extension(glDeleteFramebuffersOES);
+ init_extension(glGenFramebuffersOES);
+ init_extension(glCheckFramebufferStatusOES);
+ init_extension(glFramebufferRenderbufferOES);
+ init_extension(glFramebufferTexture2DOES);
+ init_extension(glGetFramebufferAttachmentParameterivOES);
+ init_extension(glGenerateMipmapOES);
+}
+
void
my_glAlphaFunc(GLenum func, GLclampf ref)
{
@@ -168,9 +214,10 @@ void
my_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
{
WRAPPERS_DEBUG_PRINTF("glOrthof(%f, %f, %f, %f)\n", left, right, bottom, top, zNear, zFar);
-#ifdef LANDSCAPE_TO_PORTRAIT
- glRotatef(-90,0,0,1);
-#endif
+ if (global_module_hacks.gles_landscape_to_portrait!=0) {
+ glLoadIdentity();
+ glRotatef(-90,0,0,1);
+ }
glOrthof(left, right, bottom, top, zNear, zFar);
}
void
@@ -824,8 +871,63 @@ my_glTexEnvxv(GLenum target, GLenum pname, const GLfixed *params)
void
my_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
{
- WRAPPERS_DEBUG_PRINTF("glTexImage2D()\n", target, level, internalformat, width, height, border, format, type, pixels);
- glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
+ int maxsize = 0;
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxsize);
+
+ int downscale = global_module_hacks.gles_downscale_images && (width>=maxsize || height>=maxsize);
+
+ if ( downscale && format==GL_RGBA && type==GL_UNSIGNED_SHORT_4_4_4_4 )
+ {
+ int x,y;
+ GLushort* src = (GLushort*)pixels;
+ GLushort* downsized = malloc(width*height/2);
+ GLushort* ptr = downsized;
+ for (y=0; y<height;y+=2)
+ {
+ //GLbyte* row = src + y*width*4;
+ for (x=0;x<width;x+=2)
+ {
+ int off = (y*width+x);
+ *ptr ++ = src[off];
+ }
+ }
+
+ WRAPPERS_DEBUG_PRINTF("downscale/glTexImage2D(0x%x,%d,%d,%d,%d,%d,0x%x,0x%x,0x%x)\n", target, level, internalformat, width, height, border, format, type, pixels);
+ glTexImage2D(target, level, internalformat, width>>1, height>>1, border, format, type, downsized);
+ free(downsized);
+ }
+ else
+ if ( downscale && format==GL_RGBA && type==GL_UNSIGNED_BYTE )
+ {
+ int x,y;
+ GLbyte* src = (GLbyte*)pixels;
+ GLbyte* downsized = malloc(width*height*4/2);
+ GLbyte* ptr = downsized;
+ for (y=0; y<height;y+=2)
+ {
+ //GLbyte* row = src + y*width*4;
+ for (x=0;x<width;x+=2)
+ {
+ int off = (y*width+x)*4;
+ *ptr ++ = src[off+0];
+ *ptr ++ = src[off+1];
+ *ptr ++ = src[off+2];
+ *ptr ++ = src[off+3];
+ }
+ }
+ WRAPPERS_DEBUG_PRINTF("downscale/glTexImage2D(0x%x,%d,%d,%d,%d,%d,0x%x,0x%x,0x%x)\n", target, level, internalformat, width, height, border, format, type, pixels);
+ glTexImage2D(target, level, internalformat, width>>1, height>>1, border, format, type, downsized);
+ free(downsized);
+ }
+ else
+ {
+ if (downscale)
+ WRAPPERS_DEBUG_PRINTF("downlscale unsupported/glTexImage2D(0x%x,%d,%d,%d,%d,%d,0x%x,0x%x,0x%x)\n", target, level, internalformat, width, height, border, format, type, pixels);
+ else
+ WRAPPERS_DEBUG_PRINTF("glTexImage2D(0x%x,%d,%d,%d,%d,%d,0x%x,0x%x,0x%x)\n", target, level, internalformat, width, height, border, format, type, pixels);
+
+ glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
+ }
}
void
my_glTexParameteri(GLenum target, GLenum pname, GLint param)
@@ -873,11 +975,11 @@ void
my_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
WRAPPERS_DEBUG_PRINTF("glViewport()\n", x, y, width, height);
-#ifdef LANDSCAPE_TO_PORTRAIT
- glViewport(x, y, height, width);
-#else
- glViewport(x, y, width, height);
-#endif
+ if (global_module_hacks.gles_landscape_to_portrait!=0) {
+ glViewport(x, y, height, width);
+ } else {
+ glViewport(x, y, width, height);
+ }
}
void
my_glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer)
@@ -1189,79 +1291,79 @@ GLboolean
my_glIsRenderbufferOES(GLuint renderbuffer)
{
WRAPPERS_DEBUG_PRINTF("glIsRenderbufferOES()\n", renderbuffer);
- /* No CALL */ printf("UNIMPLEMENTED: glIsRenderbufferOES\n");
+ return extensions.glIsRenderbufferOES(renderbuffer);
}
void
my_glBindRenderbufferOES(GLenum target, GLuint renderbuffer)
{
WRAPPERS_DEBUG_PRINTF("glBindRenderbufferOES()\n", target, renderbuffer);
- /* No CALL */ printf("UNIMPLEMENTED: glBindRenderbufferOES\n");
+ extensions.glBindRenderbufferOES(target, renderbuffer);
}
void
my_glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers)
{
WRAPPERS_DEBUG_PRINTF("glDeleteRenderbuffersOES()\n", n, renderbuffers);
- /* No CALL */ printf("UNIMPLEMENTED: glDeleteRenderbuffersOES\n");
+ extensions.glDeleteRenderbuffersOES(n, renderbuffers);
}
void
my_glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers)
{
- WRAPPERS_DEBUG_PRINTF("glGenRenderbuffersOES()\n", n, renderbuffers);
- /* No CALL */ printf("UNIMPLEMENTED: glGenRenderbuffersOES\n");
+ WRAPPERS_DEBUG_PRINTF("my_glGenRenderbuffersOES()\n", n, renderbuffers);
+ extensions.glGenRenderbuffersOES(n,renderbuffers);
}
void
my_glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
{
WRAPPERS_DEBUG_PRINTF("glRenderbufferStorageOES()\n", target, internalformat, width, height);
- /* No CALL */ printf("UNIMPLEMENTED: glRenderbufferStorageOES\n");
+ extensions.glRenderbufferStorageOES(target, internalformat, width, height);
}
void
my_glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint *params)
{
WRAPPERS_DEBUG_PRINTF("glGetRenderbufferParameterivOES()\n", target, pname, params);
- /* No CALL */ printf("UNIMPLEMENTED: glGetRenderbufferParameterivOES\n");
+ extensions.glGetRenderbufferParameterivOES(target,pname,params);
}
GLboolean
my_glIsFramebufferOES(GLuint framebuffer)
{
WRAPPERS_DEBUG_PRINTF("glIsFramebufferOES()\n", framebuffer);
- /* No CALL */ printf("UNIMPLEMENTED: glIsFramebufferOES\n");
+ return extensions.glIsFramebufferOES(framebuffer);
}
void
my_glBindFramebufferOES(GLenum target, GLuint framebuffer)
{
WRAPPERS_DEBUG_PRINTF("glBindFramebufferOES()\n", target, framebuffer);
- /* No CALL */ printf("UNIMPLEMENTED: glBindFramebufferOES\n");
+ extensions.glBindFramebufferOES(target,framebuffer);
}
void
my_glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers)
{
WRAPPERS_DEBUG_PRINTF("glDeleteFramebuffersOES()\n", n, framebuffers);
- /* No CALL */ printf("UNIMPLEMENTED: glDeleteFramebuffersOES\n");
+ extensions.glDeleteFramebuffersOES(n, framebuffers);
}
void
my_glGenFramebuffersOES(GLsizei n, GLuint *framebuffers)
{
WRAPPERS_DEBUG_PRINTF("glGenFramebuffersOES()\n", n, framebuffers);
- /* No CALL */ printf("UNIMPLEMENTED: glGenFramebuffersOES\n");
+ extensions.glGenFramebuffersOES(n, framebuffers);
}
GLenum
my_glCheckFramebufferStatusOES(GLenum target)
{
WRAPPERS_DEBUG_PRINTF("glCheckFramebufferStatusOES()\n", target);
- /* No CALL */ printf("UNIMPLEMENTED: glCheckFramebufferStatusOES\n");
+ return extensions.glCheckFramebufferStatusOES(target);
}
void
my_glFramebufferRenderbufferOES(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
WRAPPERS_DEBUG_PRINTF("glFramebufferRenderbufferOES()\n", target, attachment, renderbuffertarget, renderbuffer);
- /* No CALL */ printf("UNIMPLEMENTED: glFramebufferRenderbufferOES\n");
+ extensions.glFramebufferRenderbufferOES(target, attachment, renderbuffertarget, renderbuffer);
}
void
my_glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
WRAPPERS_DEBUG_PRINTF("glFramebufferTexture2DOES()\n", target, attachment, textarget, texture, level);
- /* No CALL */ printf("UNIMPLEMENTED: glFramebufferTexture2DOES\n");
+ extensions.glFramebufferTexture2DOES(target,attachment,textarget,texture,level);
}
void
my_glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params)
@@ -1273,7 +1375,7 @@ void
my_glGenerateMipmapOES(GLenum target)
{
WRAPPERS_DEBUG_PRINTF("glGenerateMipmapOES()\n", target);
- /* No CALL */ printf("UNIMPLEMENTED: glGenerateMipmapOES\n");
+ extensions.glGenerateMipmapOES(target);
}
void
my_glCurrentPaletteMatrixOES(GLuint matrixpaletteindex)
View
@@ -518,4 +518,11 @@ void
my_glMultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) SOFTFP;
void
my_glMultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount) SOFTFP;
+
+
+///
+void
+gles_extensions_init();
+
+
#endif /* APKENV_GLES */
Oops, something went wrong.

0 comments on commit 545e26e

Please sign in to comment.