2020-05-19 16:23:53 +02:00
|
|
|
#include "base_surface_opengl3d.h"
|
|
|
|
|
2020-05-19 18:32:27 +02:00
|
|
|
#include "../base_image.h"
|
|
|
|
#include "base_render_opengl3d.h"
|
|
|
|
|
|
|
|
Wintermute::BaseSurfaceOpenGL3D::BaseSurfaceOpenGL3D(Wintermute::BaseGame* game, BaseRenderOpenGL3D* renderer)
|
2020-05-21 03:35:32 +02:00
|
|
|
: BaseSurface(game), tex(nullptr), renderer(renderer), pixelOpReady(false)
|
2020-05-19 16:23:53 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::invalidate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayHalfTrans(int x, int y, Wintermute::Rect32 rect) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::isTransparentAt(int x, int y) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayTransZoom(int x, int y, Wintermute::Rect32 rect, float zoomX, float zoomY, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayTrans(int x, int y, Wintermute::Rect32 rect, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
2020-05-21 03:35:32 +02:00
|
|
|
renderer->drawSprite(*tex, rect, 100, 100, Vector2(x, y), alpha, false, blendMode, mirrorX, mirrorY);
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayTransOffset(int x, int y, Wintermute::Rect32 rect, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::display(int x, int y, Wintermute::Rect32 rect, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
2020-05-21 03:35:32 +02:00
|
|
|
renderer->drawSprite(*tex, rect, 100, 100, Vector2(x, y), 0xFFFFFFFF, true, blendMode, mirrorX, mirrorY);
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayTransform(int x, int y, Wintermute::Rect32 rect, Wintermute::Rect32 newRect, const Graphics::TransformStruct& transform) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayZoom(int x, int y, Wintermute::Rect32 rect, float zoomX, float zoomY, uint32 alpha, bool transparent, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::displayTiled(int x, int y, Wintermute::Rect32 rect, int numTimesX, int numTimesY) {
|
2020-05-21 19:43:38 +02:00
|
|
|
Vector2 scale(numTimesX, numTimesY);
|
|
|
|
renderer->drawSpriteEx(*tex, rect, Vector2(x, y), Vector2(0, 0), scale, 0, 0xFFFFFFFF, true, Graphics::BLEND_NORMAL, false, false);
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::restore() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::create(const Common::String& filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime, bool keepLoaded) {
|
2020-05-21 03:35:32 +02:00
|
|
|
BaseImage img = BaseImage();
|
2020-05-19 18:32:27 +02:00
|
|
|
if (!img.loadFile(filename)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img.getSurface()->format.bytesPerPixel == 1 && img.getPalette() == nullptr)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-21 03:35:32 +02:00
|
|
|
Graphics::Surface* surf = img.getSurface()->convertTo(OpenGL::Texture::getRGBAPixelFormat(), img.getPalette());
|
|
|
|
tex = new OpenGL::Texture(*surf);
|
|
|
|
delete surf;
|
2020-05-19 18:32:27 +02:00
|
|
|
|
|
|
|
_filename = filename;
|
|
|
|
|
|
|
|
if (defaultCK) {
|
|
|
|
ckRed = 255;
|
|
|
|
ckGreen = 0;
|
|
|
|
ckBlue = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ckDefault = defaultCK;
|
|
|
|
_ckRed = ckRed;
|
|
|
|
_ckGreen = ckGreen;
|
|
|
|
_ckBlue = ckBlue;
|
|
|
|
|
|
|
|
if (_lifeTime == 0 || lifeTime == -1 || lifeTime > _lifeTime) {
|
|
|
|
_lifeTime = lifeTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
_keepLoaded = keepLoaded;
|
|
|
|
if (_keepLoaded) {
|
|
|
|
_lifeTime = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_valid = true;
|
|
|
|
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::create(int width, int height) {
|
2020-05-21 03:35:32 +02:00
|
|
|
tex = new OpenGL::Texture(width, height);
|
2020-05-19 18:32:27 +02:00
|
|
|
_valid = true;
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::putPixel(int x, int y, byte r, byte g, byte b, int a) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::getPixel(int x, int y, byte* r, byte* g, byte* b, byte* a) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::comparePixel(int x, int y, byte r, byte g, byte b, int a) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::startPixelOp() {
|
2020-05-21 03:35:32 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->getTextureName());
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::endPixelOp() {
|
2020-05-19 18:32:27 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2020-05-19 16:23:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wintermute::BaseSurfaceOpenGL3D::isTransparentAtLite(int x, int y) {
|
2020-05-21 03:35:32 +02:00
|
|
|
if (x < 0 || y < 0 || x >= tex->getWidth() || y >= tex->getHeight()) {
|
2020-05-19 18:32:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pixelOpReady) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8* image_data = nullptr;
|
|
|
|
|
|
|
|
// assume 32 bit rgba for now
|
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
|
|
|
|
|
2020-05-21 03:35:32 +02:00
|
|
|
uint32 pixel = *reinterpret_cast<uint32*>(image_data + y * tex->getWidth() * 4 + x * 4);
|
2020-05-19 18:32:27 +02:00
|
|
|
pixel &= 0xFFFFFF00;
|
|
|
|
return pixel == 0;
|
2020-05-19 16:23:53 +02:00
|
|
|
}
|