mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 09:18:38 +00:00
WATCHMAKER: Move GL Texture logic to its own file
This commit is contained in:
parent
823932c9e1
commit
76707bbac8
@ -141,24 +141,6 @@ bool gClipToBlitterViewport(int *sposx, int *sposy, int *sdimx, int *sdimy,
|
||||
return true;
|
||||
}
|
||||
|
||||
void enter2Dmode(WGame &game) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
checkGlError("Exiting enter2Dmode");
|
||||
}
|
||||
|
||||
void exit2Dmode() {
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
checkGlError("exit2Dmode");
|
||||
}
|
||||
|
||||
void renderTexture(WGame &game, gTexture &bitmap, Rect srcRect, Rect dstRect) {
|
||||
checkGlError("Entering renderTexture");
|
||||
glClearColor(0, 0, 1, 0);
|
||||
@ -216,9 +198,9 @@ void gTexture::render(WGame &game, Rect src, Rect dst) {
|
||||
|
||||
void Renderer::blitScreenBuffer() {
|
||||
checkGlError("Entering rBlitScreenBuffer");
|
||||
enter2Dmode(*_game);
|
||||
g_renderer->enter2Dmode();
|
||||
_bitmapList.bitmaps[BACK_BUFFER].render(*_game, _game->_renderer->_viewport, _game->_renderer->_viewport);
|
||||
exit2Dmode();
|
||||
g_renderer->exit2Dmode();
|
||||
checkGlError("Exiting rBlitScreenBuffer");
|
||||
}
|
||||
|
||||
|
@ -553,63 +553,6 @@ gTexture *gUserTexture(Texture *texture, unsigned int dimx, unsigned int dimy) {
|
||||
return Texture;
|
||||
}
|
||||
|
||||
GLuint dxtCompressionToTextureFormat(DxtCompression compression) {
|
||||
switch (compression) {
|
||||
case DxtCompression::UNCOMPRESSED:
|
||||
return GL_RGBA;
|
||||
case DxtCompression::DXT1:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case DxtCompression::DXT2:
|
||||
error("DXT2 Support is not implemented");
|
||||
case DxtCompression::DXT3:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case DxtCompression::DXT4:
|
||||
error("DXT4 Support is not implemented");
|
||||
case DxtCompression::DXT5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
}
|
||||
}
|
||||
|
||||
class OpenGLTexture : public Texture {
|
||||
public:
|
||||
unsigned int _texId;
|
||||
OpenGLTexture() {
|
||||
glGenTextures(1, &_texId);
|
||||
}
|
||||
OpenGLTexture(unsigned int texId) : _texId(texId) {}
|
||||
void assignData(const TextureData &data) override {
|
||||
glBindTexture(GL_TEXTURE_2D, _texId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
// TODO: Check both compiletime and runtime for the existence of EXT_texture_compression_s3tc
|
||||
GLuint texFormat = dxtCompressionToTextureFormat(data._compression);
|
||||
bool compressed = data._compression != DxtCompression::UNCOMPRESSED;
|
||||
|
||||
if (compressed) {
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, // target
|
||||
0, // level
|
||||
texFormat, // internalFormat
|
||||
data.getWidth(), // width
|
||||
data.getHeight(), // height
|
||||
0, // border
|
||||
data.getDataSize(),
|
||||
data.getData()
|
||||
);
|
||||
checkGlError("glCompressedTexImage");
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texFormat, data.getWidth(), data.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data.getData());
|
||||
checkGlError("glTexImage2D");
|
||||
}
|
||||
}
|
||||
void bind() override {
|
||||
glBindTexture(GL_TEXTURE_2D, _texId);
|
||||
checkGlError("OpenGLTexture::bind");
|
||||
};
|
||||
};
|
||||
|
||||
class SurfaceBackedTextureData : public TextureData {
|
||||
bool _owned = true;
|
||||
public:
|
||||
@ -635,10 +578,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
Texture *createGLTexture() {
|
||||
return new OpenGLTexture();
|
||||
}
|
||||
|
||||
Common::SharedPtr<TextureData> createTextureFromSurface(Graphics::Surface &surface, int texFormat) {
|
||||
return Common::SharedPtr<TextureData>(new SurfaceBackedTextureData(&surface, false));
|
||||
}
|
||||
@ -710,7 +649,7 @@ gTexture *gLoadTexture(WorkDirs &workDirs, const char *TextName, unsigned int Lo
|
||||
}
|
||||
texture = &gTextureList[pos];
|
||||
*texture = gTexture();
|
||||
texture->_texture = new OpenGLTexture();
|
||||
texture->_texture = createGLTexture();
|
||||
|
||||
if (bUseAlternate) {
|
||||
auto stream = workDirs.resolveFile(AlternateName);
|
||||
|
@ -209,6 +209,24 @@ void OpenGLRenderer::setBlendFunc(BlendFactor src, BlendFactor dst) {
|
||||
glBlendFunc(translateBlendFactorToGL(src), translateBlendFactorToGL(dst));
|
||||
}
|
||||
|
||||
void OpenGLRenderer::enter2Dmode() {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
checkGlError("Exiting enter2Dmode");
|
||||
}
|
||||
|
||||
void OpenGLRenderer::exit2Dmode() {
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
checkGlError("exit2Dmode");
|
||||
}
|
||||
|
||||
} // End of namespace Watchmaker
|
||||
|
||||
#endif // USE_OPENGL_GAME
|
||||
|
@ -72,6 +72,9 @@ Texture *createGLTexture();
|
||||
|
||||
class OpenGLRenderer {
|
||||
public:
|
||||
void enter2Dmode();
|
||||
void exit2Dmode();
|
||||
|
||||
void pushModelView();
|
||||
void popModelView();
|
||||
void setTransformMatrix(TransformMatrix which, const Matrix4x4 &matrix);
|
||||
|
95
engines/watchmaker/3d/render/opengl_texture.cpp
Normal file
95
engines/watchmaker/3d/render/opengl_texture.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "watchmaker/3d/render/opengl_texture.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "graphics/opengl/system_headers.h"
|
||||
#include "watchmaker/3d/dds_header.h"
|
||||
#include "watchmaker/render.h"
|
||||
|
||||
#ifdef USE_OPENGL_GAME
|
||||
|
||||
namespace Watchmaker {
|
||||
|
||||
GLuint dxtCompressionToTextureFormat(DxtCompression compression) {
|
||||
switch (compression) {
|
||||
case DxtCompression::UNCOMPRESSED:
|
||||
return GL_RGBA;
|
||||
case DxtCompression::DXT1:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case DxtCompression::DXT2:
|
||||
error("DXT2 Support is not implemented");
|
||||
case DxtCompression::DXT3:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case DxtCompression::DXT4:
|
||||
error("DXT4 Support is not implemented");
|
||||
case DxtCompression::DXT5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
}
|
||||
}
|
||||
|
||||
class OpenGLTexture : public Texture {
|
||||
public:
|
||||
unsigned int _texId;
|
||||
OpenGLTexture() {
|
||||
glGenTextures(1, &_texId);
|
||||
}
|
||||
OpenGLTexture(unsigned int texId) : _texId(texId) {}
|
||||
void assignData(const TextureData &data) override {
|
||||
glBindTexture(GL_TEXTURE_2D, _texId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
// TODO: Check both compiletime and runtime for the existence of EXT_texture_compression_s3tc
|
||||
GLuint texFormat = dxtCompressionToTextureFormat(data._compression);
|
||||
bool compressed = data._compression != DxtCompression::UNCOMPRESSED;
|
||||
|
||||
if (compressed) {
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, // target
|
||||
0, // level
|
||||
texFormat, // internalFormat
|
||||
data.getWidth(), // width
|
||||
data.getHeight(), // height
|
||||
0, // border
|
||||
data.getDataSize(),
|
||||
data.getData()
|
||||
);
|
||||
checkGlError("glCompressedTexImage");
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texFormat, data.getWidth(), data.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data.getData());
|
||||
checkGlError("glTexImage2D");
|
||||
}
|
||||
}
|
||||
void bind() override {
|
||||
glBindTexture(GL_TEXTURE_2D, _texId);
|
||||
checkGlError("OpenGLTexture::bind");
|
||||
};
|
||||
};
|
||||
|
||||
Texture *createGLTexture() {
|
||||
return new OpenGLTexture();
|
||||
}
|
||||
|
||||
} // End of namespace Watchmaker
|
||||
|
||||
#endif // USE_OPENGL_GAME
|
32
engines/watchmaker/3d/render/opengl_texture.h
Normal file
32
engines/watchmaker/3d/render/opengl_texture.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WATCHMAKER_3D_OPENGL_TEXTURE_H
|
||||
#define WATCHMAKER_3D_OPENGL_TEXTURE_H
|
||||
|
||||
namespace Watchmaker {
|
||||
|
||||
class Texture;
|
||||
Texture *createGLTexture();
|
||||
|
||||
} // End of namespace Watchmaker
|
||||
|
||||
#endif // WATCHMAKER_3D_OPENGL_TEXTURE_H
|
@ -15,6 +15,7 @@ MODULE_OBJS = \
|
||||
3d/render/opengl_2d.o \
|
||||
3d/render/opengl_3d.o \
|
||||
3d/render/opengl_renderer.o \
|
||||
3d/render/opengl_texture.o \
|
||||
3d/render/render.o \
|
||||
3d/render/shadows.o \
|
||||
3d/t3d_body.o \
|
||||
|
Loading…
x
Reference in New Issue
Block a user