diff --git a/engines/myst3/gfx_opengl.cpp b/engines/myst3/gfx_opengl.cpp index d80bc707b25..3bcaaba0f83 100644 --- a/engines/myst3/gfx_opengl.cpp +++ b/engines/myst3/gfx_opengl.cpp @@ -27,6 +27,7 @@ #endif #include "engines/myst3/gfx.h" +#include "engines/myst3/gfx_opengl_texture.h" #include "common/rect.h" #include "common/textconsole.h" @@ -38,88 +39,8 @@ #include "math/vector2d.h" -#ifdef SDL_BACKEND -#include -#else -#include -#include -#endif - namespace Myst3 { -class OpenGLTexture : public Texture { -public: - OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport); - virtual ~OpenGLTexture(); - - void update(const Graphics::Surface *surface); - - GLuint id; - GLuint internalFormat; - GLuint sourceFormat; - uint32 internalWidth; - uint32 internalHeight; -}; - -// From Bit Twiddling Hacks -static uint32 upperPowerOfTwo(uint32 v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} - -OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport) { - width = surface->w; - height = surface->h; - format = surface->format; - - // Pad the textures if non power of two support is unavailable - if (nonPoTSupport) { - internalHeight = height; - internalWidth = width; - } else { - internalHeight = upperPowerOfTwo(height); - internalWidth = upperPowerOfTwo(width); - } - - if (format.bytesPerPixel == 4) { - internalFormat = GL_RGBA; - sourceFormat = GL_UNSIGNED_BYTE; - } else if (format.bytesPerPixel == 2) { - internalFormat = GL_RGB; - sourceFormat = GL_UNSIGNED_SHORT_5_6_5; - } else - error("Unknown pixel format"); - - glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, internalWidth, internalHeight, 0, internalFormat, sourceFormat, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // TODO: If non power of two textures are unavailable this clamping - // has no effect on the padded sides (resulting in white lines on the edges) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - update(surface); -} - -OpenGLTexture::~OpenGLTexture() { - glDeleteTextures(1, &id); -} - -void OpenGLTexture::update(const Graphics::Surface *surface) { - glBindTexture(GL_TEXTURE_2D, id); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->w, surface->h, internalFormat, sourceFormat, surface->getPixels()); -} - Renderer::Renderer(OSystem *system) : _system(system), _font(0), diff --git a/engines/myst3/gfx_opengl_shaders.cpp b/engines/myst3/gfx_opengl_shaders.cpp index 5cc5df333a0..d29d9f02c1b 100644 --- a/engines/myst3/gfx_opengl_shaders.cpp +++ b/engines/myst3/gfx_opengl_shaders.cpp @@ -27,6 +27,7 @@ #endif #include "engines/myst3/gfx.h" +#include "engines/myst3/gfx_opengl_texture.h" #include "common/rect.h" #include "common/textconsole.h" @@ -44,33 +45,6 @@ namespace Myst3 { -class OpenGLTexture : public Texture { -public: - OpenGLTexture(const Graphics::Surface *surface); - virtual ~OpenGLTexture(); - - void update(const Graphics::Surface *surface); - - GLuint id; - GLuint internalFormat; - GLuint sourceFormat; - uint32 internalWidth; - uint32 internalHeight; -}; - -// From Bit Twiddling Hacks -static uint32 upperPowerOfTwo(uint32 v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} - static struct { Graphics::Shader *g_box_shader; Graphics::Shader *g_cube_shader; @@ -143,47 +117,6 @@ static Math::Vector2d scaled(float x, float y) { return Math::Vector2d(x / Renderer::kOriginalWidth, y / Renderer::kOriginalHeight); } -OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface) { - width = surface->w; - height = surface->h; - format = surface->format; - - internalHeight = upperPowerOfTwo(height); - internalWidth = upperPowerOfTwo(width); - - if (format.bytesPerPixel == 4) { - internalFormat = GL_RGBA; - sourceFormat = GL_UNSIGNED_BYTE; - } else if (format.bytesPerPixel == 2) { - internalFormat = GL_RGB; - sourceFormat = GL_UNSIGNED_SHORT_5_6_5; - } else { - error("Unknown pixel format"); - } - - glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, internalWidth, internalHeight, 0, internalFormat, sourceFormat, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // TODO: If non power of two textures are unavailable this clamping - // has no effect on the padded sides (resulting in white lines on the edges) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - update(surface); -} - -OpenGLTexture::~OpenGLTexture() { - glDeleteTextures(1, &id); -} - -void OpenGLTexture::update(const Graphics::Surface *surface) { - glBindTexture(GL_TEXTURE_2D, id); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->w, surface->h, internalFormat, sourceFormat, surface->getPixels()); -} - Renderer::Renderer(OSystem *system) : _system(system), _font(0), diff --git a/engines/myst3/gfx_opengl_texture.cpp b/engines/myst3/gfx_opengl_texture.cpp new file mode 100644 index 00000000000..da394633f64 --- /dev/null +++ b/engines/myst3/gfx_opengl_texture.cpp @@ -0,0 +1,86 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "engines/myst3/gfx_opengl_texture.h" + +namespace Myst3 { + +// From Bit Twiddling Hacks +static uint32 upperPowerOfTwo(uint32 v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + +OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport) { + width = surface->w; + height = surface->h; + format = surface->format; + + // Pad the textures if non power of two support is unavailable + if (nonPoTSupport) { + internalHeight = height; + internalWidth = width; + } else { + internalHeight = upperPowerOfTwo(height); + internalWidth = upperPowerOfTwo(width); + } + + if (format.bytesPerPixel == 4) { + internalFormat = GL_RGBA; + sourceFormat = GL_UNSIGNED_BYTE; + } else if (format.bytesPerPixel == 2) { + internalFormat = GL_RGB; + sourceFormat = GL_UNSIGNED_SHORT_5_6_5; + } else + error("Unknown pixel format"); + + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, internalWidth, internalHeight, 0, internalFormat, sourceFormat, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + // TODO: If non power of two textures are unavailable this clamping + // has no effect on the padded sides (resulting in white lines on the edges) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + update(surface); +} + +OpenGLTexture::~OpenGLTexture() { + glDeleteTextures(1, &id); +} + +void OpenGLTexture::update(const Graphics::Surface *surface) { + glBindTexture(GL_TEXTURE_2D, id); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->w, surface->h, internalFormat, sourceFormat, surface->getPixels()); +} + +} // end of namespace Myst3 diff --git a/engines/myst3/gfx_opengl_texture.h b/engines/myst3/gfx_opengl_texture.h new file mode 100644 index 00000000000..6fc9cef540e --- /dev/null +++ b/engines/myst3/gfx_opengl_texture.h @@ -0,0 +1,50 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GFX_OPENGL_TEXTURE_H +#define GFX_OPENGL_TEXTURE_H + +#include "graphics/surface.h" +#include "graphics/opengles2/system_headers.h" +#include "common/textconsole.h" + +#include "engines/myst3/gfx.h" + +namespace Myst3 { + +class OpenGLTexture : public Texture { +public: + OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport = false); + virtual ~OpenGLTexture(); + + void update(const Graphics::Surface *surface); + + GLuint id; + GLuint internalFormat; + GLuint sourceFormat; + uint32 internalWidth; + uint32 internalHeight; +}; + +} // end of namespace Myst3 + +#endif diff --git a/engines/myst3/module.mk b/engines/myst3/module.mk index 9d669d9f544..b77794c0a4f 100644 --- a/engines/myst3/module.mk +++ b/engines/myst3/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS := \ directorysubentry.o \ gfx_opengl.o \ gfx_opengl_shaders.o \ + gfx_opengl_texture.o \ hotspot.o \ inventory.o \ menu.o \