From 5a322df4da3102ae0c8d3bc3071386dc5f21e580 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Oct 2012 02:24:54 +0300 Subject: Add OpenGL support for Android builds (partially). --- configure.ac | 9 +++++++-- src/graphicsmanager.cpp | 10 ++++++++++ src/graphicsmanager.h | 6 ++++++ src/graphicsvertexes.h | 8 ++++++-- src/mgl.h | 17 ++++++++++++++++- src/normalopenglgraphics.cpp | 17 +++++++++++------ src/normalopenglgraphics.h | 8 ++++++-- src/resources/fboinfo.h | 5 +++++ src/resources/image.h | 6 +++++- src/resources/openglimagehelper.h | 11 +++++++++++ src/resources/subimage.h | 11 +++++------ src/safeopenglgraphics.cpp | 5 ----- src/safeopenglgraphics.h | 7 +++++-- 13 files changed, 93 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index a4e9f68f0..512f42dfa 100755 --- a/configure.ac +++ b/configure.ac @@ -152,8 +152,13 @@ if test "x$with_opengl" == "xno"; then else with_opengl=yes if test "x$applebuild_enabled" == "xfalse"; then - AC_CHECK_LIB([GL], [glBegin], , - AC_MSG_ERROR([ *** Unable to find OpenGL library])) + + if test "x$androidbuild_enabled" == "xfalse"; then + AC_CHECK_LIB([GL], [glBegin], , + AC_MSG_ERROR([ *** Unable to find OpenGL library])) + else + LDFLAGS="$LDFLAGS -lGLESv2 -lEGL" + fi else LDFLAGS="$LDFLAGS -framework OpenGL" fi diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index c69937073..a9efd8e13 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -21,11 +21,19 @@ #include "graphicsmanager.h" #ifdef USE_OPENGL + #ifndef WIN32 +#ifdef ANDROID +#include +#include +#include +#else #include "GL/glx.h" #endif #endif +#endif + #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" @@ -53,6 +61,8 @@ #ifdef WIN32 #define getFunction(name) wglGetProcAddress(name) +#elif ANDROID +#define getFunction(name) eglGetProcAddress(name) #else #define getFunction(name) glXGetProcAddress(\ reinterpret_cast(name)) diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index b16c63fbf..53de59c46 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -24,6 +24,10 @@ #include "main.h" #ifdef USE_OPENGL + +#ifdef ANDROID +#include +#else #define GL_GLEXT_PROTOTYPES 1 #include // hack to hide warnings @@ -31,6 +35,8 @@ #undef GL_GLEXT_PROTOTYPES #endif +#endif + #include #include diff --git a/src/graphicsvertexes.h b/src/graphicsvertexes.h index 69d391864..789e9fd34 100644 --- a/src/graphicsvertexes.h +++ b/src/graphicsvertexes.h @@ -27,11 +27,15 @@ #include "localconsts.h" #ifdef USE_OPENGL -//#define NO_SDL_GLEXT + +#ifdef ANDROID +#include +#else #define GL_GLEXT_PROTOTYPES 1 +#include +#endif #include -#include #include "safeopenglgraphics.h" #include "normalopenglgraphics.h" diff --git a/src/mgl.h b/src/mgl.h index e01ad6ec2..5050c5dea 100644 --- a/src/mgl.h +++ b/src/mgl.h @@ -24,10 +24,15 @@ #include "main.h" #ifdef USE_OPENGL +#ifdef ANDROID +#include +#include +#define APIENTRY GL_APIENTRY +#else #define GL_GLEXT_PROTOTYPES 1 - #include #include +#endif #define GL_NUM_EXTENSIONS 0x821D #define GL_DEPTH_ATTACHMENT 0x8D00 @@ -35,6 +40,16 @@ #define GL_FRAMEBUFFER 0x8D40 #define GL_RENDERBUFFER 0x8D41 +#ifndef GL_COMPRESSED_RGBA_ARB +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif +#ifndef GL_MAX_ELEMENTS_VERTICES +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#endif + #define defNameE(name) extern name##_t m##name typedef void (APIENTRY *glGenRenderbuffers_t)(GLsizei, GLuint *); diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 32175c05f..cc0e05b3f 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -40,11 +40,6 @@ #include "debug.h" -#ifndef GL_TEXTURE_RECTANGLE_ARB -#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 -#endif - GLuint NormalOpenGLGraphics::mLastImage = 0; unsigned int vertexBufSize = 500; @@ -949,8 +944,13 @@ void NormalOpenGLGraphics::_beginDraw() glMatrixMode(GL_PROJECTION); glLoadIdentity(); +#ifdef ANDROID + glOrthof(0.0, static_cast(mTarget->w), + static_cast(mTarget->h), 0.0, -1.0, 1.0); +#else glOrtho(0.0, static_cast(mTarget->w), static_cast(mTarget->h), 0.0, -1.0, 1.0); +#endif glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -963,14 +963,15 @@ void NormalOpenGLGraphics::_beginDraw() glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); +#ifndef ANDROID glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); - #ifndef __MINGW32__ glHint(GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST); #endif +#endif // glScalef(0.5f, 0.5f, 0.5f); @@ -1093,9 +1094,13 @@ void NormalOpenGLGraphics::drawPoint(int x, int y) setTexturingAndBlending(false); restoreColor(); +#ifdef ANDROID + // TODO need fix +#else glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); +#endif } void NormalOpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) diff --git a/src/normalopenglgraphics.h b/src/normalopenglgraphics.h index b6a09728e..35bdf557e 100644 --- a/src/normalopenglgraphics.h +++ b/src/normalopenglgraphics.h @@ -31,11 +31,15 @@ #include "resources/fboinfo.h" -//#define NO_SDL_GLEXT +#ifdef ANDROID +#include +#include +#include +#else #define GL_GLEXT_PROTOTYPES 1 - #include #include +#endif #include diff --git a/src/resources/fboinfo.h b/src/resources/fboinfo.h index 54415e697..dcc76d435 100644 --- a/src/resources/fboinfo.h +++ b/src/resources/fboinfo.h @@ -28,8 +28,13 @@ #include "resources/fboinfo.h" +#ifdef ANDROID +#include +#include +#else #include #include +#endif struct FBOInfo final { diff --git a/src/resources/image.h b/src/resources/image.h index 3752965bc..36404b2b1 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -37,10 +37,14 @@ * extensions anyway it's safe to just disable the SDL version. */ //#define NO_SDL_GLEXT -#define GL_GLEXT_PROTOTYPES 1 +#ifdef ANDROID +#include +#else +#define GL_GLEXT_PROTOTYPES 1 #include #endif +#endif #include diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h index 02641f85f..b0428f58a 100644 --- a/src/resources/openglimagehelper.h +++ b/src/resources/openglimagehelper.h @@ -27,14 +27,25 @@ #include "main.h" #ifdef USE_OPENGL + +#ifndef GL_TEXTURE_RECTANGLE_ARB +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + #include "utils/stringvector.h" #include "resources/imagehelper.h" #include +#ifdef ANDROID +#include +#define GL_RGBA8 GL_RGBA8_OES +#else #define GL_GLEXT_PROTOTYPES 1 #include +#endif class Dye; class Image; diff --git a/src/resources/subimage.h b/src/resources/subimage.h index 47d8476cb..69e0debab 100644 --- a/src/resources/subimage.h +++ b/src/resources/subimage.h @@ -30,16 +30,15 @@ #ifdef USE_OPENGL -/* The definition of OpenGL extensions by SDL is giving problems with recent - * gl.h headers, since they also include these definitions. As we're not using - * extensions anyway it's safe to just disable the SDL version. - */ -//#define NO_SDL_GLEXT +#ifdef ANDROID +#include +#else #define GL_GLEXT_PROTOTYPES 1 - #include #endif +#endif + #include "resources/image.h" /** diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index 78210b7f8..113a33baa 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -37,11 +37,6 @@ #include "debug.h" -#ifndef GL_TEXTURE_RECTANGLE_ARB -#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 -#endif - GLuint SafeOpenGLGraphics::mLastImage = 0; SafeOpenGLGraphics::SafeOpenGLGraphics(): diff --git a/src/safeopenglgraphics.h b/src/safeopenglgraphics.h index 44c15545f..81494d5bd 100644 --- a/src/safeopenglgraphics.h +++ b/src/safeopenglgraphics.h @@ -30,11 +30,14 @@ #include "resources/fboinfo.h" -//#define NO_SDL_GLEXT +#ifdef ANDROID +#include +#include +#else #define GL_GLEXT_PROTOTYPES 1 - #include #include +#endif class SafeOpenGLGraphics final : public Graphics { -- cgit v1.2.3-70-g09d2