SET(HAVE_SDL TRUE)
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
+OPTION(GLBINDING_ENABLED "Use glbinding instead of GLEW" OFF)
+OPTION(GLBINDING_DEBUG_OUTPUT "Enable glbinding debug output for each called OpenGL function" ON)
IF(ENABLE_OPENGL)
FIND_PACKAGE(OpenGL)
IF(OPENGL_FOUND)
SET(HAVE_OPENGL TRUE)
ENDIF(OPENGL_FOUND)
- FIND_PACKAGE(GLEW)
- IF(GLEW_FOUND)
- INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
- ENDIF(GLEW_FOUND)
+ IF(GLBINDING_ENABLED)
+ FIND_PACKAGE(GLBINDING REQUIRED)
+ IF(GLBINDING_FOUND)
+ INCLUDE_DIRECTORIES(${GLBINDING_INCLUDES})
+ ADD_DEFINITIONS(-DUSE_GLBINDING)
+ IF (GLBINDING_DEBUG_OUTPUT)
+ ADD_DEFINITIONS(-DUSE_GLBINDING_DEBUG_OUTPUT)
+ ENDIF()
+ ENDIF()
+ ELSE()
+ FIND_PACKAGE(GLEW REQUIRED)
+ IF(GLEW_FOUND)
+ INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
+ ENDIF(GLEW_FOUND)
+ ENDIF()
ENDIF(ENABLE_OPENGL)
FIND_PACKAGE(OpenAL REQUIRED)
IF(MSVC)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc)
-ADD_DEFINITIONS(-D_USE_MATH_DEFINES -DNOMINMAX)
+ ADD_DEFINITIONS(-D_USE_MATH_DEFINES -DNOMINMAX)
ENDIF(MSVC)
## Build list of sources for supertux binary
TARGET_LINK_LIBRARIES(supertux2 ${PHYSFS_LIBRARY})
IF(HAVE_OPENGL)
TARGET_LINK_LIBRARIES(supertux2 ${OPENGL_LIBRARY})
- TARGET_LINK_LIBRARIES(supertux2 ${GLEW_LIBRARY})
+ IF(GLBINDING_FOUND)
+ TARGET_LINK_LIBRARIES(supertux2 ${GLBINDING_LIBRARIES})
+ ELSE()
+ TARGET_LINK_LIBRARIES(supertux2 ${GLEW_LIBRARY})
+ ENDIF()
ENDIF(HAVE_OPENGL)
IF(HAVE_LIBCURL)
TARGET_LINK_LIBRARIES(supertux2 ${CURL_LIBRARY})
#ifndef HEADER_SUPERTUX_VIDEO_GL_GL_PAINTER_HPP
#define HEADER_SUPERTUX_VIDEO_GL_GL_PAINTER_HPP
+#ifdef USE_GLBINDING
+#include <glbinding/gl/gl.h>
+using namespace gl;
+#else
#include <GL/glew.h>
+
#include "SDL_opengl.h"
+#endif
class DrawingRequest;
#include "video/gl/gl_texture.hpp"
#include "video/util.hpp"
+#ifdef USE_GLBINDING
+# include <glbinding/ContextInfo.h>
+# include <glbinding/gl/extension.h>
+# include <glbinding/callbacks.h>
+#endif
+
#define LIGHTMAP_DIV 5
#ifdef GL_VERSION_ES_CM_1_0
apply_video_mode();
+#ifdef USE_GLBINDING
+
+ glbinding::Binding::initialize();
+
+#ifdef USE_GLBINDING_DEBUG_OUTPUT
+ glbinding::setCallbackMask(glbinding::CallbackMask::After | glbinding::CallbackMask::ParametersAndReturnValue);
+
+ glbinding::setAfterCallback([](const glbinding::FunctionCall & call) {
+ std::cout << call.function.name() << "(";
+
+ for (unsigned i = 0; i < call.parameters.size(); ++i)
+ {
+ std::cout << call.parameters[i]->asString();
+ if (i < call.parameters.size() - 1)
+ std::cout << ", ";
+ }
+
+ std::cout << ")";
+
+ if (call.returnValue)
+ {
+ std::cout << " -> " << call.returnValue->asString();
+ }
+
+ std::cout << std::endl;
+ });
+#endif
+
+ static auto extensions = glbinding::ContextInfo::extensions();
+ log_info << "Using glbinding 1.0.0 " << std::endl;
+ log_info << "ARB_texture_non_power_of_two: " << static_cast<int>(extensions.find(GLextension::GL_ARB_texture_non_power_of_two) != extensions.end()) << std::endl;
+
+#endif
+
// setup opengl state and transform
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
apply_config();
#ifndef GL_VERSION_ES_CM_1_0
+ #ifndef USE_GLBINDING
GLenum err = glewInit();
if (GLEW_OK != err)
{
}
log_info << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
log_info << "GLEW_ARB_texture_non_power_of_two: " << static_cast<int>(GLEW_ARB_texture_non_power_of_two) << std::endl;
+# endif
#endif
}
#include "supertux/gameconfig.hpp"
#include "video/gl/gl_texture.hpp"
+#ifdef USE_GLBINDING
+ #include <glbinding/ContextInfo.h>
+#endif
+
namespace {
inline bool is_power_of_2(int v)
try {
glBindTexture(GL_TEXTURE_2D, m_handle);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- m_texture_width, m_texture_height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(GL_RGBA), m_texture_width,
+ m_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
set_texture_params();
} catch(...) {
m_texture_width = next_power_of_two(image->w);
m_texture_height = next_power_of_two(image->h);
#else
+# ifdef USE_GLBINDING
+ static auto extensions = glbinding::ContextInfo::extensions();
+ if (extensions.find(GLextension::GL_ARB_texture_non_power_of_two) != extensions.end())
+ {
+ m_texture_width = image->w;
+ m_texture_height = image->h;
+ }
+# else
if (GLEW_ARB_texture_non_power_of_two)
{
m_texture_width = image->w;
m_texture_height = image->h;
}
+# endif
else
{
m_texture_width = next_power_of_two(image->w);
glBindTexture(GL_TEXTURE_2D, m_handle);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-#ifdef GL_UNPACK_ROW_LENGTH
+#if defined(GL_UNPACK_ROW_LENGTH) || defined(USE_GLBINDING)
glPixelStorei(GL_UNPACK_ROW_LENGTH, convert->pitch/convert->format->BytesPerPixel);
#else
/* OpenGL ES doesn't support UNPACK_ROW_LENGTH, let's hope SDL didn't add
* padding bytes, otherwise we need some extra code here... */
- assert(convert->pitch == texture_width * convert->format->BytesPerPixel);
+ assert(convert->pitch == m_texture_width * convert->format->BytesPerPixel);
#endif
if(SDL_MUSTLOCK(convert))
SDL_LockSurface(convert);
}
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(GL_RGBA),
m_texture_width, m_texture_height, 0, sdl_format,
GL_UNSIGNED_BYTE, convert->pixels);
void
GLTexture::set_texture_params()
{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR));
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR));
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, static_cast<GLint>(GL_CLAMP_TO_EDGE));
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, static_cast<GLint>(GL_CLAMP_TO_EDGE));
assert_gl("set texture params");
}
#include <sstream>
#include <stdexcept>
+
+#ifdef USE_GLBINDING
+
+#include <glbinding/gl/gl.h>
+using namespace gl;
+
+#else
+
#ifndef GL_VERSION_ES_CM_1_0
# include <GL/glew.h>
#endif
# include <GL/glext.h>
#endif
+#endif
+
static inline void check_gl_error(const char* message)
{
GLenum error = glGetError();
void
TextureManager::save_textures()
{
-#ifdef GL_PACK_ROW_LENGTH
+#if defined(GL_PACK_ROW_LENGTH) || defined(USE_GLBINDING)
/* all this stuff is not support by OpenGL ES */
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
void
TextureManager::reload_textures()
{
-#ifdef GL_UNPACK_ROW_LENGTH
+#if defined(GL_UNPACK_ROW_LENGTH) || defined(USE_GLBINDING)
/* OpenGL ES doesn't support these */
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
assert_gl("creating texture handle");
glBindTexture(GL_TEXTURE_2D, handle);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(GL_RGBA),
saved_texture.width, saved_texture.height,
saved_texture.border, GL_RGBA,
GL_UNSIGNED_BYTE, saved_texture.pixels);