diff options
author | frogbotherer <therealchriswest@hotmail.com> | 2012-09-08 13:40:44 +0200 |
---|---|---|
committer | Raphael Langella <raphael.langella@gmail.com> | 2012-09-08 13:40:44 +0200 |
commit | f4002528321dbb23f92bade00d46ce515dd1bd27 (patch) | |
tree | c4c8a91fdbe7f14f4a6d66f59f0b1e8429a553f8 /crawl-ref/source/glwrapper-ogl.cc | |
parent | 58ccbffacfa6feedebee83d6fc22b9037f29bf92 (diff) | |
download | crawl-ref-f4002528321dbb23f92bade00d46ce515dd1bd27.tar.gz crawl-ref-f4002528321dbb23f92bade00d46ce515dd1bd27.zip |
Android port.
2 files are added to the root of the repository:
* AndroidAppSettings.cfg: settings file required for Android SDL port. Will
change on each minor release to reset configuration.
* AndroidBuild.sh: script called by the Android SDL port to commence building
the game itself
It might be nice to be able to move them elsewhere, but for now, their
presence here is required.
The build process is documented in docs/develop/android.txt
There's a TOUCH_UI compiler flag which sets all the things specific to a
touch screen interface.
There has been a large amount of changes in the Makefile for redefining where
the dat/, saves/, etc. directories go, because the "install" part of the make
isn't the final destination for these files under Android - the environment we
deploy to is a separate device from the build environment.
There is also a number of changes to the tiles interface. Some are specific
to the TOUCH_UI, but others are also changed in USE_TILE_LOCAL.
Touch only:
* 'a'bilities menu goes straight to menu without prompting first
* tap menu header to toggle/submit
* menu instead of prompt to select which corpse to butcher
* same for eating food from the floor (those 2 could go in local tiles too)
* show_more defaults to false and less --more-- messages
* pickup mode defaults to menu
* defaults for tile_layout_priority is different (commands are more
important than inventory)
* popup for yes/no prompts, level-up stat gain and swapping rings (should
be used for all prompts, and probably local tiles too)
* spell casting: force selection menu
* map mode: left-click rather than right-click for mouse mode; autotravel on
left-click removed
* remove skills training and memorisation panels
Also local tiles (some could also be integrated in webtiles):
* commands below description are clickable
* clickable shopping menu (uses PrecisionMenu)
* split the command panel in 2 (common actions and system commands)
* add a map command panel
* tapping or left-clicking the player is smarter:
* picks up the item if there's one on the tile, otherwise
* shows pick-up menu if there's several items on the tile, otherwise
* traverses stairs (or enters a portal or shop) if one is present, otherwise
* prays if an altar is present, otherwise
* waits one turn
* right-clicking the map enters map mode and brings the map commands tab to
the front; map mode stays until exited rather than upon release of mouse
Some more details can be found in android_patch_notes.txt on #5677 (although
some TODOs are already obsolete).
Signed-off-by: Raphael Langella <raphael.langella@gmail.com>
Diffstat (limited to 'crawl-ref/source/glwrapper-ogl.cc')
-rw-r--r-- | crawl-ref/source/glwrapper-ogl.cc | 219 |
1 files changed, 213 insertions, 6 deletions
diff --git a/crawl-ref/source/glwrapper-ogl.cc b/crawl-ref/source/glwrapper-ogl.cc index 98c6672b91..48999688c8 100644 --- a/crawl-ref/source/glwrapper-ogl.cc +++ b/crawl-ref/source/glwrapper-ogl.cc @@ -9,13 +9,24 @@ // If other UI types use the -ogl wrapper they should // include more conditional includes here. #ifdef USE_SDL -#ifdef USE_GLES -#include <SDL.h> -#include <SDL_gles.h> -#include <GLES/gl.h> -#else -#include <SDL_opengl.h> +# ifdef USE_GLES +# include <SDL.h> +# ifndef __ANDROID__ +# include <SDL_gles.h> +# endif +# include <GLES/gl.h> +# else +# ifdef __ANDROID__ +# include <SDL.h> +# include <GLES/gl.h> +# else +# include <SDL_opengl.h> +# endif +# endif #endif + +#ifdef __ANDROID__ +# include <android/log.h> #endif #include "debug.h" @@ -56,6 +67,10 @@ OGLStateManager::OGLStateManager() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0, 0.0, 0.0, 1.0f); glDepthFunc(GL_LEQUAL); + +#ifdef __ANDROID__ + m_last_tex = 0; +#endif } void OGLStateManager::set(const GLState& state) @@ -63,56 +78,91 @@ void OGLStateManager::set(const GLState& state) if (state.array_vertex != m_current_state.array_vertex) { if (state.array_vertex) + { glEnableClientState(GL_VERTEX_ARRAY); + glDebug("glEnableClientState(GL_VERTEX_ARRAY)"); + } else + { glDisableClientState(GL_VERTEX_ARRAY); + glDebug("glDisableClientState(GL_VERTEX_ARRAY)"); + } } if (state.array_texcoord != m_current_state.array_texcoord) { if (state.array_texcoord) + { glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glDebug("glEnableClientState(GL_TEXTURE_COORD_ARRAY)"); + } else + { glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDebug("glDisableClientState(GL_TEXTURE_COORD_ARRAY)"); + } } if (state.array_colour != m_current_state.array_colour) { if (state.array_colour) + { glEnableClientState(GL_COLOR_ARRAY); + glDebug("glEnableClientState(GL_COLOR_ARRAY)"); + } else { glDisableClientState(GL_COLOR_ARRAY); + glDebug("glDisableClientState(GL_COLOR_ARRAY)"); // [enne] This should *not* be necessary, but the Linux OpenGL // driver that I'm using sets this to the last colour of the // colour array. So, we need to unset it here. glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glDebug("glColor4f(1.0f, 1.0f, 1.0f, 1.0f)"); } } if (state.texture != m_current_state.texture) { if (state.texture) + { glEnable(GL_TEXTURE_2D); + glDebug("glEnable(GL_TEXTURE_2D)"); + } else + { glDisable(GL_TEXTURE_2D); + glDebug("glDisable(GL_TEXTURE_2D)"); + } } if (state.blend != m_current_state.blend) { if (state.blend) + { glEnable(GL_BLEND); + glDebug("glEnable(GL_BLEND)"); + } else + { glDisable(GL_BLEND); + glDebug("glDisable(GL_BLEND)"); + } } if (state.depthtest != m_current_state.depthtest) { if (state.depthtest) + { glEnable(GL_DEPTH_TEST); + glDebug("glEnable(GL_DEPTH_TEST)"); + } else + { glDisable(GL_DEPTH_TEST); + glDebug("glEnable(GL_DEPTH_TEST)"); + } } if (state.alphatest != m_current_state.alphatest @@ -122,15 +172,20 @@ void OGLStateManager::set(const GLState& state) { glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_NOTEQUAL, state.alpharef); + glDebug("glAlphaFunc(GL_NOTEQUAL, state.alpharef)"); } else + { glDisable(GL_ALPHA_TEST); + glDebug("glDisable(GL_ALPHA_TEST)"); + } } if (state.colour != m_current_state.colour) { glColor4f(state.colour.r, state.colour.g, state.colour.b, state.colour.a); + glDebug("glColor4f"); } m_current_state = state; @@ -150,10 +205,15 @@ void OGLStateManager::reset_view_for_resize(const coord_def &m_windowsz) // For ease, vertex positions are pixel positions. #ifdef USE_GLES +# ifdef __ANDROID__ + glOrthof(0, m_windowsz.x, m_windowsz.y, 0, -1000, 1000); +# else glOrthox(0, m_windowsz.x, m_windowsz.y, 0, -1000, 1000); +# endif #else glOrtho(0, m_windowsz.x, m_windowsz.y, 0, -1000, 1000); #endif + glDebug("glOrthof"); } void OGLStateManager::reset_transform() @@ -166,21 +226,28 @@ void OGLStateManager::reset_transform() void OGLStateManager::pixelstore_unpack_alignment(unsigned int bpp) { glPixelStorei(GL_UNPACK_ALIGNMENT, bpp); + glDebug("glPixelStorei"); } void OGLStateManager::delete_textures(size_t count, unsigned int *textures) { glDeleteTextures(count, (GLuint*)textures); + glDebug("glDeleteTextures"); } void OGLStateManager::generate_textures(size_t count, unsigned int *textures) { glGenTextures(count, (GLuint*)textures); + glDebug("glGenTextures"); } void OGLStateManager::bind_texture(unsigned int texture) { glBindTexture(GL_TEXTURE_2D, texture); + glDebug("glBindTexture"); +#ifdef __ANDROID__ + m_last_tex = texture; +#endif } void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width, @@ -188,18 +255,26 @@ void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width, int xoffset, int yoffset) { // Assumptions... +#ifdef __ANDROID__ + const GLenum bpp = GL_RGBA; +#else const unsigned int bpp = 4; +#endif const GLenum texture_format = GL_RGBA; const GLenum format = GL_UNSIGNED_BYTE; // Also assume that the texture is already bound using bind_texture glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glDebug("glTexEnvf"); + #ifdef GL_CLAMP glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); #else glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glDebug("glTexParameterf GL_TEXTURE_WRAP_S"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glDebug("glTexParameterf GL_TEXTURE_WRAP_T"); #endif #ifndef USE_GLES if (mip_opt == MIPMAP_CREATE) @@ -216,11 +291,17 @@ void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width, glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (xoffset >= 0 && yoffset >= 0) + { glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, texture_format, format, pixels); + glDebug("glTexSubImage2D"); + } else + { glTexImage2D(GL_TEXTURE_2D, 0, bpp, width, height, 0, texture_format, format, pixels); + glDebug("glTexImage2D"); + } } } @@ -229,9 +310,115 @@ void OGLStateManager::reset_view_for_redraw(float x, float y) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glTranslatef(x, y , 1.0f); + glDebug("glTranslatef"); } +#ifdef __ANDROID__ +void OGLStateManager::fixup_gl_state() +{ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0.0, 0.0, 0.0, 1.0f); + glDepthFunc(GL_LEQUAL); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, m_last_tex); + glDebug("glBindTexture (REBIND)"); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glDebug("glTexEnvf (REBIND)"); + + if (m_current_state.array_vertex) + { + glEnableClientState(GL_VERTEX_ARRAY); + glDebug("glEnableClientState(GL_VERTEX_ARRAY)"); + } + else + { + glDisableClientState(GL_VERTEX_ARRAY); + glDebug("glDisableClientState(GL_VERTEX_ARRAY)"); + } + if (m_current_state.array_texcoord) + { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glDebug("glEnableClientState(GL_TEXTURE_COORD_ARRAY)"); + } + else + { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDebug("glDisableClientState(GL_TEXTURE_COORD_ARRAY)"); + } + if (m_current_state.array_colour) + { + glEnableClientState(GL_COLOR_ARRAY); + glDebug("glEnableClientState(GL_COLOR_ARRAY)"); + glColor4f(m_current_state.colour.r, m_current_state.colour.g, + m_current_state.colour.b, m_current_state.colour.a); + glDebug("glColor4f"); + } + else + { + glDisableClientState(GL_COLOR_ARRAY); + glDebug("glDisableClientState(GL_COLOR_ARRAY)"); + + // [enne] This should *not* be necessary, but the Linux OpenGL + // driver that I'm using sets this to the last colour of the + // colour array. So, we need to unset it here. + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glDebug("glColor4f(1.0f, 1.0f, 1.0f, 1.0f)"); + } + if (m_current_state.texture) + { + // glEnable(GL_TEXTURE_2D); + // glDebug("glEnable(GL_TEXTURE_2D)"); + } + else + { + glDisable(GL_TEXTURE_2D); + glDebug("glDisable(GL_TEXTURE_2D)"); + } + if (m_current_state.blend) + { + glEnable(GL_BLEND); + glDebug("glEnable(GL_BLEND)"); + } + else + { + glDisable(GL_BLEND); + glDebug("glDisable(GL_BLEND)"); + } + if (m_current_state.depthtest) + { + glEnable(GL_DEPTH_TEST); + glDebug("glEnable(GL_DEPTH_TEST)"); + } + else + { + glDisable(GL_DEPTH_TEST); + glDebug("glEnable(GL_DEPTH_TEST)"); + } + if (m_current_state.alphatest) + { + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_NOTEQUAL, m_current_state.alpharef); + glDebug("glAlphaFunc(GL_NOTEQUAL, state.alpharef)"); + } + else + { + glDisable(GL_ALPHA_TEST); + glDebug("glDisable(GL_ALPHA_TEST)"); + } +} +#endif + +void OGLStateManager::glDebug(const char* msg) +{ +#ifdef __ANDROID__ + int e = glGetError(); + if(e>0) + __android_log_print(ANDROID_LOG_INFO, "Crawl.gl", "ERROR %x: %s",e,msg); +#endif +} ///////////////////////////////////////////////////////////////////////////// // OGLShapeBuffer @@ -375,12 +562,15 @@ void OGLShapeBuffer::draw(const GLState &state) glmanager->set(state); glVertexPointer(3, GL_FLOAT, 0, &m_position_buffer[0]); + glDebug("glVertexPointer"); if (state.array_texcoord && m_texture_verts) glTexCoordPointer(2, GL_FLOAT, 0, &m_texture_buffer[0]); + glDebug("glTexCoordPointer"); if (state.array_colour && m_colour_verts) glColorPointer(4, GL_UNSIGNED_BYTE, 0, &m_colour_buffer[0]); + glDebug("glColorPointer"); switch (m_prim_type) { @@ -395,6 +585,8 @@ void OGLShapeBuffer::draw(const GLState &state) die("Invalid primitive type"); break; } + glDebug("glDrawElements"); + } void OGLShapeBuffer::clear() @@ -405,5 +597,20 @@ void OGLShapeBuffer::clear() m_colour_buffer.clear(); } +void OGLShapeBuffer::glDebug(const char* msg) +{ +#ifdef __ANDROID__ + int e = glGetError(); + if(e>0) + __android_log_print(ANDROID_LOG_INFO, "Crawl.gl", "ERROR %x: %s",e,msg); +#else +#ifdef DEBUG_DIAGNOSTICS + int e = glGetError(); + if(e>0) + printf("ERROR %x: %s\n",e,msg); +#endif +#endif +} + #endif // USE_GL #endif // USE_TILE_LOCAL |