diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics/core/device.h | 1 | ||||
-rw-r--r-- | src/graphics/core/vertex.h | 3 | ||||
-rw-r--r-- | src/graphics/engine/engine.cpp | 24 | ||||
-rw-r--r-- | src/graphics/engine/text.cpp | 4 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.cpp | 67 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.h | 2 |
6 files changed, 21 insertions, 80 deletions
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 71ebef7..0d76644 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -99,7 +99,6 @@ enum TransformType enum RenderState { RENDER_STATE_LIGHTING, - RENDER_STATE_TEXTURING, RENDER_STATE_BLENDING, RENDER_STATE_FOG, RENDER_STATE_DEPTH_TEST, diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index fa6120f..2ee6be4 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -91,8 +91,7 @@ struct VertexCol Color color; explicit VertexCol(Math::Vector aCoord = Math::Vector(), - Color aColor = Color(), - Math::Point aTexCoord = Math::Point()) + Color aColor = Color()) : coord(aCoord), pad(0.0f), color(aColor) {} //! Returns a string "(c: [...], col: [...])" diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e34034d..c094c63 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -1851,8 +1851,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - m_device->SetTextureFactor(color); TextureStageParams params; @@ -1873,8 +1871,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - m_device->SetTextureFactor(color.Inverse()); TextureStageParams params; @@ -1891,20 +1887,22 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_FOG, false); m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(RENDER_STATE_TEXTURING, false); m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR); + + m_device->SetTextureEnabled(0, false); } else if (state & ENG_RSTATE_TCOLOR_WHITE) // transparent white color? { m_device->SetRenderState(RENDER_STATE_FOG, false); m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(RENDER_STATE_TEXTURING, false); m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO); + + m_device->SetTextureEnabled(0, false); } else if (state & ENG_RSTATE_TDIFFUSE) // diffuse color as transparent? { @@ -1915,8 +1913,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_DST_ALPHA); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - TextureStageParams params; params.colorOperation = TEX_MIX_OPER_REPLACE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; @@ -1932,7 +1928,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); m_device->SetRenderState(RENDER_STATE_BLENDING, false); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, TextureStageParams()); // default operation } @@ -1942,7 +1937,8 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); m_device->SetRenderState(RENDER_STATE_BLENDING, false); - m_device->SetRenderState(RENDER_STATE_TEXTURING, false); + + m_device->SetTextureEnabled(0, false); } else if (state & ENG_RSTATE_TEXT) // font rendering? { @@ -1953,7 +1949,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, TextureStageParams()); // default operation } @@ -1968,8 +1963,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.5f); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - m_device->SetTextureFactor(color); TextureStageParams params; @@ -1990,8 +1983,6 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true); m_device->SetRenderState(RENDER_STATE_FOG, true); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - TextureStageParams params; params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? @@ -2063,9 +2054,7 @@ void CEngine::SetState(int state, const Color& color) // In interface mode, disable lighting if (m_interfaceMode) - { m_device->SetRenderState(RENDER_STATE_LIGHTING, false); - } } void CEngine::SetMaterial(const Material& mat) @@ -3584,7 +3573,6 @@ void CEngine::DrawOverColor() m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); m_device->SetRenderState(RENDER_STATE_LIGHTING, false); m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetRenderState(RENDER_STATE_TEXTURING, false); m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 4deeb53..9091905 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -647,7 +647,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) p2.y = pos.y + size.y; } - m_device->SetRenderState(RENDER_STATE_TEXTURING, false); + m_device->SetTextureEnabled(0, false); VertexCol quad[] = { @@ -660,7 +660,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); m_engine->AddStatisticTriangle(2); - m_device->SetRenderState(RENDER_STATE_TEXTURING, true); + m_device->SetTextureEnabled(0, true); } void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 58b7ece..56a7130 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -69,7 +69,6 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config) { m_config = config; m_lighting = false; - m_texturing = false; } @@ -167,7 +166,6 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) // Reset state m_lighting = false; - m_texturing = false; Destroy(); Create(); } @@ -552,7 +550,7 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par // Restore the previous state of 1st stage glBindTexture(GL_TEXTURE_2D, m_currentTextures[0].id); - if ( (! m_texturing) || (! m_texturesEnabled[0]) ) + if (! m_texturesEnabled[0]) glDisable(GL_TEXTURE_2D); return result; @@ -560,10 +558,6 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par void CGLDevice::DestroyTexture(const Texture &texture) { - auto it = m_allTextures.find(texture); - if (it != m_allTextures.end()) - m_allTextures.erase(it); - // Unbind the texture if in use anywhere for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) { @@ -572,16 +566,22 @@ void CGLDevice::DestroyTexture(const Texture &texture) } glDeleteTextures(1, &texture.id); + + auto it = m_allTextures.find(texture); + if (it != m_allTextures.end()) + m_allTextures.erase(it); } void CGLDevice::DestroyAllTextures() { - for (auto it = m_allTextures.begin(); it != m_allTextures.end(); ++it) - glDeleteTextures(1, &(*it).id); - // Unbind all texture stages for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) SetTexture(index, Texture()); + + for (auto it = m_allTextures.begin(); it != m_allTextures.end(); ++it) + glDeleteTextures(1, &(*it).id); + + m_allTextures.clear(); } int CGLDevice::GetMaxTextureCount() @@ -605,7 +605,6 @@ void CGLDevice::SetTexture(int index, const Texture &texture) if (same) return; // nothing to do - glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0 + index); glBindTexture(GL_TEXTURE_2D, texture.id); @@ -623,7 +622,6 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) m_currentTextures[index].id = textureId; - glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0 + index); glBindTexture(GL_TEXTURE_2D, textureId); @@ -684,8 +682,6 @@ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶m if (! m_currentTextures[index].Valid()) return; - // Enable the given stage - glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0 + index); // To save some trouble @@ -802,10 +798,6 @@ after_tex_operations: else if (params.wrapT == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else assert(false); - - // Disable the stage if it is set so - if ( (! m_texturing) || (! m_texturesEnabled[0]) ) - glDisable(GL_TEXTURE_2D); } void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) @@ -821,8 +813,6 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr if (! m_currentTextures[index].Valid()) return; - // Enable the given stage - glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0 + index); if (wrapS == TEX_WRAP_CLAMP) @@ -836,10 +826,6 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr else if (wrapT == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else assert(false); - - // Disable the stage if it is set so - if ( (! m_texturing) || (! m_texturesEnabled[0]) ) - glDisable(GL_TEXTURE_2D); } TextureStageParams CGLDevice::GetTextureStageParams(int index) @@ -855,15 +841,8 @@ void CGLDevice::SetTextureFactor(const Color &color) // Needs to be set for all texture stages for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) { - // Activate stage glActiveTexture(GL_TEXTURE0 + index); - glEnable(GL_TEXTURE_2D); - glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color.Array()); - - // Disable the stage if it is set so - if ( (! m_texturing) || (! m_texturesEnabled[index]) ) - glDisable(GL_TEXTURE_2D); } } @@ -871,15 +850,10 @@ Color CGLDevice::GetTextureFactor() { // Get from 1st stage (should be the same for all stages) glActiveTexture(GL_TEXTURE0); - glEnable(GL_TEXTURE_2D); GLfloat color[4] = { 0.0f }; glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); - // Disable the 1st stage if it is set so - if ( (! m_texturing) || (! m_texturesEnabled[0]) ) - glDisable(GL_TEXTURE_2D); - return Color(color[0], color[1], color[2], color[3]); } @@ -955,6 +929,8 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord2)); + glColor3f(1.0f, 1.0f, 1.0f); + glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount); glDisableClientState(GL_VERTEX_ARRAY); @@ -1069,22 +1045,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) return; } - else if (state == RENDER_STATE_TEXTURING) - { - m_texturing = enabled; - - // Enable/disable stages with new setting - for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) - { - glActiveTexture(GL_TEXTURE0 + index); - if (m_texturing && m_texturesEnabled[index]) - glEnable(GL_TEXTURE_2D); - else - glDisable(GL_TEXTURE_2D); - } - - return; - } GLenum flag = 0; @@ -1110,9 +1070,6 @@ bool CGLDevice::GetRenderState(RenderState state) if (state == RENDER_STATE_LIGHTING) return m_lighting; - if (state == RENDER_STATE_TEXTURING) - return m_texturing; - GLenum flag = 0; switch (state) diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 282f141..78c7433 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -190,8 +190,6 @@ private: //! Current lights enable status std::vector<bool> m_lightsEnabled; - //! Whether texturing is enabled in general - bool m_texturing; //! Current textures; \c NULL value means unassigned std::vector<Texture> m_currentTextures; //! Current texture stages enable status |