[AD] CMake issues and OpenGL performance/compatibility issues

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

Tomasu made me post this stuff here - hope it's OK :P

First some CMake issues: CMAKE_FIND_ROOT_PATH is totally the wrong variable to use for the 'deps' folder, since it gets prepended to ALL other paths - it is more a cross-compiling 'chroot'-style thing. Instead, we should be using CMAKE_PREFIX_PATH. I propose the following patch:

---8<---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5046d7b..63a8918 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,8 +53,8 @@ file(GLOB deps_subdirs
     )
 foreach(subdir ${deps_subdirs})
     if(EXISTS "${subdir}/include" OR EXISTS "${subdir}/lib")
-        message(STATUS "Adding ${subdir} to CMAKE_FIND_ROOT_PATH")
-        list(APPEND CMAKE_FIND_ROOT_PATH "${subdir}")
+        message(STATUS "Adding ${subdir} to CMAKE_PREFIX_PATH")
+        list(APPEND CMAKE_PREFIX_PATH "${subdir}")
     endif()
 endforeach(subdir)

@@ -239,7 +239,7 @@ if(MINGW)
     endif("$ENV{MINGDIR}" STREQUAL "")

     # Search in MINGDIR for headers and libraries.
-    set(CMAKE_PREFIX_PATH "${MINGDIR}")
+    list(APPEND CMAKE_PREFIX_PATH "${MINGDIR}")

     # Install to MINGDIR
     if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

---8<---

Next, OpenGL issues. I'm working with a stone-age laptop that only does GL 2.0, and have encountered some performance and compatibility issues with Allegro 5 (GIT).

The first was a crash bug for me. When using PROGRAMMABLE_PIPELINE, there's code in ogl_flush_vertex_cache() in src/opengl/ogl_draw.c that creates a vertex array object and a vertex buffer object. The VBO works fine, but the VAO functions (starting with glGenVertexArrays) are null and so it crashes trying to call them. In GL 2.0, VAOs are only a convenience so that instead of constantly calling glVertexPointer/glColorPointer/etc. to switch between different VBOs, you can just put those pointers in VAOs on startup and then use a single function to switch from one VAO to another. But Allegro only uses one VAO, and calls all those functions every time anyway, so we aren't actually gaining anything from the way we use them. Commenting out the VAO-related lines fixes it for me. The only question is whether more recent GL versions (say 3.0 or 4.0) have deprecated the concept of assigning those pointers 'globally' instead of per-VAO (I haven't checked).

On to the performance issues - this laptop did something weird where my game performed fine (30-40 fps) some of the time, but then dropped to 5 fps for periods - it kept oscillating. So I used 'gDEBugger GL' to investigate, and it flagged some calls to glGet*() functions and told me that they have to wait for the GL to finish all current operations before they can return. Two that were affecting me are in ogl_flush_vertex_cache() again: there's a call to glGetIntegerv() to work out if binding a texture is necessary, so I tweaked it locally to risk doing a redundant bind instead; and there's a call to glGetError() that should be wrapped in #ifdef DEBUGMODE. Finally, glsl_use_shader() in ogl_shader.c calls glGetError() twice; for now I've avoided this by retrieving the Allegro shader source and managing it myself (but it would be nice for al_use_shader() not to have this problem). Once I did all these things, my game's performance was generally better, and it still oscillated a bit but it stayed at 15 fps or higher. It also flagged a redundant call to glFlush() in wgl_flip_display() in src/win/wgl_disp.c because SwapBuffers() implies it, but I'm not sure if commenting that out made much of a difference. (Obviously commenting it out is not the correct fix since the 'if' might not run and we still need the glFlush() in that case.)

Note: the only Allegro rendering my game is doing is some text. The rest is all direct GL calls. So I haven't tested much of Allegro this way.

One more thing I noticed: when you create a display with PROGRAMMABLE_PIPELINE, it compiles and links the default shader, but doesn't 'use' it. So the Allegro rendering functions don't work until you first call al_use_shader(null). We probably want to 'use' that shader initially.

Ben :)




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/