diff --git a/project/jni/glshim/Android.mk b/project/jni/glshim/Android.mk index 86c098937..e2c7e8508 100644 --- a/project/jni/glshim/Android.mk +++ b/project/jni/glshim/Android.mk @@ -38,9 +38,10 @@ LOCAL_SRC_FILES := \ src/gl/wrap/glesext.c \ src/gl/wrap/glstub.c \ src/gl/math/eval.c \ + src/glx/lookup.c \ src/glx/streaming.c -LOCAL_CFLAGS += -g -std=c99 -funwind-tables -O3 -DBCMHOST +LOCAL_CFLAGS += -g -std=c99 -funwind-tables -O3 -DBCMHOST -include include/android_debug.h LOCAL_LDLIBS := -ldl -llog -lEGL diff --git a/project/jni/glshim/include/android_debug.h b/project/jni/glshim/include/android_debug.h new file mode 100644 index 000000000..fca4445fd --- /dev/null +++ b/project/jni/glshim/include/android_debug.h @@ -0,0 +1,69 @@ +#ifndef __ANDROID_DEBUG_H__ +#define __ANDROID_DEBUG_H__ + +// Redirect printf() to Android log +// Put this file into CFLAGS: "-include ../android_debug.h" + +#include +#include +#include + +#ifdef __cplusplus +// Include everything beforehand, so we wont' get compiler eerors because of our #define +#include +#include +#include +#include +#include +#include + +namespace std +{ + class android_cout: public ostringstream + { + public: + android_cout() {} + template + android_cout &operator<<(const T &v) + { + *((ostringstream*)this) << v; + if( this->str().find('\n') != ::std::string::npos ) + { + __android_log_print(ANDROID_LOG_INFO, "glshim", "%s", this->str().c_str()); + this->str().clear(); + } + return *this; + } + ~android_cout() + { + __android_log_print(ANDROID_LOG_INFO, "glshim", "%s", this->str().c_str()); + this->str().clear(); + } + }; + static const char * android_endl = "\n"; +} +#define cout android_cout() +#define cerr android_cout() +#define endl android_endl + +#endif + +#define printf(...) __android_log_print(ANDROID_LOG_INFO, "glshim", __VA_ARGS__) + +// Override fprintf(stderr, ...) constructs +static inline int __sdl_logged_fprintf(FILE *stream, const char *format, ...) +{ + int ret = 0; + va_list args; + va_start(args, format); + if( stream == stderr || stream == stdout ) + ret = __android_log_vprint(ANDROID_LOG_INFO, "glshim", format, args); + else + ret = vfprintf(stream, format, args); + va_end(args); + return ret; +} + +#define fprintf(...) __sdl_logged_fprintf(__VA_ARGS__) + +#endif diff --git a/project/jni/glshim/src/gl/gl.c b/project/jni/glshim/src/gl/gl.c index 87894f906..0ef9ebc0a 100755 --- a/project/jni/glshim/src/gl/gl.c +++ b/project/jni/glshim/src/gl/gl.c @@ -333,13 +333,13 @@ void glGetFloatv(GLenum pname, GLfloat *params) { *params=MAX_STACK_TEXTURE; break; case GL_MODELVIEW_STACK_DEPTH: - *params=(state.modelview_matrix)?1:(state.modelview_matrix->top+1); + *params=(state.modelview_matrix)?(state.modelview_matrix->top+1):1; break; case GL_PROJECTION_STACK_DEPTH: - *params=(state.projection_matrix)?1:(state.projection_matrix->top+1); + *params=(state.projection_matrix)?(state.projection_matrix->top+1):1; break; case GL_TEXTURE_STACK_DEPTH: - *params=(state.texture_matrix)?1:(state.texture_matrix[state.texture.active]->top+1); + *params=(state.texture_matrix)?(state.texture_matrix[state.texture.active]->top+1):1; break; case GL_MAX_LIST_NESTING: *params=64; // fake, no limit in fact @@ -380,7 +380,7 @@ static void proxy_glEnable(GLenum cap, bool enable, void (*next)(GLenum)) { // 2. enable GL_TEXTURE_2D // 3. disable GL_TEXTURE_1D // 4. render. GL_TEXTURE_2D would be disabled. - cap = map_tex_target(cap); + // cap = map_tex_target(cap); // Alpha Hack if (alphahack && (cap==GL_ALPHA_TEST) && enable) @@ -407,6 +407,11 @@ static void proxy_glEnable(GLenum cap, bool enable, void (*next)(GLenum)) { proxy_enable(GL_NORMAL_ARRAY, normal_array); proxy_enable(GL_COLOR_ARRAY, color_array); proxy_enable(GL_TEXTURE_COORD_ARRAY, tex_coord_array[state.texture.client]); + + // Texture 1D and 3D + enable(GL_TEXTURE_1D, texture_1d[state.texture.active]); + enable(GL_TEXTURE_3D, texture_3d[state.texture.active]); + default: errorGL(); next(cap); break; } #undef proxy_enable @@ -471,6 +476,10 @@ GLboolean glIsEnabled(GLenum cap) { return state.enable.color_sum; case GL_SECONDARY_COLOR_ARRAY: return state.enable.secondary_array; + case GL_TEXTURE_1D: + return state.enable.texture_1d[state.texture.active]; + case GL_TEXTURE_3D: + return state.enable.texture_1d[state.texture.active]; default: errorGL(); return gles_glIsEnabled(cap); @@ -565,6 +574,8 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indic LOAD_GLES(glVertexPointer); LOAD_GLES(glColorPointer); LOAD_GLES(glTexCoordPointer); + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); GLuint len = 0; for (int i=0; i=GL_TRIANGLES) { int n, s; @@ -661,6 +677,14 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indic free(final_colors); // glColorPointer(old_color.size, old_color.type, old_color.stride, old_color.pointer); } + for (int aa=0; aadata; @@ -686,6 +710,8 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { LOAD_GLES(glVertexPointer); LOAD_GLES(glColorPointer); LOAD_GLES(glTexCoordPointer); + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); renderlist_t *list, *active = state.list.active; if (active && (state.list.compiling || state.gl_batch)) { @@ -753,15 +779,20 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { gles_glNormalPointer(state.pointers.normal.type, state.pointers.normal.stride, state.pointers.normal.pointer); if (state.enable.vertex_array) gles_glVertexPointer(state.pointers.vertex.size, state.pointers.vertex.type, state.pointers.vertex.stride, state.pointers.vertex.pointer); - //GLuint old_tex = state.texture.client; - for (int aa=0; aa=GL_TRIANGLES) { int n, s; @@ -800,6 +831,14 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { if (final_colors) { free(final_colors); } + for (int aa=0; aadata; diff --git a/project/jni/glshim/src/gl/state.h b/project/jni/glshim/src/gl/state.h index 9360891c3..3cf7a689f 100755 --- a/project/jni/glshim/src/gl/state.h +++ b/project/jni/glshim/src/gl/state.h @@ -19,7 +19,9 @@ typedef struct { texgen_s[MAX_TEX], texgen_t[MAX_TEX], texgen_r[MAX_TEX], - texture_2d[MAX_TEX]; + texture_2d[MAX_TEX], + texture_3d[MAX_TEX], + texture_1d[MAX_TEX]; } enable_state_t; diff --git a/project/jni/glshim/src/gl/texture.c b/project/jni/glshim/src/gl/texture.c index ee6ab8687..4d83164ae 100755 --- a/project/jni/glshim/src/gl/texture.c +++ b/project/jni/glshim/src/gl/texture.c @@ -311,7 +311,8 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, } } if (bound && (texshrink==2 || texshrink==3)) { - if (((width > ((texshrink==2)?512:256)) && (height > 8)) || ((height > ((texshrink==2)?512:256)) && (width > 8))) { + if (((width%2==0) && (height%2==0)) && + ((width > ((texshrink==2)?512:256)) && (height > 8)) || ((height > ((texshrink==2)?512:256)) && (width > 8))) { GLvoid *out = pixels; pixel_halfscale(pixels, &out, width, height, format, type); if (out != pixels && pixels!=datab) @@ -323,7 +324,8 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, } } if (bound && (texshrink==4)) { - if (((width > 256) && (height > 8)) || ((height > 256) && (width > 8))) { + if (((width%4==0) && (height%4==0)) && + ((width > 256) && (height > 8)) || ((height > 256) && (width > 8))) { if ((width>=1024) || (height>=1024)) { GLvoid *out = pixels; pixel_quarterscale(pixels, &out, width, height, format, type); @@ -346,7 +348,8 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, } } if (bound && (texshrink==5)) { - while (((width > 256) && (height > 8)) || ((height > 256) && (width > 8))) { + while (((width%2==0) && (height%2==0)) && + ((width > 256) && (height > 8)) || ((height > 256) && (width > 8))) { GLvoid *out = pixels; pixel_halfscale(pixels, &out, width, height, format, type); if (out != pixels && pixels!=datab) @@ -358,8 +361,9 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, } } if (bound && (texshrink==6)) { - if (((width > 128) && (height > 8)) || ((height > 128) && (width > 8))) { - if ((width>=512) || (height>=512)) { + if (((width%2==0) && (height%2==0)) && + ((width > 128) && (height > 8)) || ((height > 128) && (width > 8))) { + if (((width%2==0) && (height%2==0)) && (width>=512) || (height>=512)) { while (((width > 256) && (height > 8)) || ((height > 256) && (width > 8))) { GLvoid *out = pixels; pixel_halfscale(pixels, &out, width, height, format, type); diff --git a/project/jni/glshim/src/glx/lookup.c b/project/jni/glshim/src/glx/lookup.c index caa07b8aa..55d0fdabb 100755 --- a/project/jni/glshim/src/glx/lookup.c +++ b/project/jni/glshim/src/glx/lookup.c @@ -1,4 +1,10 @@ +#ifdef ANDROID +#include "../gl/gl.h" +#else #include "glx.h" +#endif + + #define MAP(func_name, func) \ if (strcmp(name, func_name) == 0) return (void *)func; @@ -31,6 +37,7 @@ void *glXGetProcAddressARB(const char *name) { #include "glesfuncs.inc" #endif +#ifndef ANDROID // glX calls EX(glXChooseVisual); EX(glXCopyContext); @@ -66,7 +73,8 @@ void *glXGetProcAddressARB(const char *name) { EX(glXGetVisualFromFBConfig); EX(glXCreateWindow); EX(glXDestroyWindow); - +#endif + // GL_ARB_vertex_buffer_object ARB(glBindBuffer); ARB(glBufferData); @@ -437,6 +445,7 @@ void *glXGetProcAddressARB(const char *name) { STUB(glIndexPointer); printf("glXGetProcAddress: %s not found.\n", name); + return NULL; }