[Scummvm-git-logs] scummvm master -> 6fd55467029e577766cf77d3db7fa497fd2b566f
aquadran
aquadran at gmail.com
Sat Jan 2 07:17:49 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6fd5546702 WINTERMUTE: Remove the OpenGL Texture renderer
Commit: 6fd55467029e577766cf77d3db7fa497fd2b566f
https://github.com/scummvm/scummvm/commit/6fd55467029e577766cf77d3db7fa497fd2b566f
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-01-02T08:17:46+01:00
Commit Message:
WINTERMUTE: Remove the OpenGL Texture renderer
Changed paths:
R engines/wintermute/base/gfx/opengl/base_render_opengl_texture.cpp
R engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h
R engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.cpp
R engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h
R engines/wintermute/base/gfx/opengl/render_ticket.cpp
R engines/wintermute/base/gfx/opengl/render_ticket.h
engines/wintermute/base/gfx/base_renderer.h
engines/wintermute/module.mk
diff --git a/engines/wintermute/base/gfx/base_renderer.h b/engines/wintermute/base/gfx/base_renderer.h
index bbf36c8af8..ae6bc0d573 100644
--- a/engines/wintermute/base/gfx/base_renderer.h
+++ b/engines/wintermute/base/gfx/base_renderer.h
@@ -239,7 +239,6 @@ BaseRenderer *makeOSystemRenderer(BaseGame *inGame); // Implemented in BRenderSD
#ifdef ENABLE_WME3D
class BaseRenderer3D;
-BaseRenderer *makeOpenGLTextureRenderer(BaseGame *inGame);
BaseRenderer3D *makeOpenGL3DRenderer(BaseGame *inGame);
BaseRenderer3D *makeOpenGL3DShaderRenderer(BaseGame *inGame);
#endif
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.cpp
deleted file mode 100644
index c957751076..0000000000
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.cpp
+++ /dev/null
@@ -1,648 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#include "engines/wintermute/base/base_surface_storage.h"
-#include "engines/wintermute/base/gfx/base_image.h"
-#include "engines/wintermute/math/math_util.h"
-#include "engines/wintermute/base/base_game.h"
-#include "engines/wintermute/base/base_sprite.h"
-#include "common/system.h"
-#include "common/queue.h"
-#include "common/config-manager.h"
-#include "graphics/transparent_surface.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-#include "graphics/opengl/texture.h"
-#include "graphics/opengl/surfacerenderer.h"
-#include "engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h"
-#include "engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h"
-#include "engines/wintermute/base/gfx/opengl/render_ticket.h"
-
-#define DIRTY_RECT_LIMIT 800
-
-namespace Wintermute {
-
-BaseRenderer *makeOpenGLTextureRenderer(BaseGame *inGame) {
- return new BaseRenderOpenGLTexture(inGame);
-}
-
-//////////////////////////////////////////////////////////////////////////
-BaseRenderOpenGLTexture::BaseRenderOpenGLTexture(BaseGame *inGame) : BaseRenderer(inGame) {
- _renderSurface = new Graphics::Surface();
- _blankSurface = new Graphics::Surface();
- _lastFrameIter = _renderQueue.end();
- _needsFlip = true;
- _skipThisFrame = false;
-
- _borderLeft = _borderRight = _borderTop = _borderBottom = 0;
- _ratioX = _ratioY = 1.0f;
- _dirtyRect = nullptr;
- _disableDirtyRects = false;
- if (ConfMan.hasKey("dirty_rects")) {
- _disableDirtyRects = !ConfMan.getBool("dirty_rects");
- }
-
- _disableDirtyRects = true;
-
- _lastScreenChangeID = g_system->getScreenChangeID();
-}
-
-//////////////////////////////////////////////////////////////////////////
-BaseRenderOpenGLTexture::~BaseRenderOpenGLTexture() {
- RenderQueueIterator it = _renderQueue.begin();
- while (it != _renderQueue.end()) {
- RenderTicketOpenGL *ticket = *it;
- it = _renderQueue.erase(it);
- delete ticket;
- }
-
- delete _dirtyRect;
-
- _renderSurface->free();
- delete _renderSurface;
- _blankSurface->free();
- delete _blankSurface;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseRenderOpenGLTexture::initRenderer(int width, int height, bool windowed) {
- _width = width;
- _height = height;
- _renderRect.setWidth(_width);
- _renderRect.setHeight(_height);
-
- _realWidth = width;
- _realHeight = height;
-
- //TODO: Tiny resolution-displays might want to do some resolution-selection logic here
-
- //_realWidth = BaseEngine::instance().getRegistry()->readInt("Debug", "ForceResWidth", _width);
- //_realHeight = BaseEngine::instance().getRegistry()->readInt("Debug", "ForceResHeight", _height);
-
- float origAspect = (float)_width / (float)_height;
- float realAspect = (float)_realWidth / (float)_realHeight;
-
- float ratio;
- if (origAspect < realAspect) {
- // normal to wide
- ratio = (float)_realHeight / (float)_height;
- } else {
- // wide to normal
- ratio = (float)_realWidth / (float)_width;
- }
-
- _borderLeft = (int)((_realWidth - (_width * ratio)) / 2);
- _borderRight = (int)(_realWidth - (_width * ratio) - _borderLeft);
-
- _borderTop = (int)((_realHeight - (_height * ratio)) / 2);
- _borderBottom = (int)(_realHeight - (_height * ratio) - _borderTop);
-
-
-
- _ratioX = (float)(_realWidth - _borderLeft - _borderRight) / (float)_width;
- _ratioY = (float)(_realHeight - _borderTop - _borderBottom) / (float)_height;
-
- _windowed = !ConfMan.getBool("fullscreen");
-
- Graphics::PixelFormat format = OpenGL::TextureGL::getRGBAPixelFormat();
-
- g_system->showMouse(false);
-
- _renderSurface->create(g_system->getWidth(), g_system->getHeight(), format);
- _blankSurface->create(g_system->getWidth(), g_system->getHeight(), format);
- _blankSurface->fillRect(Common::Rect(0, 0, _blankSurface->h, _blankSurface->w), _blankSurface->format.ARGBToColor(255, 0, 0, 0));
- _active = true;
-
- _clearColor = _renderSurface->format.ARGBToColor(255, 0, 0, 0);
-
- return STATUS_OK;
-}
-
-bool BaseRenderOpenGLTexture::indicatorFlip() {
- if (_indicatorWidthDrawn > 0 && _indicatorHeight > 0) {
- drawRenderSurface();
- g_system->updateScreen();
- }
- return STATUS_OK;
-}
-
-bool BaseRenderOpenGLTexture::forcedFlip() {
- drawRenderSurface();
- g_system->updateScreen();
- return STATUS_OK;
-}
-
-bool BaseRenderOpenGLTexture::flip() {
- if (_skipThisFrame) {
- _skipThisFrame = false;
- delete _dirtyRect;
- _dirtyRect = nullptr;
- drawRenderSurface();
- g_system->updateScreen();
- _needsFlip = false;
-
- // Reset ticketing state
- _lastFrameIter = _renderQueue.end();
- RenderQueueIterator it;
- for (it = _renderQueue.begin(); it != _renderQueue.end(); ++it) {
- (*it)->_wantsDraw = false;
- }
-
- addDirtyRect(_renderRect);
- return true;
- }
- if (!_disableDirtyRects) {
- drawTickets();
- } else {
- // Clear the scale-buffered tickets that wasn't reused.
- RenderQueueIterator it = _renderQueue.begin();
- while (it != _renderQueue.end()) {
- if ((*it)->_wantsDraw == false) {
- RenderTicketOpenGL *ticket = *it;
- it = _renderQueue.erase(it);
- delete ticket;
- } else {
- (*it)->_wantsDraw = false;
- ++it;
- }
- }
- }
-
- int oldScreenChangeID = _lastScreenChangeID;
- _lastScreenChangeID = g_system->getScreenChangeID();
- bool screenChanged = _lastScreenChangeID != oldScreenChangeID;
-
- if (_needsFlip || _disableDirtyRects || screenChanged) {
- if (_disableDirtyRects || screenChanged) {
- //g_system->copyRectToScreen((byte *)_renderSurface->getPixels(), _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
- }
- // g_system->copyRectToScreen((byte *)_renderSurface->getPixels(), _renderSurface->pitch, _dirtyRect->left, _dirtyRect->top, _dirtyRect->width(), _dirtyRect->height());
- delete _dirtyRect;
- _dirtyRect = nullptr;
- _needsFlip = false;
- }
- _lastFrameIter = _renderQueue.end();
-
- drawRenderSurface();
- g_system->updateScreen();
-
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::onWindowChange() {
- _windowed = !g_system->getFeatureState(OSystem::kFeatureFullscreenMode);
-}
-
-//////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::setWindowed(bool windowed) {
- ConfMan.setBool("fullscreen", !windowed);
- g_system->beginGFXTransaction();
- g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !windowed);
- g_system->endGFXTransaction();
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseRenderOpenGLTexture::fill(byte r, byte g, byte b, Common::Rect *rect) {
- _clearColor = _renderSurface->format.ARGBToColor(0xFF, r, g, b);
- if (!_disableDirtyRects) {
- return STATUS_OK;
- }
- if (!rect) {
-// TODO: This should speed things up, but for some reason it misses the size by quite a bit.
-/* if (r == 0 && g == 0 && b == 0) {
- // Simply memcpy from the buffered black-surface, way faster than Surface::fillRect.
- memcpy(_renderSurface->pixels, _blankSurface->pixels, _renderSurface->pitch * _renderSurface->h);
- return STATUS_OK;
- }*/
- rect = &_renderRect;
- }
- // TODO: This doesn't work with dirty rects
- _renderSurface->fillRect(*rect, _clearColor);
-
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::fade(uint16 alpha) {
- byte dwAlpha = (byte)(255 - alpha);
- return fadeToColor(0, 0, 0, dwAlpha);
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::fadeToColor(byte r, byte g, byte b, byte a) {
- Common::Rect fillRect;
-
- Rect32 rc;
- _gameRef->getCurrentViewportRect(&rc);
- fillRect.left = (int16)rc.left;
- fillRect.top = (int16)rc.top;
- fillRect.setWidth((int16)(rc.right - rc.left));
- fillRect.setHeight((int16)(rc.bottom - rc.top));
-
- modTargetRect(&fillRect);
-
- //TODO: This is only here until I'm sure about the final pixelformat
- uint32 col = _renderSurface->format.ARGBToColor(a, r, g, b);
-
- Graphics::Surface surf;
- surf.create((uint16)fillRect.width(), (uint16)fillRect.height(), _renderSurface->format);
- Common::Rect sizeRect(fillRect);
- sizeRect.translate(-fillRect.top, -fillRect.left);
- surf.fillRect(fillRect, col);
- Graphics::TransformStruct temp = Graphics::TransformStruct();
- temp._alphaDisable = false;
- drawSurface(nullptr, &surf, &sizeRect, &fillRect, temp);
- surf.free();
-
- //SDL_SetRenderDrawColor(_renderer, r, g, b, a);
- //SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_BLEND);
- //SDL_RenderFillRect(_renderer, &fillRect);
-}
-
-Graphics::PixelFormat BaseRenderOpenGLTexture::getPixelFormat() const {
- return _renderSurface->format;
-}
-
-void BaseRenderOpenGLTexture::drawSurface(BaseSurfaceOpenGLTexture *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, Graphics::TransformStruct &transform) {
-
- if (_disableDirtyRects) {
- RenderTicketOpenGL *ticket = new RenderTicketOpenGL(owner, surf, srcRect, dstRect, transform);
- ticket->_wantsDraw = true;
- _renderQueue.push_back(ticket);
- drawFromSurface(ticket);
- return;
- }
-
- // Skip rects that are completely outside the screen:
- if ((dstRect->left < 0 && dstRect->right < 0) || (dstRect->top < 0 && dstRect->bottom < 0)) {
- return;
- }
-
- if (owner) { // Fade-tickets are owner-less
- RenderTicketOpenGL compare(owner, nullptr, srcRect, dstRect, transform);
- RenderQueueIterator it = _lastFrameIter;
- ++it;
- // Avoid calling end() and operator* every time, when potentially going through
- // LOTS of tickets.
- RenderQueueIterator endIterator = _renderQueue.end();
- RenderTicketOpenGL *compareTicket = nullptr;
- for (; it != endIterator; ++it) {
- compareTicket = *it;
- if (*(compareTicket) == compare && compareTicket->_isValid) {
- if (_disableDirtyRects) {
- drawFromSurface(compareTicket);
- } else {
- drawFromQueuedTicket(it);
- }
- return;
- }
- }
- }
- RenderTicketOpenGL *ticket = new RenderTicketOpenGL(owner, surf, srcRect, dstRect, transform);
- if (!_disableDirtyRects) {
- drawFromTicket(ticket);
- } else {
- ticket->_wantsDraw = true;
- _renderQueue.push_back(ticket);
- drawFromSurface(ticket);
- }
-}
-
-void BaseRenderOpenGLTexture::invalidateTicket(RenderTicketOpenGL *renderTicket) {
- addDirtyRect(renderTicket->_dstRect);
- renderTicket->_isValid = false;
-// renderTicket->_canDelete = true; // TODO: Maybe readd this, to avoid even more duplicates.
-}
-
-void BaseRenderOpenGLTexture::invalidateTicketsFromSurface(BaseSurfaceOpenGLTexture *surf) {
- RenderQueueIterator it;
- for (it = _renderQueue.begin(); it != _renderQueue.end(); ++it) {
- if ((*it)->_owner == surf) {
- invalidateTicket(*it);
- }
- }
-}
-
-void BaseRenderOpenGLTexture::drawFromTicket(RenderTicketOpenGL *renderTicket) {
- renderTicket->_wantsDraw = true;
-
- ++_lastFrameIter;
- // In-order
- if (_renderQueue.empty() || _lastFrameIter == _renderQueue.end()) {
- _lastFrameIter--;
- _renderQueue.push_back(renderTicket);
- ++_lastFrameIter;
- addDirtyRect(renderTicket->_dstRect);
- } else {
- // Before something
- RenderQueueIterator pos = _lastFrameIter;
- _renderQueue.insert(pos, renderTicket);
- --_lastFrameIter;
- addDirtyRect(renderTicket->_dstRect);
- }
-}
-
-void BaseRenderOpenGLTexture::drawFromQueuedTicket(const RenderQueueIterator &ticket) {
- RenderTicketOpenGL *renderTicket = *ticket;
- assert(!renderTicket->_wantsDraw);
- renderTicket->_wantsDraw = true;
-
- ++_lastFrameIter;
- // Not in the same order?
- if (*_lastFrameIter != renderTicket) {
- --_lastFrameIter;
- // Remove the ticket from the list
- assert(*_lastFrameIter != renderTicket);
- _renderQueue.erase(ticket);
- // Is not in order, so readd it as if it was a new ticket
- drawFromTicket(renderTicket);
- }
-}
-
-void BaseRenderOpenGLTexture::addDirtyRect(const Common::Rect &rect) {
- if (!_dirtyRect) {
- _dirtyRect = new Common::Rect(rect);
- } else {
- _dirtyRect->extend(rect);
- }
- _dirtyRect->clip(_renderRect);
-}
-
-void BaseRenderOpenGLTexture::drawTickets() {
- RenderQueueIterator it = _renderQueue.begin();
- // Clean out the old tickets
- // Note: We draw invalid tickets too, otherwise we wouldn't be honoring
- // the draw request they obviously made BEFORE becoming invalid, either way
- // we have a copy of their data, so their invalidness won't affect us.
- while (it != _renderQueue.end()) {
- if ((*it)->_wantsDraw == false) {
- RenderTicketOpenGL *ticket = *it;
- addDirtyRect((*it)->_dstRect);
- it = _renderQueue.erase(it);
- delete ticket;
- } else {
- ++it;
- }
- }
- if (!_dirtyRect || _dirtyRect->width() == 0 || _dirtyRect->height() == 0) {
- it = _renderQueue.begin();
- while (it != _renderQueue.end()) {
- RenderTicketOpenGL *ticket = *it;
- ticket->_wantsDraw = false;
- ++it;
- }
- return;
- }
-
- it = _renderQueue.begin();
- _lastFrameIter = _renderQueue.end();
- // A special case: If the screen has one giant OPAQUE rect to be drawn, then we skip filling
- // the background color. Typical use-case: Fullscreen FMVs.
- // Caveat: The FPS-counter will invalidate this.
- if (it != _lastFrameIter && _renderQueue.front() == _renderQueue.back() && (*it)->_transform._alphaDisable == true) {
- // If our single opaque rect fills the dirty rect, we can skip filling.
- if (*_dirtyRect != (*it)->_dstRect) {
- // Apply the clear-color to the dirty rect.
- _renderSurface->fillRect(*_dirtyRect, _clearColor);
- }
- // Otherwise Do NOT fill.
- } else {
- // Apply the clear-color to the dirty rect.
- _renderSurface->fillRect(*_dirtyRect, _clearColor);
- }
- for (; it != _renderQueue.end(); ++it) {
- RenderTicketOpenGL *ticket = *it;
- if (ticket->_dstRect.intersects(*_dirtyRect)) {
- // dstClip is the area we want redrawn.
- Common::Rect dstClip(ticket->_dstRect);
- // reduce it to the dirty rect
- dstClip.clip(*_dirtyRect);
- // we need to keep track of the position to redraw the dirty rect
- Common::Rect pos(dstClip);
- int16 offsetX = ticket->_dstRect.left;
- int16 offsetY = ticket->_dstRect.top;
- // convert from screen-coords to surface-coords.
- dstClip.translate(-offsetX, -offsetY);
-
- drawFromSurface(ticket, &pos, &dstClip);
- _needsFlip = true;
- }
- // Some tickets want redraw but don't actually clip the dirty area (typically the ones that shouldnt become clear-color)
- ticket->_wantsDraw = false;
- }
- g_system->copyRectToScreen((byte *)_renderSurface->getBasePtr(_dirtyRect->left, _dirtyRect->top), _renderSurface->pitch, _dirtyRect->left, _dirtyRect->top, _dirtyRect->width(), _dirtyRect->height());
-
- it = _renderQueue.begin();
- // Clean out the old tickets
- while (it != _renderQueue.end()) {
- if ((*it)->_isValid == false) {
- RenderTicketOpenGL *ticket = *it;
- addDirtyRect((*it)->_dstRect);
- it = _renderQueue.erase(it);
- delete ticket;
- } else {
- ++it;
- }
- }
-
-}
-
-// Replacement for SDL2's SDL_RenderCopy
-void BaseRenderOpenGLTexture::drawFromSurface(RenderTicketOpenGL *ticket) {
- ticket->drawToSurface(_renderSurface);
-}
-
-void BaseRenderOpenGLTexture::drawFromSurface(RenderTicketOpenGL *ticket, Common::Rect *dstRect, Common::Rect *clipRect) {
- ticket->drawToSurface(_renderSurface, dstRect, clipRect);
-}
-
-void BaseRenderOpenGLTexture::drawRenderSurface() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-
- for (int i = 0; i < _renderSurface->h; ++i) {
- for (int j = 0; j < _renderSurface->w; ++j) {
- byte* pixel = reinterpret_cast<byte*>(_renderSurface->getPixels());
- pixel += i * _renderSurface->w * 4 + j * 4;
-
- byte tmp = pixel[0];
- pixel[0] = pixel[3];
- pixel[3] = tmp;
- tmp = pixel[1];
- pixel[1] = pixel[2];
- pixel[2] = tmp;
- }
- }
-
- OpenGL::TextureGL tex(*_renderSurface);
-
- OpenGL::SurfaceRenderer* renderer = OpenGL::createBestSurfaceRenderer();
-
- renderer->prepareState();
- renderer->setFlipY(true);
- renderer->render(&tex, Math::Rect2d(Math::Vector2d(0, 0), Math::Vector2d(1, 1)));
- renderer->restorePreviousState();
- delete renderer;
-
- uint32 background = BYTETORGBA(0, 0, 0, 0);
- _renderSurface->fillRect(Common::Rect(0, 0, _renderSurface->w, _renderSurface->h), background);
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseRenderOpenGLTexture::drawLine(int x1, int y1, int x2, int y2, uint32 color) {
- // This function isn't used outside of indicator-displaying, and thus quite unused in
- // BaseRenderOpenGL when dirty-rects are enabled.
- if (!_disableDirtyRects && !_indicatorDisplay) {
- error("BaseRenderOpenGL::DrawLine - doesn't work for dirty rects yet");
- }
-
- byte r = RGBCOLGetR(color);
- byte g = RGBCOLGetG(color);
- byte b = RGBCOLGetB(color);
- byte a = RGBCOLGetA(color);
-
- //SDL_SetRenderDrawColor(_renderer, r, g, b, a);
- //SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_BLEND);
-
- Point32 point1, point2;
- point1.x = x1;
- point1.y = y1;
- pointToScreen(&point1);
-
- point2.x = x2;
- point2.y = y2;
- pointToScreen(&point2);
-
- // TODO: This thing is mostly here until I'm sure about the final color-format.
- uint32 colorVal = _renderSurface->format.ARGBToColor(a, r, g, b);
- _renderSurface->drawLine(point1.x, point1.y, point2.x, point2.y, colorVal);
- //SDL_RenderDrawLine(_renderer, point1.x, point1.y, point2.x, point2.y);
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-BaseImage *BaseRenderOpenGLTexture::takeScreenshot() {
-// TODO: Clip by viewport.
- BaseImage *screenshot = new BaseImage();
- screenshot->copyFrom(_renderSurface);
- return screenshot;
-}
-
-//////////////////////////////////////////////////////////////////////////
-Common::String BaseRenderOpenGLTexture::getName() const {
- return "3D-OSystem-renderer";
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseRenderOpenGLTexture::setViewport(int left, int top, int right, int bottom) {
- Common::Rect rect;
- // TODO: Hopefully this is the same logic that ScummVM uses.
- rect.left = (int16)(left + _borderLeft);
- rect.top = (int16)(top + _borderTop);
- rect.setWidth((int16)((right - left) * _ratioX));
- rect.setHeight((int16)((bottom - top) * _ratioY));
-
- _renderRect = rect;
- return STATUS_OK;
-}
-
-Rect32 BaseRenderOpenGLTexture::getViewPort() {
- Rect32 ret;
- ret.top = _renderRect.top;
- ret.bottom = _renderRect.bottom;
- ret.left = _renderRect.left;
- ret.right = _renderRect.right;
- return ret;
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::modTargetRect(Common::Rect *rect) {
- return;
- int newWidth = (int16)MathUtil::roundUp(rect->width() * _ratioX);
- int newHeight = (int16)MathUtil::roundUp(rect->height() * _ratioY);
- rect->left = (int16)MathUtil::round(rect->left * _ratioX + _borderLeft);
- rect->top = (int16)MathUtil::round(rect->top * _ratioY + _borderTop);
- rect->setWidth(newWidth);
- rect->setHeight(newHeight);
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::pointFromScreen(Point32 *point) {
- point->x = (int16)(point->x / _ratioX - _borderLeft / _ratioX + _renderRect.left);
- point->y = (int16)(point->y / _ratioY - _borderTop / _ratioY + _renderRect.top);
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::pointToScreen(Point32 *point) {
- point->x = (int16)MathUtil::roundUp(point->x * _ratioX) + _borderLeft - _renderRect.left;
- point->y = (int16)MathUtil::roundUp(point->y * _ratioY) + _borderTop - _renderRect.top;
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseRenderOpenGLTexture::dumpData(const char *filename) {
- warning("BaseRenderOpenGL::DumpData(%s) - stubbed", filename); // TODO
-}
-
-BaseSurface *BaseRenderOpenGLTexture::createSurface() {
- return new BaseSurfaceOpenGLTexture(_gameRef);
-}
-
-void BaseRenderOpenGLTexture::endSaveLoad() {
- BaseRenderer::endSaveLoad();
-
- // Clear the scale-buffered tickets as we just loaded.
- RenderQueueIterator it = _renderQueue.begin();
- while (it != _renderQueue.end()) {
- RenderTicketOpenGL *ticket = *it;
- it = _renderQueue.erase(it);
- delete ticket;
- }
- // HACK: After a save the buffer will be drawn before the scripts get to update it,
- // so just skip this single frame.
- _skipThisFrame = true;
- _lastFrameIter = _renderQueue.end();
-
- _renderSurface->fillRect(Common::Rect(0, 0, _renderSurface->w, _renderSurface->h), _renderSurface->format.ARGBToColor(255, 0, 0, 0));
- g_system->copyRectToScreen((byte *)_renderSurface->getPixels(), _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
- drawRenderSurface();
- g_system->updateScreen();
-}
-
-bool BaseRenderOpenGLTexture::startSpriteBatch() {
- return STATUS_OK;
-}
-
-bool BaseRenderOpenGLTexture::endSpriteBatch() {
- return STATUS_OK;
-}
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL) && !defined(USE_GLES2)
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h b/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h
deleted file mode 100644
index a9ae25976a..0000000000
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#ifndef WINTERMUTE_BASE_RENDER_OPENGL_TEXTURE_H
-#define WINTERMUTE_BASE_RENDER_OPENGL_TEXTURE_H
-
-#include "engines/wintermute/base/gfx/base_renderer.h"
-#include "common/rect.h"
-#include "graphics/surface.h"
-#include "common/list.h"
-#include "graphics/transform_struct.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-namespace Wintermute {
-class BaseSurfaceOpenGLTexture;
-class RenderTicketOpenGL;
-/**
- * A 2D-renderer implementation for WME.
- * This renderer makes use of a "ticket"-system, where all draw-calls
- * are stored as tickets until flip() is called, and compared against the tickets
- * from last frame, to determine which calls were the same as last round
- * (i.e. in the exact same order, with the exact same arguments), and thus
- * figure out which parts of the screen need to be redrawn.
- *
- * Important concepts to handle here, is the ordered number of any ticket
- * which is called the "drawNum", every frame this starts from scratch, and
- * then the incoming tickets created from the draw-calls are checked to see whether
- * they came before, on, or after the drawNum they had last frame. Everything else
- * being equal, this information is then used to check whether the draw order changed,
- * which will then create a need for redrawing, as we draw with an alpha-channel here.
- *
- * There is also a draw path that draws without tickets, for debugging purposes,
- * as well as to accomodate situations with large enough amounts of draw calls,
- * that there will be too much overhead involved with comparing the generated tickets.
- */
-class BaseRenderOpenGLTexture : public BaseRenderer {
-public:
- BaseRenderOpenGLTexture(BaseGame *inGame);
- ~BaseRenderOpenGLTexture() override;
-
- typedef Common::List<RenderTicketOpenGL *>::iterator RenderQueueIterator;
-
- Common::String getName() const override;
-
- bool initRenderer(int width, int height, bool windowed) override;
- bool flip() override;
- bool indicatorFlip() override;
- bool forcedFlip() override;
- bool fill(byte r, byte g, byte b, Common::Rect *rect = nullptr) override;
- Graphics::PixelFormat getPixelFormat() const override;
- void fade(uint16 alpha) override;
- void fadeToColor(byte r, byte g, byte b, byte a) override;
-
- bool drawLine(int x1, int y1, int x2, int y2, uint32 color) override;
-
- BaseImage *takeScreenshot() override;
- void onWindowChange() override;
- void setWindowed(bool windowed) override;
-
- void invalidateTicket(RenderTicketOpenGL *renderTicket);
- void invalidateTicketsFromSurface(BaseSurfaceOpenGLTexture *surf);
- /**
- * Insert a new ticket into the queue, adding a dirty rect
- * @param renderTicket the ticket to be added.
- */
- void drawFromTicket(RenderTicketOpenGL *renderTicket);
- /**
- * Re-insert an existing ticket into the queue, adding a dirty rect
- * out-of-order from last draw from the ticket.
- * @param ticket iterator pointing to the ticket to be added.
- */
- void drawFromQueuedTicket(const RenderQueueIterator &ticket);
-
- bool setViewport(int left, int top, int right, int bottom) override;
- bool setViewport(Rect32 *rect) override { return BaseRenderer::setViewport(rect); }
- Rect32 getViewPort() override;
- void modTargetRect(Common::Rect *rect);
- void pointFromScreen(Point32 *point);
- void pointToScreen(Point32 *point);
-
- void dumpData(const char *filename) override;
-
- float getScaleRatioX() const override {
- return _ratioX;
- }
- float getScaleRatioY() const override {
- return _ratioY;
- }
- bool startSpriteBatch() override;
- bool endSpriteBatch() override;
- void endSaveLoad() override;
- void drawSurface(BaseSurfaceOpenGLTexture *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, Graphics::TransformStruct &transform);
- BaseSurface *createSurface() override;
-private:
- /**
- * Mark a specified rect of the screen as dirty.
- * @param rect the region to be marked as dirty
- */
- void addDirtyRect(const Common::Rect &rect);
- /**
- * Traverse the tickets that are dirty, and draw them
- */
- void drawTickets();
- // Non-dirty-rects:
- void drawFromSurface(RenderTicketOpenGL *ticket);
- // Dirty-rects:
- void drawFromSurface(RenderTicketOpenGL *ticket, Common::Rect *dstRect, Common::Rect *clipRect);
-
- void drawRenderSurface();
-
- Common::Rect *_dirtyRect;
- Common::List<RenderTicketOpenGL *> _renderQueue;
-
- bool _needsFlip;
- RenderQueueIterator _lastFrameIter;
- Common::Rect _renderRect;
- Graphics::Surface *_renderSurface;
- Graphics::Surface *_blankSurface;
-
- int _borderLeft;
- int _borderTop;
- int _borderRight;
- int _borderBottom;
-
- bool _disableDirtyRects;
- float _ratioX;
- float _ratioY;
- uint32 _clearColor;
-
- bool _skipThisFrame;
- int _lastScreenChangeID; // previous value of OSystem::getScreenChangeID()
-};
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL) && !defined(USE_GLES2)
-
-#endif
diff --git a/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.cpp b/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.cpp
deleted file mode 100644
index b95e039af9..0000000000
--- a/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.cpp
+++ /dev/null
@@ -1,490 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#include "engines/wintermute/base/base_engine.h"
-#include "engines/wintermute/base/base_file_manager.h"
-#include "engines/wintermute/base/base_game.h"
-#include "engines/wintermute/base/gfx/base_image.h"
-#include "engines/wintermute/platform_osystem.h"
-#include "graphics/transparent_surface.h"
-#include "graphics/transform_tools.h"
-#include "graphics/pixelformat.h"
-#include "graphics/surface.h"
-#include "common/stream.h"
-#include "common/system.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-#include "engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h"
-#include "engines/wintermute/base/gfx/opengl/base_render_opengl_texture.h"
-
-namespace Wintermute {
-
-//////////////////////////////////////////////////////////////////////////
-BaseSurfaceOpenGLTexture::BaseSurfaceOpenGLTexture(BaseGame *inGame) : BaseSurface(inGame) {
- _surface = new Graphics::Surface();
- _alphaMask = nullptr;
- _alphaType = Graphics::ALPHA_FULL;
- _lockPixels = nullptr;
- _lockPitch = 0;
- _loaded = false;
- _rotation = 0;
-}
-
-//////////////////////////////////////////////////////////////////////////
-BaseSurfaceOpenGLTexture::~BaseSurfaceOpenGLTexture() {
- if (_surface) {
- _surface->free();
- delete _surface;
- _surface = nullptr;
- }
-
- delete[] _alphaMask;
- _alphaMask = nullptr;
-
- _gameRef->addMem(-_width * _height * 4);
- BaseRenderOpenGLTexture *renderer = static_cast<BaseRenderOpenGLTexture *>(_gameRef->_renderer);
- renderer->invalidateTicketsFromSurface(this);
-}
-
-Graphics::AlphaType hasTransparencyTypeOpenGL(const Graphics::Surface *surf) {
- if (surf->format.bytesPerPixel != 4) {
- warning("hasTransparencyType:: non 32 bpp surface passed as argument");
- return Graphics::ALPHA_OPAQUE;
- }
- uint8 r, g, b, a;
- bool seenAlpha = false;
- bool seenFullAlpha = false;
- for (int i = 0; i < surf->h; i++) {
- if (seenFullAlpha) {
- break;
- }
- for (int j = 0; j < surf->w; j++) {
- uint32 pix = *(const uint32 *)surf->getBasePtr(j, i);
- surf->format.colorToARGB(pix, a, r, g, b);
- if (a != 255) {
- seenAlpha = true;
- if (a != 0) {
- seenFullAlpha = true;
- break;
- }
- }
- }
- }
- if (seenFullAlpha) {
- return Graphics::ALPHA_FULL;
- } else if (seenAlpha) {
- return Graphics::ALPHA_BINARY;
- } else {
- return Graphics::ALPHA_OPAQUE;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::create(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime, bool keepLoaded) {
- /* BaseRenderOpenGL *renderer = static_cast<BaseRenderOpenGL *>(_gameRef->_renderer); */
- _filename = filename;
-// const Graphics::Surface *surface = image->getSurface();
-
- 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;
- }
-
- return STATUS_OK;
-}
-
-bool BaseSurfaceOpenGLTexture::finishLoad() {
- BaseImage *image = new BaseImage();
- if (!image->loadFile(_filename)) {
- delete image;
- return false;
- }
-
- _width = image->getSurface()->w;
- _height = image->getSurface()->h;
-
- bool isSaveGameGrayscale = _filename.matchString("savegame:*g", true);
- if (isSaveGameGrayscale) {
- warning("grayscaleConversion not yet implemented");
- // FIBITMAP *newImg = FreeImage_ConvertToGreyscale(img); TODO
- }
-
- _surface->free();
- delete _surface;
-
- bool needsColorKey = false;
- bool replaceAlpha = true;
- if (image->getSurface()->format.bytesPerPixel == 1) {
- if (!image->getPalette()) {
- error("Missing palette while loading 8bit image %s", _filename.c_str());
- }
- _surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
- needsColorKey = true;
- } else {
- if (image->getSurface()->format != g_system->getScreenFormat()) {
- _surface = image->getSurface()->convertTo(g_system->getScreenFormat());
- } else {
- _surface = new Graphics::Surface();
- _surface->copyFrom(*image->getSurface());
- }
-
- if (_filename.hasSuffix(".bmp") && image->getSurface()->format.bytesPerPixel == 4) {
- // 32 bpp BMPs have nothing useful in their alpha-channel -> color-key
- needsColorKey = true;
- replaceAlpha = false;
- } else if (image->getSurface()->format.aBits() == 0) {
- needsColorKey = true;
- }
- }
-
- if (needsColorKey) {
- Graphics::TransparentSurface trans(*_surface);
- trans.applyColorKey(_ckRed, _ckGreen, _ckBlue, replaceAlpha);
- }
-
- _alphaType = hasTransparencyTypeOpenGL(_surface);
- _valid = true;
-
- _gameRef->addMem(_width * _height * 4);
-
- delete image;
-
- // Bug #6572 WME: Rosemary - Sprite flaw on going upwards
- // Some Rosemary sprites have non-fully transparent pixels
- // In original WME it wasn't seen because sprites were downscaled
- // Let's set alpha to 0 if it is smaller then some treshold
- if (BaseEngine::instance().getGameId() == "rosemary" && _filename.hasPrefix("actors") && _surface->format.bytesPerPixel == 4) {
- uint8 treshold = 16;
- for (int x = 0; x < _surface->w; x++) {
- for (int y = 0; y < _surface->h; y++) {
- uint32 pixel = getPixelAt(_surface, x, y);
- uint8 r, g, b, a;
- _surface->format.colorToARGB(pixel, a, r, g, b);
- if (a > 0 && a < treshold) {
- uint32 *p = (uint32 *)_surface->getBasePtr(x, y);
- *p = _surface->format.ARGBToColor(0, 0, 0, 0);
- }
- }
- }
- }
-
- _loaded = true;
-
- return true;
-}
-
-//////////////////////////////////////////////////////////////////////////
-void BaseSurfaceOpenGLTexture::genAlphaMask(Graphics::Surface *surface) {
- warning("BaseSurfaceOpenGL::GenAlphaMask - Not ported yet");
- return;
- // TODO: Reimplement this
- delete[] _alphaMask;
- _alphaMask = nullptr;
- if (!surface) {
- return;
- }
-
- bool hasColorKey;
- /* uint32 colorKey; */
- uint8 ckRed, ckGreen, ckBlue;
- /* if (SDL_GetColorKey(surface, &colorKey) == 0) {
- hasColorKey = true;
- SDL_GetRGB(colorKey, surface->format, &ckRed, &ckGreen, &ckBlue);
- } else hasColorKey = false;
- */
- _alphaMask = new byte[surface->w * surface->h];
-
- bool hasTransparency = false;
- for (int y = 0; y < surface->h; y++) {
- for (int x = 0; x < surface->w; x++) {
- uint32 pixel = getPixelAt(surface, x, y);
-
- uint8 r, g, b, a;
- surface->format.colorToARGB(pixel, a, r, g, b);
- //SDL_GetRGBA(pixel, surface->format, &r, &g, &b, &a);
-
- if (hasColorKey && r == ckRed && g == ckGreen && b == ckBlue) {
- a = 0;
- }
-
- _alphaMask[y * surface->w + x] = a;
- if (a < 255) {
- hasTransparency = true;
- }
- }
- }
-
- if (!hasTransparency) {
- delete[] _alphaMask;
- _alphaMask = nullptr;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////
-uint32 BaseSurfaceOpenGLTexture::getPixelAt(Graphics::Surface *surface, int x, int y) {
- int bpp = surface->format.bytesPerPixel;
- /* Here p is the address to the pixel we want to retrieve */
- uint8 *p = (uint8 *)surface->getBasePtr(x, y);
-
- switch (bpp) {
- case 1:
- return *p;
- break;
-
- case 2:
- return *(uint16 *)p;
- break;
-
- case 3:
-#ifdef SCUMM_BIG_ENDIAN
- // if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
- return p[0] << 16 | p[1] << 8 | p[2];
-#else
- //else
- return p[0] | p[1] << 8 | p[2] << 16;
-#endif
- break;
-
- case 4:
- return *(uint32 *)p;
- break;
-
- default:
- return 0; /* shouldn't happen, but avoids warnings */
- }
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::create(int width, int height) {
- _width = width;
- _height = height;
-
- _gameRef->addMem(_width * _height * 4);
-
- _valid = true;
-
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::isTransparentAt(int x, int y) {
- return isTransparentAtLite(x, y);
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::isTransparentAtLite(int x, int y) {
- if (x < 0 || x >= _surface->w || y < 0 || y >= _surface->h) {
- return true;
- }
-
- if (_surface->format.bytesPerPixel == 4) {
- uint32 pixel = *(uint32 *)_surface->getBasePtr(x, y);
- uint8 r, g, b, a;
- _surface->format.colorToARGB(pixel, a, r, g, b);
- if (a <= 128) {
- return true;
- } else {
- return false;
- }
- }
-
- return false;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::startPixelOp() {
- //SDL_LockTexture(_texture, nullptr, &_lockPixels, &_lockPitch);
- // Any pixel-op makes the caching useless:
- BaseRenderOpenGLTexture *renderer = static_cast<BaseRenderOpenGLTexture *>(_gameRef->_renderer);
- renderer->invalidateTicketsFromSurface(this);
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::endPixelOp() {
- //SDL_UnlockTexture(_texture);
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::display(int x, int y, Rect32 rect, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
- _rotation = 0;
- return drawSprite(x, y, &rect, nullptr, Graphics::TransformStruct(Graphics::kDefaultZoomX, Graphics::kDefaultZoomY, mirrorX, mirrorY));
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayTrans(int x, int y, Rect32 rect, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
- _rotation = 0;
- return drawSprite(x, y, &rect, nullptr, Graphics::TransformStruct(Graphics::kDefaultZoomX, Graphics::kDefaultZoomY, blendMode, alpha, mirrorX, mirrorY));
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayTransOffset(int x, int y, Rect32 rect, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) {
- _rotation = 0;
- return drawSprite(x, y, &rect, nullptr, Graphics::TransformStruct(Graphics::kDefaultZoomX, Graphics::kDefaultZoomY, Graphics::kDefaultAngle, Graphics::kDefaultHotspotX, Graphics::kDefaultHotspotY, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY));
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
- _rotation = 0;
- return drawSprite(x, y, &rect, nullptr, Graphics::TransformStruct((int32)zoomX, (int32)zoomY, blendMode, alpha, mirrorX, mirrorY));
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, bool transparent, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) {
- _rotation = 0;
- Graphics::TransformStruct transform;
- if (transparent) {
- transform = Graphics::TransformStruct((int32)zoomX, (int32)zoomY, Graphics::kDefaultAngle, Graphics::kDefaultHotspotX, Graphics::kDefaultHotspotY, blendMode, alpha, mirrorX, mirrorY);
- } else {
- transform = Graphics::TransformStruct((int32)zoomX, (int32)zoomY, mirrorX, mirrorY);
- }
- return drawSprite(x, y, &rect, nullptr, transform);
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const Graphics::TransformStruct &transform) {
- _rotation = (uint32)transform._angle;
- if (transform._angle < 0.0f) {
- warning("Negative rotation: %d %d", transform._angle, _rotation);
- _rotation = (uint32)(360.0f + transform._angle);
- warning("Negative post rotation: %d %d", transform._angle, _rotation);
- }
- return drawSprite(x, y, &rect, &newRect, transform);
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::displayTiled(int x, int y, Rect32 rect, int numTimesX, int numTimesY) {
- assert(numTimesX > 0 && numTimesY > 0);
- Graphics::TransformStruct transform(numTimesX, numTimesY);
- return drawSprite(x, y, &rect, nullptr, transform);
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseSurfaceOpenGLTexture::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, Graphics::TransformStruct transform) {
- BaseRenderOpenGLTexture *renderer = static_cast<BaseRenderOpenGLTexture *>(_gameRef->_renderer);
-
- if (!_loaded) {
- finishLoad();
- }
-
- if (renderer->_forceAlphaColor != 0) {
- transform._rgbaMod = renderer->_forceAlphaColor;
- }
-
- // TODO: This _might_ miss the intended behaviour by 1 in each direction
- // But I think it fits the model used in Wintermute.
- Common::Rect srcRect;
- srcRect.left = rect->left;
- srcRect.top = rect->top;
- srcRect.setWidth(rect->right - rect->left);
- srcRect.setHeight(rect->bottom - rect->top);
-
- Common::Rect position;
-
- if (newRect) {
- position.top = y;
- position.left = x;
- position.setWidth(newRect->width());
- position.setHeight(newRect->height());
- } else {
-
- Common::Rect r;
- r.top = 0;
- r.left = 0;
- r.setWidth(rect->width());
- r.setHeight(rect->height());
-
- r = Graphics::TransformTools::newRect(r, transform, 0);
-
- position.top = r.top + y + transform._offset.y;
- position.left = r.left + x + transform._offset.x;
- position.setWidth(r.width() * transform._numTimesX);
- position.setHeight(r.height() * transform._numTimesY);
- }
- renderer->modTargetRect(&position);
-
- // TODO: This actually requires us to have the SAME source-offsets every time,
- // But no checking is in place for that yet.
-
- // Optimize by not doing alpha-blits if we lack alpha
- // If angle is not 0, then transparent regions are added near the corners
- if (_alphaType == Graphics::ALPHA_OPAQUE && transform._angle == 0) {
- transform._alphaDisable = true;
- }
-
- renderer->drawSurface(this, _surface, &srcRect, &position, transform);
- return STATUS_OK;
-}
-
-bool BaseSurfaceOpenGLTexture::putSurface(const Graphics::Surface &surface, bool hasAlpha) {
- _loaded = true;
- if (surface.format == _surface->format && surface.pitch == _surface->pitch && surface.h == _surface->h) {
- const byte *src = (const byte *)surface.getBasePtr(0, 0);
- byte *dst = (byte *)_surface->getBasePtr(0, 0);
- memcpy(dst, src, surface.pitch * surface.h);
- } else {
- _surface->free();
- _surface->copyFrom(surface);
- }
- if (hasAlpha) {
- _alphaType = Graphics::ALPHA_FULL;
- } else {
- _alphaType = Graphics::ALPHA_OPAQUE;
- }
- BaseRenderOpenGLTexture *renderer = static_cast<BaseRenderOpenGLTexture *>(_gameRef->_renderer);
- renderer->invalidateTicketsFromSurface(this);
-
- return STATUS_OK;
-}
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL_GAME) && !defined(USE_GLES2)
diff --git a/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h b/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h
deleted file mode 100644
index 4affea268e..0000000000
--- a/engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#ifndef WINTERMUTE_BASE_SURFACE_OPENGL_TEXTURE_H
-#define WINTERMUTE_BASE_SURFACE_OPENGL_TEXTURE_H
-
-#include "graphics/surface.h"
-#include "graphics/transparent_surface.h"
-#include "engines/wintermute/base/gfx/base_surface.h"
-#include "common/list.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-namespace Wintermute {
-struct TransparentSurface;
-class BaseImage;
-class BaseSurfaceOpenGLTexture : public BaseSurface {
-public:
- BaseSurfaceOpenGLTexture(BaseGame *inGame);
- ~BaseSurfaceOpenGLTexture() override;
-
- bool create(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime = -1, bool keepLoaded = false) override;
- bool create(int width, int height) override;
-
- bool isTransparentAt(int x, int y) override;
- bool isTransparentAtLite(int x, int y) override;
-
- bool startPixelOp() override;
- bool endPixelOp() override;
-
-
- bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = Graphics::kDefaultRgbaMod, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
- bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = Graphics::kDefaultRgbaMod, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
- bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = Graphics::kDefaultRgbaMod, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override;
- bool display(int x, int y, Rect32 rect, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
- bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = Graphics::kDefaultRgbaMod, bool transparent = false, Graphics::TSpriteBlendMode blendMode = Graphics::BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override;
- bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const Graphics::TransformStruct &transform) override;
- bool displayTiled(int x, int y, Rect32 rect, int numTimesX, int numTimesY) override;
- bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override;
- /* static unsigned DLL_CALLCONV ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
- static int DLL_CALLCONV SeekProc(fi_handle handle, long offset, int origin);
- static long DLL_CALLCONV TellProc(fi_handle handle);*/
- int getWidth() override {
- if (!_loaded) {
- finishLoad();
- }
- if (_surface) {
- return _surface->w;
- }
- return _width;
- }
- int getHeight() override {
- if (!_loaded) {
- finishLoad();
- }
- if (_surface) {
- return _surface->h;
- }
- return _height;
- }
- bool getPixel(int x, int y, byte *r, byte *g, byte *b, byte *a) override {
- if (!_loaded) {
- finishLoad();
- }
- if (_surface) {
- uint32 pixel = getPixelAt(_surface, x, y);
- _surface->format.colorToARGB(pixel, *a, *r, *g, *b);
- return STATUS_OK;
- }
- return STATUS_FAILED;
- }
-
- Graphics::AlphaType getAlphaType() const { return _alphaType; }
-private:
- Graphics::Surface *_surface;
- bool _loaded;
- bool finishLoad();
- bool drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, Graphics::TransformStruct transformStruct);
- void genAlphaMask(Graphics::Surface *surface);
- uint32 getPixelAt(Graphics::Surface *surface, int x, int y);
-
- uint32 _rotation;
- Graphics::AlphaType _alphaType;
- void *_lockPixels;
- int _lockPitch;
- byte *_alphaMask;
-};
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL_GAME) && !defined(USE_GLES2)
-
-#endif
diff --git a/engines/wintermute/base/gfx/opengl/render_ticket.cpp b/engines/wintermute/base/gfx/opengl/render_ticket.cpp
deleted file mode 100644
index 0786cf2229..0000000000
--- a/engines/wintermute/base/gfx/opengl/render_ticket.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-
-#include "engines/wintermute/base/base_game.h"
-#include "graphics/transform_tools.h"
-#include "common/textconsole.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-#include "engines/wintermute/base/gfx/opengl/render_ticket.h"
-#include "engines/wintermute/base/gfx/opengl/base_surface_opengl_texture.h"
-
-namespace Wintermute {
-
-RenderTicketOpenGL::RenderTicketOpenGL(BaseSurfaceOpenGLTexture *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, Graphics::TransformStruct transform) :
- _owner(owner),
- _srcRect(*srcRect),
- _dstRect(*dstRect),
- _isValid(true),
- _wantsDraw(true),
- _transform(transform) {
- if (surf) {
- _surface = new Graphics::Surface();
- _surface->create((uint16)srcRect->width(), (uint16)srcRect->height(), surf->format);
- assert(_surface->format.bytesPerPixel == 4);
- // Get a clipped copy of the surface
- for (int i = 0; i < _surface->h; i++) {
- memcpy(_surface->getBasePtr(0, i), surf->getBasePtr(srcRect->left, srcRect->top + i), srcRect->width() * _surface->format.bytesPerPixel);
- }
- // Then scale it if necessary
- //
- // NB: The numTimesX/numTimesY properties don't yet mix well with
- // scaling and rotation, but there is no need for that functionality at
- // the moment.
- // NB: Mirroring and rotation are probably done in the wrong order.
- // (Mirroring should most likely be done before rotation. See also
- // TransformTools.)
- if (_transform._angle != Graphics::kDefaultAngle) {
- Graphics::TransparentSurface src(*_surface, false);
- Graphics::Surface *temp;
- if (owner->_gameRef->getBilinearFiltering()) {
- temp = src.rotoscaleT<Graphics::FILTER_BILINEAR>(transform);
- } else {
- temp = src.rotoscaleT<Graphics::FILTER_NEAREST>(transform);
- }
- _surface->free();
- delete _surface;
- _surface = temp;
- } else if ((dstRect->width() != srcRect->width() ||
- dstRect->height() != srcRect->height()) &&
- _transform._numTimesX * _transform._numTimesY == 1) {
- Graphics::Surface *temp = _surface->scale(dstRect->width(), dstRect->height(), owner->_gameRef->getBilinearFiltering());
- _surface->free();
- delete _surface;
- _surface = temp;
- }
- } else {
- _surface = nullptr;
- }
-}
-
-RenderTicketOpenGL::~RenderTicketOpenGL() {
- if (_surface) {
- _surface->free();
- delete _surface;
- }
-}
-
-bool RenderTicketOpenGL::operator==(const RenderTicketOpenGL &t) const {
- if ((t._owner != _owner) ||
- (t._transform != _transform) ||
- (t._dstRect != _dstRect) ||
- (t._srcRect != _srcRect)
- ) {
- return false;
- }
- return true;
-}
-
-// Replacement for SDL2's SDL_RenderCopy
-void RenderTicketOpenGL::drawToSurface(Graphics::Surface *_targetSurface) const {
- Graphics::Surface* converted_surface = getSurface()->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
- Graphics::TransparentSurface src(*converted_surface, false);
-
- Common::Rect clipRect;
- clipRect.setWidth(getSurface()->w);
- clipRect.setHeight(getSurface()->h);
-
- if (_owner) {
- if (_transform._alphaDisable) {
- src.setAlphaMode(Graphics::ALPHA_OPAQUE);
- } else if (_transform._angle) {
- src.setAlphaMode(Graphics::ALPHA_FULL);
- } else {
- src.setAlphaMode(_owner->getAlphaType());
- }
- }
-
- int y = _dstRect.top;
- int w = _dstRect.width() / _transform._numTimesX;
- int h = _dstRect.height() / _transform._numTimesY;
-
- for (int ry = 0; ry < _transform._numTimesY; ++ry) {
- int x = _dstRect.left;
- for (int rx = 0; rx < _transform._numTimesX; ++rx) {
- src.blit(*_targetSurface, x, y, _transform._flip, &clipRect, _transform._rgbaMod, clipRect.width(), clipRect.height());
- x += w;
- }
- y += h;
- }
-
- delete converted_surface;
-}
-
-void RenderTicketOpenGL::drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect) const {
- Graphics::Surface* converted_surface = getSurface()->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
- Graphics::TransparentSurface src(*converted_surface, false);
- bool doDelete = false;
- if (!clipRect) {
- doDelete = true;
- clipRect = new Common::Rect();
- clipRect->setWidth(getSurface()->w * _transform._numTimesX);
- clipRect->setHeight(getSurface()->h * _transform._numTimesY);
- }
-
- if (_owner) {
- if (_transform._alphaDisable) {
- src.setAlphaMode(Graphics::ALPHA_OPAQUE);
- } else if (_transform._angle) {
- src.setAlphaMode(Graphics::ALPHA_FULL);
- } else {
- src.setAlphaMode(_owner->getAlphaType());
- }
- }
-
- if (_transform._numTimesX * _transform._numTimesY == 1) {
-
- src.blit(*_targetSurface, dstRect->left, dstRect->top, _transform._flip, clipRect, _transform._rgbaMod, clipRect->width(), clipRect->height(), _transform._blendMode);
-
- } else {
-
- // clipRect is a subrect of the full numTimesX*numTimesY rect
- Common::Rect subRect;
-
- int y = 0;
- int w = getSurface()->w;
- int h = getSurface()->h;
- assert(w == _dstRect.width() / _transform._numTimesX);
- assert(h == _dstRect.height() / _transform._numTimesY);
-
- int basex = dstRect->left - clipRect->left;
- int basey = dstRect->top - clipRect->top;
-
- for (int ry = 0; ry < _transform._numTimesY; ++ry) {
- int x = 0;
- for (int rx = 0; rx < _transform._numTimesX; ++rx) {
-
- subRect.left = x;
- subRect.top = y;
- subRect.setWidth(w);
- subRect.setHeight(h);
-
- if (subRect.intersects(*clipRect)) {
- subRect.clip(*clipRect);
- subRect.translate(-x, -y);
- src.blit(*_targetSurface, basex + x + subRect.left, basey + y + subRect.top, _transform._flip, &subRect, _transform._rgbaMod, subRect.width(), subRect.height(), _transform._blendMode);
-
- }
-
- x += w;
- }
- y += h;
- }
- }
-
- if (doDelete) {
- delete clipRect;
- }
-
- delete converted_surface;
-}
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL_GAME) && !defined(USE_GLES2)
diff --git a/engines/wintermute/base/gfx/opengl/render_ticket.h b/engines/wintermute/base/gfx/opengl/render_ticket.h
deleted file mode 100644
index 5452f56c0f..0000000000
--- a/engines/wintermute/base/gfx/opengl/render_ticket.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* 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 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.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#ifndef WINTERMUTE_RENDER_TICKET_H
-#define WINTERMUTE_RENDER_TICKET_H
-
-#include "graphics/transparent_surface.h"
-#include "graphics/surface.h"
-#include "common/rect.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) || defined(USE_GLES2)
-
-namespace Wintermute {
-
-class BaseSurfaceOpenGLTexture;
-/**
- * A single RenderTicket.
- * A render ticket is a collection of the data and draw specifications made
- * for a single draw-call in the OSystem-backend for WME. The ticket additionally
- * holds the order in which this call was made, so that it can be detected if
- * the same call is done in the following frame. Thus allowing us to potentially
- * skip drawing the same region again, unless anything has changed. Since a surface
- * can have a potentially large amount of draw-calls made to it, at varying rotation,
- * zoom, and crop-levels we also need to hold a copy of the necessary data.
- * (Video-surfaces may even change their data). The promise that is made when a ticket
- * is created is that what the state was of the surface at THAT point, is what will end
- * up on screen at flip() time.
- */
-class RenderTicketOpenGL {
-public:
- RenderTicketOpenGL(BaseSurfaceOpenGLTexture *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, Graphics::TransformStruct transform);
- RenderTicketOpenGL() : _isValid(true), _wantsDraw(false), _transform(Graphics::TransformStruct()) {}
- ~RenderTicketOpenGL();
- const Graphics::Surface *getSurface() const { return _surface; }
- // Non-dirty-rects:
- void drawToSurface(Graphics::Surface *_targetSurface) const;
- // Dirty-rects:
- void drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect) const;
-
- Common::Rect _dstRect;
-
- bool _isValid;
- bool _wantsDraw;
-
- Graphics::TransformStruct _transform;
-
- BaseSurfaceOpenGLTexture *_owner;
- bool operator==(const RenderTicketOpenGL &a) const;
- const Common::Rect *getSrcRect() const { return &_srcRect; }
-private:
- Graphics::Surface *_surface;
- Common::Rect _srcRect;
-};
-
-} // End of namespace Wintermute
-
-#endif // defined(USE_OPENGL_GAME) && !defined(USE_GLES2)
-
-#endif
diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk
index 3f429fcd4f..4c3b17c324 100644
--- a/engines/wintermute/module.mk
+++ b/engines/wintermute/module.mk
@@ -160,12 +160,9 @@ MODULE_OBJS += \
ad/ad_waypoint_group3d.o \
base/gfx/base_renderer3d.o \
base/gfx/shadow_volume.o \
- base/gfx/opengl/base_surface_opengl_texture.o \
- base/gfx/opengl/base_render_opengl_texture.o \
base/gfx/opengl/base_surface_opengl3d.o \
base/gfx/opengl/base_render_opengl3d.o \
base/gfx/opengl/base_render_opengl3d_shader.o \
- base/gfx/opengl/render_ticket.o \
base/gfx/opengl/meshx_opengl.o \
base/gfx/opengl/meshx_opengl_shader.o \
base/gfx/opengl/mesh3ds_opengl.o \
More information about the Scummvm-git-logs
mailing list