forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STARK: Fully separate bitmaps and textures
- Loading branch information
1 parent
63a2dc4
commit 5bd0ec4
Showing
66 changed files
with
473 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* 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 STARK_GFX_BITMAP_H | ||
#define STARK_GFX_BITMAP_H | ||
|
||
#include "common/hash-str.h" | ||
|
||
namespace Graphics { | ||
struct Surface; | ||
} | ||
|
||
namespace Stark { | ||
namespace Gfx { | ||
|
||
/** | ||
* An abstract bitmap | ||
*/ | ||
class Bitmap { | ||
public: | ||
Bitmap() : _width(0), _height(0) {} | ||
virtual ~Bitmap() {} | ||
|
||
enum SamplingFilter { | ||
kNearest, | ||
kLinear | ||
}; | ||
|
||
/** Make the texture active */ | ||
virtual void bind() const = 0; | ||
|
||
/** Define or update the texture pixel data */ | ||
virtual void update(const Graphics::Surface *surface, const byte *palette = nullptr) = 0; | ||
|
||
/** Set the filter used when sampling the texture */ | ||
virtual void setSamplingFilter(SamplingFilter filter) = 0; | ||
|
||
/** Get the texture width */ | ||
uint32 width() const { return _width; } | ||
|
||
/** Get the texture height */ | ||
uint32 height() const { return _height; } | ||
|
||
protected: | ||
uint32 _width; | ||
uint32 _height; | ||
}; | ||
|
||
} // End of namespace Gfx | ||
} // End of namespace Stark | ||
|
||
#endif // STARK_GFX_BITMAP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* 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 "engines/stark/gfx/openglbitmap.h" | ||
|
||
#include "engines/stark/gfx/driver.h" | ||
|
||
#include "graphics/surface.h" | ||
|
||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) | ||
|
||
#include "graphics/opengl/context.h" | ||
|
||
namespace Stark { | ||
namespace Gfx { | ||
|
||
OpenGlBitmap::OpenGlBitmap() : | ||
Bitmap(), | ||
_id(0) { | ||
glGenTextures(1, &_id); | ||
|
||
bind(); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
} | ||
|
||
OpenGlBitmap::~OpenGlBitmap() { | ||
glDeleteTextures(1, &_id); | ||
} | ||
|
||
void OpenGlBitmap::bind() const { | ||
glBindTexture(GL_TEXTURE_2D, _id); | ||
} | ||
|
||
void OpenGlBitmap::update(const Graphics::Surface *surface, const byte *palette) { | ||
bind(); | ||
|
||
_width = surface->w; | ||
_height = surface->h; | ||
|
||
if (surface->format.bytesPerPixel != 4) { | ||
// Convert the surface to texture format | ||
Graphics::Surface *convertedSurface = surface->convertTo(Driver::getRGBAPixelFormat(), palette); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, convertedSurface->w, convertedSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, convertedSurface->getPixels()); | ||
|
||
convertedSurface->free(); | ||
delete convertedSurface; | ||
} else { | ||
assert(surface->format == Driver::getRGBAPixelFormat()); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->getPixels()); | ||
} | ||
} | ||
|
||
void OpenGlBitmap::setSamplingFilter(Bitmap::SamplingFilter filter) { | ||
switch (filter) { | ||
case kNearest: | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
break; | ||
case kLinear: | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
break; | ||
default: | ||
warning("Unhandled sampling filter %d", filter); | ||
} | ||
} | ||
|
||
} // End of namespace Gfx | ||
} // End of namespace Stark | ||
|
||
#endif // defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* 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 STARK_GFX_OPENGL_BITMAP_H | ||
#define STARK_GFX_OPENGL_BITMAP_H | ||
|
||
#include "engines/stark/gfx/bitmap.h" | ||
|
||
#include "graphics/opengl/system_headers.h" | ||
|
||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) | ||
|
||
namespace Stark { | ||
namespace Gfx { | ||
|
||
/** | ||
* An OpenGL texture wrapper for 2D elements | ||
*/ | ||
class OpenGlBitmap : public Bitmap { | ||
public: | ||
OpenGlBitmap(); | ||
virtual ~OpenGlBitmap(); | ||
|
||
// Bitmap API | ||
void bind() const override; | ||
void update(const Graphics::Surface *surface, const byte *palette = nullptr) override; | ||
void setSamplingFilter(SamplingFilter filter) override; | ||
|
||
protected: | ||
GLuint _id; | ||
}; | ||
|
||
} // End of namespace Gfx | ||
} // End of namespace Stark | ||
|
||
#endif // defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) | ||
|
||
#endif // STARK_GFX_OPENGL_BITMAP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.