Merge branch 'sdl_android' of github.com:pelya/commandergenius into sdl_android

This commit is contained in:
Sergii Pylypenko
2015-03-06 22:33:01 +02:00
6 changed files with 144 additions and 20 deletions

View File

@@ -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

View File

@@ -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 <stdio.h>
#include <stdarg.h>
#include <android/log.h>
#ifdef __cplusplus
// Include everything beforehand, so we wont' get compiler eerors because of our #define
#include <string>
#include <ios>
#include <streambuf>
#include <sstream>
#include <fstream>
#include <iostream>
namespace std
{
class android_cout: public ostringstream
{
public:
android_cout() {}
template <class T>
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

View File

@@ -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<count; i++)
if (len<sindices[i]) len = sindices[i]; // get the len of the arrays
@@ -613,15 +624,20 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indic
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<MAX_TEX; aa++)
GLuint old_tex = state.texture.client;
for (int aa=0; aa<MAX_TEX; aa++) {
if (!state.enable.texture_2d[aa] && (state.enable.texture_1d[aa] || state.enable.texture_3d[aa])) {
glClientActiveTexture(aa+GL_TEXTURE0);
gles_glEnable(GL_TEXTURE_2D);
}
if (state.enable.tex_coord_array[aa]) {
tex_setup_texcoord(aa, len);
/*glClientActiveTexture(aa+GL_TEXTURE0);
gles_glTexCoordPointer(state.pointers.tex_coord[aa].size, state.pointers.tex_coord[aa].type, state.pointers.tex_coord[aa].stride, state.pointers.tex_coord[aa].pointer);*/
}
/*if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);*/
}
if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);
if (state.polygon_mode == GL_LINE && mode_init>=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; aa<MAX_TEX; aa++) {
if (!state.enable.texture_2d[aa] && (state.enable.texture_1d[aa] || state.enable.texture_3d[aa])) {
glClientActiveTexture(aa+GL_TEXTURE0);
gles_glDisable(GL_TEXTURE_2D);
}
}
if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);
}
#define shift_pointer(a, b) \
if (state.enable.b && state.pointers.a.buffer) state.pointers.a.pointer -= (uintptr_t)state.pointers.a.buffer->data;
@@ -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<MAX_TEX; aa++)
GLuint old_tex = state.texture.client;
for (int aa=0; aa<MAX_TEX; aa++) {
if (!state.enable.texture_2d[aa] && (state.enable.texture_1d[aa] || state.enable.texture_3d[aa])) {
glClientActiveTexture(aa+GL_TEXTURE0);
gles_glEnable(GL_TEXTURE_2D);
}
if (state.enable.tex_coord_array[aa]) {
tex_setup_texcoord(aa, count+first);
/*glClientActiveTexture(aa+GL_TEXTURE0);
gles_glTexCoordPointer(state.pointers.tex_coord[aa].size, state.pointers.tex_coord[aa].type, state.pointers.tex_coord[aa].stride, state.pointers.tex_coord[aa].pointer);*/
}
/*if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);*/
}
if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);
if (state.polygon_mode == GL_LINE && mode_init>=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; aa<MAX_TEX; aa++) {
if (!state.enable.texture_2d[aa] && (state.enable.texture_1d[aa] || state.enable.texture_3d[aa])) {
glClientActiveTexture(aa+GL_TEXTURE0);
gles_glDisable(GL_TEXTURE_2D);
}
}
if (state.texture.client!=old_tex)
glClientActiveTexture(old_tex+GL_TEXTURE0);
#define shift_pointer(a, b) \
if (state.enable.b && state.pointers.a.buffer) state.pointers.a.pointer = state.pointers.a.pointer - (uintptr_t)state.pointers.a.buffer->data;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
}