From 1064c9c73b953909de2476f99402f8209aa60ea8 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 24 Jul 2016 20:27:51 +0000 Subject: [PATCH] Make XashXT renderer work --- Android.mk | 2 +- GL/gl.h | 5 ++- GL/gl_entries.in | 18 ++++---- nanoWrap.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++--- nanogl.cpp | 21 +++++++-- 5 files changed, 133 insertions(+), 21 deletions(-) diff --git a/Android.mk b/Android.mk index 70c5634..7cba042 100644 --- a/Android.mk +++ b/Android.mk @@ -20,7 +20,7 @@ LOCAL_MODULE := NanoGL include $(XASH3D_CONFIG) -LOCAL_CFLAGS += +LOCAL_CFLAGS += -D__MULTITEXTURE_SUPPORT__ LOCAL_C_INCLUDES := $(LOCAL_PATH)/GL diff --git a/GL/gl.h b/GL/gl.h index 48fb508..37a2a84 100644 --- a/GL/gl.h +++ b/GL/gl.h @@ -718,10 +718,11 @@ void glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderb void glNormalPointer(GLenum type, GLsizei stride, const void *ptr); -void pglMultiTexCoord3f(GLenum, GLfloat, GLfloat, GLfloat); +void glMultiTexCoord3f(GLenum, GLfloat, GLfloat, GLfloat); -void pglMultiTexCoord2f(GLenum, GLfloat, GLfloat); +void glMultiTexCoord2f(GLenum, GLfloat, GLfloat); +void glDrawArrays( GLenum mode, GLint first, GLsizei count ); #ifdef __cplusplus } diff --git a/GL/gl_entries.in b/GL/gl_entries.in index 70b1fb3..19220c2 100644 --- a/GL/gl_entries.in +++ b/GL/gl_entries.in @@ -187,12 +187,12 @@ #endif // fbo -GL_ENTRY(void, glGenFramebuffers, GLsizei n, GLuint* framebuffers) -GL_ENTRY(void, glGenRenderbuffers, GLsizei n, GLuint* renderbuffers) -GL_ENTRY(void, glRenderbufferStorage, GLenum target, GLenum internalformat, GLsizei width, GLsizei height) -GL_ENTRY(void, glBindFramebuffer, GLenum target, GLuint framebuffer) -GL_ENTRY(void, glBindRenderbuffer, GLenum target, GLuint renderbuffer) -GL_ENTRY(void, glFramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) -GL_ENTRY(void, glDeleteRenderbuffers, GLsizei n, const GLuint* renderbuffers) -GL_ENTRY(void, glDeleteFramebuffers, GLsizei n, const GLuint* framebuffers) -GL_ENTRY(void, glFramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +GL_ENTRY(void,glGenFramebuffersOES, GLsizei n, GLuint* framebuffers) +GL_ENTRY(void,glGenRenderbuffersOES, GLsizei n, GLuint* renderbuffers) +GL_ENTRY(void,glRenderbufferStorageOES, GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +GL_ENTRY(void,glBindFramebufferOES, GLenum target, GLuint framebuffer) +GL_ENTRY(void,glBindRenderbufferOES, GLenum target, GLuint renderbuffer) +GL_ENTRY(void,glFramebufferTexture2DOES, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +GL_ENTRY(void,glDeleteRenderbuffersOES, GLsizei n, const GLuint* renderbuffers) +GL_ENTRY(void,glDeleteFramebuffersOES, GLsizei n, const GLuint* framebuffers) +GL_ENTRY(void,glFramebufferRenderbufferOES, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) diff --git a/nanoWrap.cpp b/nanoWrap.cpp index 5ea8acf..a2189f3 100644 --- a/nanoWrap.cpp +++ b/nanoWrap.cpp @@ -1839,11 +1839,11 @@ void glMultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t ) #endif /* Vladimir */ -void glDrawArrays( GLenum mode, int first, int count) +/*void glDrawArrays( GLenum mode, int first, int count) { FlushOnStateChange(); glEsImpl->glDrawArrays(mode, first , count); -} +}*/ void glMultMatrixf (const GLfloat *m) { FlushOnStateChange(); @@ -1942,16 +1942,114 @@ void glTexEnvi (GLenum target, GLenum pname, GLint param) glEsImpl->glTexEnvi(target, pname, param); } -void pglMultiTexCoord3f(GLenum, GLfloat, GLfloat, GLfloat) +void glMultiTexCoord3fARB(GLenum, GLfloat, GLfloat, GLfloat) { } -void pglMultiTexCoord2f(GLenum, GLfloat, GLfloat) +void glMultiTexCoord2f(GLenum, GLfloat, GLfloat) { } +void glDrawArrays( GLenum mode, GLint first, GLsizei count ) + { + // ensure that all primitives specified between glBegin/glEnd pairs + // are rendered first, and that we have correct tmu in use.. + if( mode == GL_QUADS ) mode = GL_TRIANGLE_FAN; + FlushOnStateChange(); + // setup correct vertex/color/texcoord pointers + if (arraysValid || + tmuState0.vertex_array.changed || + tmuState0.color_array.changed || + tmuState0.texture_coord_array.changed || tmuState0.normal_array.changed) + { + glEsImpl->glClientActiveTexture(GL_TEXTURE0); + } + if (arraysValid || tmuState0.vertex_array.changed) + { + if (tmuState0.vertex_array.enabled) + { + glEsImpl->glEnableClientState(GL_VERTEX_ARRAY); + } + else + { + glEsImpl->glDisableClientState(GL_VERTEX_ARRAY); + } + glEsImpl->glVertexPointer(tmuState0.vertex_array.size, + tmuState0.vertex_array.type, + tmuState0.vertex_array.stride, + tmuState0.vertex_array.ptr); + tmuState0.vertex_array.changed = GL_FALSE; + } + if (arraysValid || tmuState0.color_array.changed) + { + if (tmuState0.color_array.enabled) + { + glEsImpl->glEnableClientState(GL_COLOR_ARRAY); + } + else + { + glEsImpl->glDisableClientState(GL_COLOR_ARRAY); + } + glEsImpl->glColorPointer(tmuState0.color_array.size, + tmuState0.color_array.type, + tmuState0.color_array.stride, + tmuState0.color_array.ptr); + tmuState0.color_array.changed = GL_FALSE; + } + if (arraysValid || tmuState0.normal_array.changed) + { + if (tmuState0.normal_array.enabled) + { + glEsImpl->glEnableClientState(GL_NORMAL_ARRAY); + } + else + { + glEsImpl->glDisableClientState(GL_NORMAL_ARRAY); + } + glEsImpl->glNormalPointer(tmuState0.normal_array.type, + tmuState0.normal_array.stride, + tmuState0.normal_array.ptr); + tmuState0.normal_array.changed = GL_FALSE; + } + if (arraysValid || tmuState0.texture_coord_array.changed) + { + tmuState0.texture_coord_array.changed = GL_FALSE; + if (tmuState0.texture_coord_array.enabled) + { + glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else + { + glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glEsImpl->glTexCoordPointer(tmuState0.texture_coord_array.size, + tmuState0.texture_coord_array.type, + tmuState0.texture_coord_array.stride, + tmuState0.texture_coord_array.ptr); + } + + if (arraysValid || tmuState1.texture_coord_array.changed) + { + tmuState1.texture_coord_array.changed = GL_FALSE; + glEsImpl->glClientActiveTexture(GL_TEXTURE1); + if (tmuState1.texture_coord_array.enabled) + { + glEsImpl->glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else + { + glEsImpl->glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glEsImpl->glTexCoordPointer(tmuState1.texture_coord_array.size, + tmuState1.texture_coord_array.type, + tmuState1.texture_coord_array.stride, + tmuState1.texture_coord_array.ptr); + } + arraysValid = GL_FALSE; + glEsImpl->glDrawArrays(mode, first, count); + } /*void glNormalPointer(GLenum type, GLsizei stride, const void *ptr) { glEsImpl->glNormalPointer( type, stride, ptr ); @@ -1973,7 +2071,7 @@ void glGenFramebuffers (GLsizei n, GLuint* framebuffers) void glGenRenderbuffers( GLsizei n, GLuint* renderbuffers ) { FlushOnStateChange(); - glEsImpl->glGenFramebuffers( n, renderbuffers ); + glEsImpl->glGenRenderbuffers( n, renderbuffers ); } void glBindRenderbuffer(GLenum target, GLuint renderbuffer) diff --git a/nanogl.cpp b/nanogl.cpp index 5f97fed..c8454b0 100644 --- a/nanogl.cpp +++ b/nanogl.cpp @@ -144,9 +144,9 @@ static int CreateGlEsInterface( const char * name, void * lib, void * lib1, void if ( f == NULL ) { LOGE ( "<%s> not found in libEGL.so", *api); if( glEsImpl->eglGetProcAddress && ( (void*)glEsImpl->eglGetProcAddress != (void*)gl_unimplemented ) ) - f = glEsImpl->eglGetProcAddress( *api ); + f = (void*)glEsImpl->eglGetProcAddress( *api ); if(f == NULL) - f = default_func; //(void*)gl_unimplemented; + f = (void*)default_func; //(void*)gl_unimplemented; } else { @@ -157,9 +157,9 @@ static int CreateGlEsInterface( const char * name, void * lib, void * lib1, void { LOGE ( "libEGL.so not loaded!"); if( glEsImpl->eglGetProcAddress && ( (void*)glEsImpl->eglGetProcAddress != (void*)gl_unimplemented ) ) - f = glEsImpl->eglGetProcAddress( *api ); + f = (void*)glEsImpl->eglGetProcAddress( *api ); if( !f ) - f = default_func; + f = (void*)default_func; } } else { @@ -285,6 +285,19 @@ int nanoGL_Init() return 0; } +#ifdef __ANDROID__ + // somewhy it does not initialize correctly + *((void**)&glEsImpl->glGenFramebuffers) = (void*)glEsImpl->eglGetProcAddress( "glGenFramebuffersOES" ); + *((void**)&glEsImpl->glGenRenderbuffers) = (void*)glEsImpl->eglGetProcAddress( "glGenRenderbuffersOES" ); + *((void**)&glEsImpl->glRenderbufferStorage) = (void*)glEsImpl->eglGetProcAddress( "glRenderbufferStorageOES" ); + *((void**)&glEsImpl->glBindFramebuffer) = (void*)glEsImpl->eglGetProcAddress( "glBindFramebufferOES" ); + *((void**)&glEsImpl->glBindRenderbuffer) = (void*)glEsImpl->eglGetProcAddress( "glBindRenderbufferOES" ); + *((void**)&glEsImpl->glFramebufferTexture2D) = (void*)glEsImpl->eglGetProcAddress( "glFramebufferTexture2DOES" ); + *((void**)&glEsImpl->glDeleteRenderbuffers) = (void*)glEsImpl->eglGetProcAddress( "glDeleteRenderbuffersOES" ); + *((void**)&glEsImpl->glDeleteFramebuffers) = (void*)glEsImpl->eglGetProcAddress( "glDeleteFramebuffersOES" ); + *((void**)&glEsImpl->glFramebufferRenderbuffer) = (void*)glEsImpl->eglGetProcAddress( "glFramebufferRenderbufferOES" ); +#endif + // Init nanoGL InitGLStructs(); return 1; -- 2.29.2