From 8818a8e5db86f140230d789427373e1771747f5d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 5 Jan 2013 23:03:06 +0100 Subject: [PATCH] Corrected OpenGL extension detection - corrected multitexture and VBO detection - GLEW is now a required library - minor CMakeLists refactoring --- CMakeLists.txt | 46 ++----- src/CMakeLists.txt | 45 +++---- src/app/app.cpp | 1 - src/common/config.h.cmake | 1 - src/graphics/core/device.h | 5 +- src/graphics/opengl/gldevice.cpp | 204 +++++++++++++++++-------------- src/graphics/opengl/gldevice.h | 6 +- 7 files changed, 146 insertions(+), 162 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 399ae965..4fc91c10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,14 @@ set(COLOBOT_VERSION_UNRELEASED "~pre-alpha") # Append git characteristics to version if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git") - find_package(Git) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD - OUTPUT_VARIABLE GIT_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") + find_package(Git) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}") endif() set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}") @@ -67,6 +67,7 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) # Build openal sound support option(OPENAL_SOUND "Build openal sound support" OFF) + ## # Required packages ## @@ -85,17 +86,11 @@ set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_ADDITIONALVERSION "1.51" "1.51.0") find_package(Boost COMPONENTS system filesystem regex REQUIRED) -# GLEW requirement depends on platform -# By default it is auto detected -# This setting may be used to override -# Possible values: -# - auto -> determine automatically -# - 1 -> always enable -# - 0 -> always disable -set(USE_GLEW auto) # This is useful on Windows, if linking against standard GLEW dll fails option(GLEW_STATIC "Link statically with GLEW" OFF) +find_package(GLEW REQUIRED) + ## # Additional settings to use when cross-compiling with MXE (http://mxe.cc/) @@ -113,38 +108,19 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(PLATFORM_WINDOWS 1) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 0) - - # On Windows, GLEW is required - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 1) - endif() elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") message(STATUS "Linux system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 1) set(PLATFORM_OTHER 0) - - # On Linux, we should be fine without GLEW - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 0) - endif() else() message(STATUS "Other system detected") set(PLATFORM_WINDOWS 0) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 1) - - # Use GLEW to be safe - if (${USE_GLEW} MATCHES "auto") - set(USE_GLEW 1) - endif() endif() -if(${USE_GLEW}) - find_package(GLEW REQUIRED) -endif() - if(NOT ${ASSERTS}) add_definitions(-DNDEBUG) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abd4a950..c00d347a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,32 +19,24 @@ endif() # Optional libraries set(OPTIONAL_LIBS "") -set(OPTIONAL_INCLUDE_DIRS "") - -if(${USE_GLEW} AND NOT ${MXE}) - set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY}) - set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH}) -endif() - - -# Additional libraries per platform -set(PLATFORM_LIBS "") -set(OPENAL_LIBS "") if (${OPENAL_SOUND}) if (${MXE}) - set(OPENAL_LIBS - ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a - ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a - ) + set(OPTIONAL_LIBS + ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a + ) else() - set(OPENAL_LIBS - openal - alut - ) + set(OPTIONAL_LIBS + openal + alut + ) endif() endif() +# Additional libraries per platform +set(PLATFORM_LIBS "") + if (${MXE}) # MXE requires special treatment set(PLATFORM_LIBS ${MXE_LIBS}) elseif (${PLATFORM_WINDOWS}) @@ -63,9 +55,9 @@ set(OPENAL_SRC "") if (${OPENAL_SOUND}) set(OPENAL_SRC - sound/oalsound/alsound.cpp - sound/oalsound/buffer.cpp - sound/oalsound/channel.cpp + sound/oalsound/alsound.cpp + sound/oalsound/buffer.cpp + sound/oalsound/channel.cpp ) endif() @@ -192,16 +184,16 @@ ${OPENAL_SRC} set(LIBS +CBot ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARIES} +${GLEW_LIBRARY} +${Boost_LIBRARIES} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} -${Boost_LIBRARIES} -CBot -${OPENAL_LIBS} ) include_directories( @@ -212,8 +204,9 @@ ${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} -${OPTIONAL_INCLUDE_DIRS} +${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} +${OPTIONAL_INCLUDE_DIRS} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/app/app.cpp b/src/app/app.cpp index 4c66e24b..7323e2d0 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -264,7 +264,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message("\n"); GetLogger()->Message("List of available options:\n"); GetLogger()->Message(" -help this help\n"); - GetLogger()->Message(" -vbo enable OpenGL VBOs\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 022bb692..1595e09a 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -5,7 +5,6 @@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ -#cmakedefine USE_GLEW @USE_GLEW@ #cmakedefine GLEW_STATIC #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 618d21ab..41d7796a 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -104,8 +104,7 @@ enum RenderState RENDER_STATE_DEPTH_TEST, RENDER_STATE_DEPTH_WRITE, RENDER_STATE_ALPHA_TEST, - RENDER_STATE_CULLING, - RENDER_STATE_DITHERING + RENDER_STATE_CULLING }; /** @@ -287,7 +286,7 @@ public: virtual void DestroyAllTextures() = 0; //! Returns the maximum number of multitexture stages - virtual int GetMaxTextureCount() = 0; + virtual int GetMaxTextureStageCount() = 0; //! Sets the texture at given texture stage virtual void SetTexture(int index, const Texture &texture) = 0; //! Sets the texture image by ID at given texture stage diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 9460e076..c535609d 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -24,22 +24,9 @@ #include "math/geometry.h" -#if defined(USE_GLEW) - -// When using GLEW, only glew.h is needed +// Using GLEW so only glew.h is needed #include -#else - -// Should define prototypes of used extensions as OpenGL functions -#define GL_GLEXT_PROTOTYPES - -#include -#include -#include - -#endif // if defined(GLEW) - #include #include @@ -74,7 +61,8 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config) m_config = config; m_lighting = false; m_lastVboId = 0; - m_useVbo = false; + m_multitextureAvailable = false; + m_vboAvailable = false; } @@ -93,7 +81,6 @@ bool CGLDevice::Create() { GetLogger()->Info("Creating CDevice\n"); -#if defined(USE_GLEW) static bool glewInited = false; if (!glewInited) @@ -106,26 +93,16 @@ bool CGLDevice::Create() return false; } - if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) ) - { - GetLogger()->Error("GLEW reports required extensions not supported\n"); - return false; - } + m_multitextureAvailable = glewIsSupported("GL_ARB_multitexture GL_ARB_texture_env_combine"); + if (!m_multitextureAvailable) + GetLogger()->Error("GLEW reports multitexturing not supported - graphics quality will be degraded!\n"); - if (GLEW_ARB_vertex_buffer_object) - { + m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); + if (m_vboAvailable) GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); - m_useVbo = true; - } else - { GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); - } } -#endif - - /* NOTE: when not using GLEW, extension testing is not performed, as it is assumed that - glext.h is up-to-date and the OpenGL shared library has the required functions present. */ // This is mostly done in all modern hardware by default // DirectX doesn't even allow the option to turn off perspective correction anymore @@ -135,6 +112,9 @@ bool CGLDevice::Create() // To avoid problems with scaling & lighting glEnable(GL_RESCALE_NORMAL); + // Minimal depth bias to avoid Z-fighting + SetDepthBias(0.001f); + // Set just to be sure glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); @@ -186,14 +166,14 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) Create(); } -void CGLDevice::SetUseVbo(bool useVbo) +void CGLDevice::SetUseVbo(bool vboAvailable) { - m_useVbo = useVbo; + m_vboAvailable = vboAvailable; } bool CGLDevice::GetUseVbo() { - return m_useVbo; + return m_vboAvailable; } void CGLDevice::BeginScene() @@ -610,7 +590,7 @@ void CGLDevice::DestroyAllTextures() m_allTextures.clear(); } -int CGLDevice::GetMaxTextureCount() +int CGLDevice::GetMaxTextureStageCount() { return m_currentTextures.size(); } @@ -621,17 +601,21 @@ int CGLDevice::GetMaxTextureCount() The setting is remembered, even if texturing is disabled at the moment. */ void CGLDevice::SetTexture(int index, const Texture &texture) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); bool same = m_currentTextures[index].id == texture.id; m_currentTextures[index] = texture; // remember the new value + if (!m_multitextureAvailable && index != 0) + return; + if (same) return; // nothing to do - glActiveTexture(GL_TEXTURE0 + index); + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(GL_TEXTURE_2D, texture.id); // Params need to be updated for the new bound texture @@ -640,15 +624,19 @@ void CGLDevice::SetTexture(int index, const Texture &texture) void CGLDevice::SetTexture(int index, unsigned int textureId) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); if (m_currentTextures[index].id == textureId) return; // nothing to do m_currentTextures[index].id = textureId; - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(GL_TEXTURE_2D, textureId); // Params need to be updated for the new bound texture @@ -659,16 +647,14 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ Texture CGLDevice::GetTexture(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_currentTextures[index]; } void CGLDevice::SetTextureEnabled(int index, bool enabled) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); bool same = m_texturesEnabled[index] == enabled; @@ -677,7 +663,12 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) if (same) return; // nothing to do - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + if (enabled) glEnable(GL_TEXTURE_2D); else @@ -686,8 +677,7 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) bool CGLDevice::GetTextureEnabled(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_texturesEnabled[index]; } @@ -698,17 +688,36 @@ bool CGLDevice::GetTextureEnabled(int index) The settings are remembered, even if texturing is disabled at the moment. */ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶ms) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); // Remember the settings m_textureStageParams[index] = params; + if (!m_multitextureAvailable && index != 0) + return; + // Don't actually do anything if texture not set if (! m_currentTextures[index].Valid()) return; - glActiveTexture(GL_TEXTURE0 + index); + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); + + if (params.wrapS == TEX_WRAP_CLAMP) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + else if (params.wrapS == TEX_WRAP_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + else assert(false); + + if (params.wrapT == TEX_WRAP_CLAMP) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + else if (params.wrapT == TEX_WRAP_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + else assert(false); + + // Texture env setting is silly without multitexturing + if (!m_multitextureAvailable) + return; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, params.factor.Array()); @@ -812,26 +821,12 @@ after_tex_color: glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); else assert(false); - -after_tex_operations: - - if (params.wrapS == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - else if (params.wrapS == TEX_WRAP_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - else assert(false); - - if (params.wrapT == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - else if (params.wrapT == TEX_WRAP_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - else assert(false); +after_tex_operations: ; } void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); // Remember the settings m_textureStageParams[index].wrapS = wrapS; @@ -841,7 +836,11 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr if (! m_currentTextures[index].Valid()) return; - glActiveTexture(GL_TEXTURE0 + index); + if (!m_multitextureAvailable && index != 0) + return; + + if (m_multitextureAvailable) + glActiveTexture(GL_TEXTURE0 + index); if (wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -858,8 +857,7 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr TextureStageParams CGLDevice::GetTextureStageParams(int index) { - assert(index >= 0); - assert(index < static_cast( m_currentTextures.size() )); + assert(index >= 0 && index < static_cast( m_currentTextures.size() )); return m_textureStageParams[index]; } @@ -890,7 +888,9 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), reinterpret_cast(&vs[0].normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), reinterpret_cast(&vs[0].texCoord)); @@ -914,13 +914,18 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord)); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord2)); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast(&vs[0].texCoord2)); + } glColor4fv(color.Array()); @@ -929,8 +934,11 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1 - glClientActiveTexture(GL_TEXTURE0); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } } void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) @@ -952,7 +960,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -986,7 +994,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -1020,7 +1028,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { unsigned int id = 0; - if (m_useVbo) + if (m_vboAvailable) { id = ++m_lastVboId; @@ -1053,7 +1061,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1080,7 +1088,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1107,7 +1115,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1134,7 +1142,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv void CGLDevice::DrawStaticBuffer(unsigned int bufferId) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1151,7 +1159,9 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), static_cast(nullptr) + offsetof(Vertex, texCoord)); } @@ -1163,13 +1173,18 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, normal)); - glClientActiveTexture(GL_TEXTURE0); + if (m_multitextureAvailable) + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord)); - glClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord2)); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast(nullptr) + offsetof(VertexTex2, texCoord2)); + } } else if ((*it).second.vertexType == VERTEX_TYPE_COL) { @@ -1194,8 +1209,11 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1 - glClientActiveTexture(GL_TEXTURE0); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if (m_multitextureAvailable) + { + glClientActiveTexture(GL_TEXTURE0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } } else if ((*it).second.vertexType == VERTEX_TYPE_COL) { @@ -1214,7 +1232,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) { - if (m_useVbo) + if (m_vboAvailable) { auto it = m_vboObjects.find(bufferId); if (it == m_vboObjects.end()) @@ -1355,7 +1373,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -1380,7 +1397,6 @@ bool CGLDevice::GetRenderState(RenderState state) case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index dd43f2c2..71376713 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -111,7 +111,7 @@ public: virtual void DestroyTexture(const Texture &texture); virtual void DestroyAllTextures(); - virtual int GetMaxTextureCount(); + virtual int GetMaxTextureStageCount(); virtual void SetTexture(int index, const Texture &texture); virtual void SetTexture(int index, unsigned int textureId); virtual Texture GetTexture(int index); @@ -229,8 +229,10 @@ private: int vertexCount; }; + //! Whether to use multitexturing + bool m_multitextureAvailable; //! Whether to use VBOs or display lists - bool m_useVbo; + bool m_vboAvailable; //! Map of saved VBO objects std::map m_vboObjects; //! Last ID of VBO object