diff options
Diffstat (limited to 'src/graphics/opengl')
-rw-r--r-- | src/graphics/opengl/README.txt | 13 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.cpp | 65 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.h | 12 |
3 files changed, 58 insertions, 32 deletions
diff --git a/src/graphics/opengl/README.txt b/src/graphics/opengl/README.txt index 0aba0ed..596871d 100644 --- a/src/graphics/opengl/README.txt +++ b/src/graphics/opengl/README.txt @@ -1,6 +1,7 @@ -src/graphics/opengl - -OpenGL engine implementation - -Contains the concrete implementation using OpenGL of abstract CDevice class -from src/graphics/core +/** + * \dir graphics/opengl + * \brief OpenGL engine implementation + * + * Contains the concrete implementation using OpenGL of abstract CDevice class + * from src/graphics/core + */
\ No newline at end of file diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 3a255f4..3526b13 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -64,7 +64,6 @@ void Gfx::GLDeviceConfig::LoadDefault() Gfx::CGLDevice::CGLDevice(const Gfx::GLDeviceConfig &config) { m_config = config; - m_wasInit = false; m_lighting = false; m_texturing = false; } @@ -74,9 +73,11 @@ Gfx::CGLDevice::~CGLDevice() { } -bool Gfx::CGLDevice::GetWasInit() +void Gfx::CGLDevice::DebugHook() { - return m_wasInit; + /* This function is only called here, so it can be used + * as a breakpoint when debugging using gDEBugger */ + glColor3i(0, 0, 0); } std::string Gfx::CGLDevice::GetError() @@ -110,8 +111,6 @@ bool Gfx::CGLDevice::Create() /* 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. */ - m_wasInit = true; - // This is mostly done in all modern hardware by default // DirectX doesn't even allow the option to turn off perspective correction anymore // So turn it on permanently @@ -130,7 +129,7 @@ bool Gfx::CGLDevice::Create() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glViewport(0, 0, m_config.size.w, m_config.size.h); + glViewport(0, 0, m_config.size.x, m_config.size.y); m_lights = std::vector<Gfx::Light>(GL_MAX_LIGHTS, Gfx::Light()); @@ -158,8 +157,6 @@ void Gfx::CGLDevice::Destroy() m_currentTextures.clear(); m_texturesEnabled.clear(); m_textureStageParams.clear(); - - m_wasInit = false; } void Gfx::CGLDevice::ConfigChanged(const Gfx::GLDeviceConfig& newConfig) @@ -385,18 +382,22 @@ bool Gfx::CGLDevice::GetLightEnabled(int index) This struct must not be deleted in other way than through DeleteTexture() */ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms) { - Gfx::Texture result; - ImageData *data = image->GetData(); if (data == NULL) { m_error = "Invalid texture data"; - return result; // invalid texture + return Gfx::Texture(); // invalid texture } - result.valid = true; - result.size.w = data->surface->w; - result.size.h = data->surface->h; + return CreateTexture(data, params); +} + +Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms) +{ + Gfx::Texture result; + + result.size.x = data->surface->w; + result.size.y = data->surface->h; // Use & enable 1st texture stage glActiveTexture(GL_TEXTURE0); @@ -461,7 +462,7 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCrea // Restore the previous state of 1st stage - if (m_currentTextures[0].valid) + if (m_currentTextures[0].Valid()) glBindTexture(GL_TEXTURE_2D, m_currentTextures[0].id); else glBindTexture(GL_TEXTURE_2D, 0); @@ -516,7 +517,7 @@ void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) m_currentTextures[index] = texture; // remember the change - if (! texture.valid) + if (! texture.Valid()) { glBindTexture(GL_TEXTURE_2D, 0); // unbind texture } @@ -531,6 +532,24 @@ void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) glDisable(GL_TEXTURE_2D); } +void Gfx::CGLDevice::SetTexture(int index, unsigned int textureId) +{ + assert(index >= 0); + assert(index < static_cast<int>( m_currentTextures.size() )); + + // Enable the given texture stage + glActiveTexture(GL_TEXTURE0 + index); + glEnable(GL_TEXTURE_2D); + + m_currentTextures[index].id = textureId; + + glBindTexture(GL_TEXTURE_2D, textureId); + + // Disable the stage if it is set so + if ( (! m_texturing) || (! m_texturesEnabled[index]) ) + glDisable(GL_TEXTURE_2D); +} + /** Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ Gfx::Texture Gfx::CGLDevice::GetTexture(int index) @@ -576,7 +595,7 @@ void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStagePar m_textureStageParams[index] = params; // Don't actually do anything if texture not set - if (! m_currentTextures[index].valid) + if (! m_currentTextures[index].Valid()) return; // Enable the given stage @@ -1159,17 +1178,19 @@ void Gfx::CGLDevice::GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float & void Gfx::CGLDevice::SetCullMode(Gfx::CullMode mode) { - if (mode == Gfx::CULL_CW) glCullFace(GL_CW); - else if (mode == Gfx::CULL_CCW) glCullFace(GL_CCW); + // Cull clockwise back faces, so front face is the opposite + // (assuming GL_CULL_FACE is GL_BACK) + if (mode == Gfx::CULL_CW ) glFrontFace(GL_CCW); + else if (mode == Gfx::CULL_CCW) glFrontFace(GL_CW); else assert(false); } Gfx::CullMode Gfx::CGLDevice::GetCullMode() { GLint flag = 0; - glGetIntegerv(GL_CULL_FACE, &flag); - if (flag == GL_CW) return Gfx::CULL_CW; - else if (flag == GL_CCW) return Gfx::CULL_CCW; + glGetIntegerv(GL_FRONT_FACE, &flag); + if (flag == GL_CW) return Gfx::CULL_CCW; + else if (flag == GL_CCW) return Gfx::CULL_CW; else assert(false); return Gfx::CULL_CW; } diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 1864000..3daea8a 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -14,7 +14,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// gldevice.h +/** + * \file graphics/opengl/gldevice.h + * \brief OpenGL implementation - Gfx::CGLDevice class + */ #pragma once @@ -73,7 +76,8 @@ public: CGLDevice(const Gfx::GLDeviceConfig &config); virtual ~CGLDevice(); - virtual bool GetWasInit(); + virtual void DebugHook(); + virtual std::string GetError(); virtual bool Create(); @@ -100,11 +104,13 @@ public: virtual bool GetLightEnabled(int index); virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms); + virtual Gfx::Texture CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms); virtual void DestroyTexture(const Gfx::Texture &texture); virtual void DestroyAllTextures(); virtual int GetMaxTextureCount(); virtual void SetTexture(int index, const Gfx::Texture &texture); + virtual void SetTexture(int index, unsigned int textureId); virtual Gfx::Texture GetTexture(int index); virtual void SetTextureEnabled(int index, bool enabled); virtual bool GetTextureEnabled(int index); @@ -163,8 +169,6 @@ private: private: //! Current config Gfx::GLDeviceConfig m_config; - //! Was initialized? - bool m_wasInit; //! Last encountered error std::string m_error; |