From 3b9f9804ee751f36aaff2d5d593c56f478f62425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Ko=C5=82odziejski?= Date: Wed, 8 Dec 2021 14:52:18 +0100 Subject: [PATCH] TINYGL: Rearrange access to TinyGL --- engines/grim/gfx_tinygl.cpp | 1 - engines/grim/gfx_tinygl.h | 2 +- engines/myst3/gfx_tinygl.cpp | 2 +- engines/myst3/gfx_tinygl.h | 4 +- engines/myst3/gfx_tinygl_texture.cpp | 3 +- engines/myst3/gfx_tinygl_texture.h | 6 +- engines/playground3d/gfx_tinygl.cpp | 2 +- engines/playground3d/gfx_tinygl.h | 2 +- engines/stark/gfx/tinygl.cpp | 2 +- engines/stark/gfx/tinygl.h | 3 +- engines/stark/gfx/tinyglactor.cpp | 1 - engines/stark/gfx/tinyglactor.h | 2 +- engines/stark/gfx/tinyglbitmap.cpp | 1 - engines/stark/gfx/tinyglbitmap.h | 2 +- engines/stark/gfx/tinyglfade.cpp | 1 - engines/stark/gfx/tinyglfade.h | 2 +- engines/stark/gfx/tinyglprop.cpp | 1 - engines/stark/gfx/tinyglprop.h | 2 +- engines/stark/gfx/tinyglsurface.cpp | 2 +- engines/stark/gfx/tinyglsurface.h | 3 +- engines/stark/gfx/tinygltexture.cpp | 1 - engines/stark/gfx/tinygltexture.h | 2 +- graphics/tinygl/gl.h | 8 +- graphics/tinygl/tinygl.h | 41 +++++++ graphics/tinygl/zblit.cpp | 7 +- graphics/tinygl/zblit.h | 142 +---------------------- graphics/tinygl/zblit_public.h | 164 +++++++++++++++++++++++++++ graphics/tinygl/zbuffer.h | 136 ++++++++++++---------- graphics/tinygl/zdirtyrect.cpp | 7 +- graphics/tinygl/zdirtyrect.h | 13 +-- graphics/tinygl/zgl.h | 9 +- graphics/tinygl/ztriangle.cpp | 24 ++-- 32 files changed, 328 insertions(+), 270 deletions(-) create mode 100644 graphics/tinygl/tinygl.h create mode 100644 graphics/tinygl/zblit_public.h diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index e2fed2e7c44..8ddea296ca3 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -829,7 +829,6 @@ void GfxTinyGL::disableLights() { } void GfxTinyGL::setupLight(Light *light, int lightId) { - assert(lightId < T_MAX_LIGHTS); tglEnable(TGL_LIGHTING); float lightColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f }; diff --git a/engines/grim/gfx_tinygl.h b/engines/grim/gfx_tinygl.h index 9f2a10f9c0d..9b3b98ff4ba 100644 --- a/engines/grim/gfx_tinygl.h +++ b/engines/grim/gfx_tinygl.h @@ -25,7 +25,7 @@ #include "engines/grim/gfx_base.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" namespace Graphics { struct Surface; diff --git a/engines/myst3/gfx_tinygl.cpp b/engines/myst3/gfx_tinygl.cpp index b4ceaecdc20..dfa6e51d6a7 100644 --- a/engines/myst3/gfx_tinygl.cpp +++ b/engines/myst3/gfx_tinygl.cpp @@ -25,6 +25,7 @@ #include "common/textconsole.h" #include "graphics/surface.h" +#include "graphics/tinygl/tinygl.h" #include "math/vector2d.h" #include "math/glmath.h" @@ -32,7 +33,6 @@ #include "engines/myst3/gfx.h" #include "engines/myst3/gfx_tinygl.h" #include "engines/myst3/gfx_tinygl_texture.h" -#include "graphics/tinygl/zblit.h" namespace Myst3 { diff --git a/engines/myst3/gfx_tinygl.h b/engines/myst3/gfx_tinygl.h index 49edd131c27..299b001fb05 100644 --- a/engines/myst3/gfx_tinygl.h +++ b/engines/myst3/gfx_tinygl.h @@ -25,10 +25,12 @@ #include "common/rect.h" #include "common/system.h" + #include "math/vector3d.h" #include "engines/myst3/gfx.h" -#include "graphics/tinygl/zgl.h" + +#include "graphics/tinygl/tinygl.h" namespace Myst3 { diff --git a/engines/myst3/gfx_tinygl_texture.cpp b/engines/myst3/gfx_tinygl_texture.cpp index 0d647c1047d..8590e599fc9 100644 --- a/engines/myst3/gfx_tinygl_texture.cpp +++ b/engines/myst3/gfx_tinygl_texture.cpp @@ -21,7 +21,8 @@ */ #include "engines/myst3/gfx_tinygl_texture.h" -#include "graphics/tinygl/zblit.h" + +#include "graphics/tinygl/tinygl.h" namespace Myst3 { diff --git a/engines/myst3/gfx_tinygl_texture.h b/engines/myst3/gfx_tinygl_texture.h index 683e46b0fe3..583d5596472 100644 --- a/engines/myst3/gfx_tinygl_texture.h +++ b/engines/myst3/gfx_tinygl_texture.h @@ -23,12 +23,12 @@ #ifndef GFX_TINYGL_TEXTURE_H #define GFX_TINYGL_TEXTURE_H -#include "graphics/surface.h" -#include "graphics/tinygl/zgl.h" #include "common/textconsole.h" +#include "graphics/surface.h" +#include "graphics/tinygl/tinygl.h" + #include "engines/myst3/gfx.h" -#include "graphics/tinygl/zblit.h" namespace Myst3 { diff --git a/engines/playground3d/gfx_tinygl.cpp b/engines/playground3d/gfx_tinygl.cpp index 3bf9a07b819..002231dd170 100644 --- a/engines/playground3d/gfx_tinygl.cpp +++ b/engines/playground3d/gfx_tinygl.cpp @@ -25,7 +25,7 @@ #include "common/textconsole.h" #include "graphics/surface.h" -#include "graphics/tinygl/zblit.h" +#include "graphics/tinygl/tinygl.h" #include "math/vector2d.h" #include "math/glmath.h" diff --git a/engines/playground3d/gfx_tinygl.h b/engines/playground3d/gfx_tinygl.h index fbc19da41ea..0959631b589 100644 --- a/engines/playground3d/gfx_tinygl.h +++ b/engines/playground3d/gfx_tinygl.h @@ -28,7 +28,7 @@ #include "math/vector3d.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" #include "engines/playground3d/gfx.h" diff --git a/engines/stark/gfx/tinygl.cpp b/engines/stark/gfx/tinygl.cpp index bdd9c1bdb15..242ed794e48 100644 --- a/engines/stark/gfx/tinygl.cpp +++ b/engines/stark/gfx/tinygl.cpp @@ -20,13 +20,13 @@ * */ -#include "engines/stark/gfx/tinygl.h" #include "common/system.h" #include "common/config-manager.h" #include "math/matrix4.h" +#include "engines/stark/gfx/tinygl.h" #include "engines/stark/gfx/tinyglactor.h" #include "engines/stark/gfx/tinyglprop.h" #include "engines/stark/gfx/tinyglsurface.h" diff --git a/engines/stark/gfx/tinygl.h b/engines/stark/gfx/tinygl.h index 731deb6a3ca..6384c571aa6 100644 --- a/engines/stark/gfx/tinygl.h +++ b/engines/stark/gfx/tinygl.h @@ -24,12 +24,13 @@ #define STARK_GFX_TINYGL_H #include "common/system.h" + #include "math/vector3d.h" #include "engines/stark/gfx/driver.h" #include "engines/stark/gfx/renderentry.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" namespace Stark { namespace Gfx { diff --git a/engines/stark/gfx/tinyglactor.cpp b/engines/stark/gfx/tinyglactor.cpp index dae8900b20c..9940214bdda 100644 --- a/engines/stark/gfx/tinyglactor.cpp +++ b/engines/stark/gfx/tinyglactor.cpp @@ -21,7 +21,6 @@ */ #include "engines/stark/gfx/tinyglactor.h" - #include "engines/stark/model/model.h" #include "engines/stark/model/animhandler.h" #include "engines/stark/scene.h" diff --git a/engines/stark/gfx/tinyglactor.h b/engines/stark/gfx/tinyglactor.h index 1967a8c1faa..65bb8190872 100644 --- a/engines/stark/gfx/tinyglactor.h +++ b/engines/stark/gfx/tinyglactor.h @@ -27,7 +27,7 @@ #include "engines/stark/visual/actor.h" #include "engines/stark/gfx/tinygl.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" #include "common/hashmap.h" #include "common/hash-ptr.h" diff --git a/engines/stark/gfx/tinyglbitmap.cpp b/engines/stark/gfx/tinyglbitmap.cpp index b68cc768fa8..e1d98a79c1f 100644 --- a/engines/stark/gfx/tinyglbitmap.cpp +++ b/engines/stark/gfx/tinyglbitmap.cpp @@ -21,7 +21,6 @@ */ #include "engines/stark/gfx/tinyglbitmap.h" - #include "engines/stark/gfx/driver.h" #include "graphics/surface.h" diff --git a/engines/stark/gfx/tinyglbitmap.h b/engines/stark/gfx/tinyglbitmap.h index 754513ede23..1e02de6567f 100644 --- a/engines/stark/gfx/tinyglbitmap.h +++ b/engines/stark/gfx/tinyglbitmap.h @@ -25,7 +25,7 @@ #include "engines/stark/gfx/texture.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" namespace Stark { namespace Gfx { diff --git a/engines/stark/gfx/tinyglfade.cpp b/engines/stark/gfx/tinyglfade.cpp index a4b827d43bb..4972e75b5b6 100644 --- a/engines/stark/gfx/tinyglfade.cpp +++ b/engines/stark/gfx/tinyglfade.cpp @@ -21,7 +21,6 @@ */ #include "engines/stark/gfx/tinyglfade.h" - #include "engines/stark/gfx/tinygl.h" namespace Stark { diff --git a/engines/stark/gfx/tinyglfade.h b/engines/stark/gfx/tinyglfade.h index df3b6f21e94..ff9c9ea1bb9 100644 --- a/engines/stark/gfx/tinyglfade.h +++ b/engines/stark/gfx/tinyglfade.h @@ -25,7 +25,7 @@ #include "engines/stark/gfx/faderenderer.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" namespace Stark { namespace Gfx { diff --git a/engines/stark/gfx/tinyglprop.cpp b/engines/stark/gfx/tinyglprop.cpp index 423df81ea36..7694a86eb7c 100644 --- a/engines/stark/gfx/tinyglprop.cpp +++ b/engines/stark/gfx/tinyglprop.cpp @@ -21,7 +21,6 @@ */ #include "engines/stark/gfx/tinyglprop.h" - #include "engines/stark/gfx/texture.h" #include "engines/stark/formats/biffmesh.h" #include "engines/stark/scene.h" diff --git a/engines/stark/gfx/tinyglprop.h b/engines/stark/gfx/tinyglprop.h index 2c3a973c4e2..ca75bf67423 100644 --- a/engines/stark/gfx/tinyglprop.h +++ b/engines/stark/gfx/tinyglprop.h @@ -27,7 +27,7 @@ #include "engines/stark/visual/prop.h" #include "engines/stark/gfx/tinygl.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" #include "common/hashmap.h" #include "common/hash-ptr.h" diff --git a/engines/stark/gfx/tinyglsurface.cpp b/engines/stark/gfx/tinyglsurface.cpp index 5752862deaf..487205f7eff 100644 --- a/engines/stark/gfx/tinyglsurface.cpp +++ b/engines/stark/gfx/tinyglsurface.cpp @@ -24,7 +24,7 @@ #include "engines/stark/gfx/tinyglbitmap.h" #include "engines/stark/gfx/texture.h" -#include "graphics/tinygl/zblit.h" +#include "graphics/tinygl/tinygl.h" namespace Stark { namespace Gfx { diff --git a/engines/stark/gfx/tinyglsurface.h b/engines/stark/gfx/tinyglsurface.h index 38d9c0e26fb..671be90ae50 100644 --- a/engines/stark/gfx/tinyglsurface.h +++ b/engines/stark/gfx/tinyglsurface.h @@ -26,8 +26,7 @@ #include "engines/stark/gfx/surfacerenderer.h" #include "engines/stark/gfx/tinygl.h" -#include "graphics/tinygl/zgl.h" -#include "graphics/tinygl/zblit.h" +#include "graphics/tinygl/tinygl.h" #include "math/vector2d.h" diff --git a/engines/stark/gfx/tinygltexture.cpp b/engines/stark/gfx/tinygltexture.cpp index e2b64c213d6..571510a046a 100644 --- a/engines/stark/gfx/tinygltexture.cpp +++ b/engines/stark/gfx/tinygltexture.cpp @@ -21,7 +21,6 @@ */ #include "engines/stark/gfx/tinygltexture.h" - #include "engines/stark/gfx/driver.h" #include "graphics/surface.h" diff --git a/engines/stark/gfx/tinygltexture.h b/engines/stark/gfx/tinygltexture.h index 387c75339b1..37156417b20 100644 --- a/engines/stark/gfx/tinygltexture.h +++ b/engines/stark/gfx/tinygltexture.h @@ -25,7 +25,7 @@ #include "engines/stark/gfx/texture.h" -#include "graphics/tinygl/zgl.h" +#include "graphics/tinygl/tinygl.h" namespace Stark { namespace Gfx { diff --git a/graphics/tinygl/gl.h b/graphics/tinygl/gl.h index 9c5d221ff9b..0c6214fc8fc 100644 --- a/graphics/tinygl/gl.h +++ b/graphics/tinygl/gl.h @@ -849,16 +849,10 @@ void tglTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoi // polygon offset void tglPolygonOffset(TGLfloat factor, TGLfloat units); -// custom extension +// custom extensions void tglSetShadowMaskBuf(unsigned char *buf); void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b); void tglEnableDirtyRects(bool enable); void tglDebug(int mode); -namespace TinyGL { - -void presentBuffer(); - -} // end of namespace TinyGL - #endif diff --git a/graphics/tinygl/tinygl.h b/graphics/tinygl/tinygl.h new file mode 100644 index 00000000000..b4103c883f6 --- /dev/null +++ b/graphics/tinygl/tinygl.h @@ -0,0 +1,41 @@ +/* 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. + * + */ + +#ifndef GRAPHICS_TINYGL_H +#define GRAPHICS_TINYGL_H + +#include "graphics/pixelformat.h" +#include "graphics/surface.h" +#include "graphics/tinygl/gl.h" +#include "graphics/tinygl/zblit_public.h" + +namespace TinyGL { + +void createContext(int screenW, int screenH, Graphics::PixelFormat pixelFormat, int textureSize, bool dirtyRectsEnable = true); +void destroyContext(); +void presentBuffer(); +void getSurfaceRef(Graphics::Surface &surface); +Graphics::Surface *copyToBuffer(const Graphics::PixelFormat &dstFormat); + +} // end of namespace TinyGL + +#endif diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp index ca2d50801c6..d29646679a3 100644 --- a/graphics/tinygl/zblit.cpp +++ b/graphics/tinygl/zblit.cpp @@ -20,12 +20,6 @@ * */ -/* - * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard, - * which is licensed under the zlib-license (see LICENSE). - * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later). - */ - #include "common/array.h" #include "graphics/tinygl/zblit.h" @@ -33,6 +27,7 @@ #include "graphics/tinygl/pixelbuffer.h" #include "graphics/tinygl/zdirtyrect.h" #include "graphics/tinygl/gl.h" + #include namespace TinyGL { diff --git a/graphics/tinygl/zblit.h b/graphics/tinygl/zblit.h index 7ffc4993d22..f5db4c64af0 100644 --- a/graphics/tinygl/zblit.h +++ b/graphics/tinygl/zblit.h @@ -20,154 +20,18 @@ * */ -/* - * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard, - * which is licensed under the zlib-license (see LICENSE). - * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later). - */ - #ifndef GRAPHICS_TINYGL_ZBLIT_H_ #define GRAPHICS_TINYGL_ZBLIT_H_ -#include "graphics/surface.h" #include "common/rect.h" +#include "graphics/surface.h" +#include "graphics/tinygl/zblit_public.h" + namespace TinyGL { -struct BlitTransform { - BlitTransform(int dstX, int dstY) : _rotation(0), _originX(0), _originY(0), _aTint(1.0f), - _rTint(1.0f), _gTint(1.0f), _bTint(1.0), _flipHorizontally(false), - _flipVertically(false) { - _destinationRectangle.translate(dstX, dstY); - } - - void sourceRectangle(int srcX, int srcY, int srcWidth, int srcHeight) { - _sourceRectangle.left = srcX; - _sourceRectangle.top = srcY; - _sourceRectangle.setWidth(srcWidth); - _sourceRectangle.setHeight(srcHeight); - } - - void tint(float aTint, float rTint = 1.0f, float gTint = 1.0f, float bTint = 1.0f) { - _aTint = aTint; - _rTint = rTint; - _gTint = gTint; - _bTint = bTint; - } - - void scale(int width, int height) { - _destinationRectangle.setWidth(width); - _destinationRectangle.setHeight(height); - } - - void rotate(int rotation, int originX, int originY) { - _rotation = rotation; - _originX = originX; - _originY = originY; - } - - void flip(bool verticalFlip, bool horizontalFlip) { - _flipVertically = verticalFlip; - _flipHorizontally = horizontalFlip; - } - - bool operator==(const BlitTransform &other) const { - return _sourceRectangle == other._sourceRectangle && _destinationRectangle == other._destinationRectangle && - _rotation == other._rotation && _originX == other._originX && _originY == other._originY && - _aTint == other._aTint && _rTint == other._rTint && _gTint == other._gTint && _bTint == other._bTint && - _flipHorizontally == other._flipHorizontally && _flipVertically == other._flipVertically; - } - - Common::Rect _sourceRectangle; - Common::Rect _destinationRectangle; - int _rotation; - int _originX, _originY; - float _aTint, _rTint, _gTint, _bTint; - bool _flipHorizontally, _flipVertically; -}; - struct BlitImage; -} // end of namespace TinyGL - - -/** -@brief Generates a new blit image. -@return returns an opaque pointer to the blit image. -*/ -TinyGL::BlitImage *tglGenBlitImage(); - -/** -@brief Copies a surface data into the provided blit image. -@param pointer to the blit image. -@param referece to the surface that's being copied -@param color key value for alpha color keying -@param boolean that enables alpha color keying -*/ -void tglUploadBlitImage(TinyGL::BlitImage *blitImage, const Graphics::Surface &surface, uint32 colorKey, bool applyColorKey); - -/** -@brief Destroys an instance of blit image. -@param pointer to the blit image. -*/ -void tglDeleteBlitImage(TinyGL::BlitImage *blitImage); - -/** -@brief Getter for current blit image width and height -@param pointer to the blit image. -@param reference to the width variable -@param reference to the height variable -*/ -void tglGetBlitImageSize(TinyGL::BlitImage *blitImage, int &width, int &height); - -/** -@brief Provides a way to check if the image has been updated. -@param pointer to the blit image. -@param boolean that enables alpha color keying -*/ -int tglGetBlitImageVersion(TinyGL::BlitImage *blitImage); - -/** -@brief Blits an image to the color buffer. -@param pointer to the blit image. -@param blit transform information. -*/ -void tglBlit(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform); - -/** -@brief Blits an image to the color buffer. -@param pointer to the blit image. -@param x destination coordinate. -@param y destination coordinate. -*/ -void tglBlit(TinyGL::BlitImage *blitImage, int x, int y); - -/** -@brief Blits an image to the color buffer without performing any type of blending. -@param pointer to the blit image. -@param blit transform information. -*/ -void tglBlitNoBlend(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform); - -/** -@brief Blits an image to the color buffer without performinc any type of blending, image transformation or tinting. -@param pointer to the blit image. -@param x destination coordinate. -@param y destination coordinate. -*/ -void tglBlitFast(TinyGL::BlitImage *blitImage, int x, int y); - -/** -@brief Blits an image to the depth buffer. -@param pointer to the blit image. -@param x destination coordinate. -@param y destination coordinate. -*/ -void tglBlitZBuffer(TinyGL::BlitImage *blitImage, int x, int y); - -void tglIncBlitImageRef(TinyGL::BlitImage *blitImage); - -namespace TinyGL { namespace Internal { /** @brief Performs a cleanup of disposed blit images. diff --git a/graphics/tinygl/zblit_public.h b/graphics/tinygl/zblit_public.h new file mode 100644 index 00000000000..cfbbaed0e60 --- /dev/null +++ b/graphics/tinygl/zblit_public.h @@ -0,0 +1,164 @@ +/* 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. + * + */ + +#ifndef GRAPHICS_TINYGL_ZBLIT_PUBLIC_H +#define GRAPHICS_TINYGL_ZBLIT_PUBLIC_H + +#include "common/rect.h" + +#include "graphics/surface.h" + +namespace TinyGL { + +struct BlitTransform { + BlitTransform(int dstX, int dstY) : _rotation(0), _originX(0), _originY(0), _aTint(1.0f), + _rTint(1.0f), _gTint(1.0f), _bTint(1.0), _flipHorizontally(false), + _flipVertically(false) { + _destinationRectangle.translate(dstX, dstY); + } + + void sourceRectangle(int srcX, int srcY, int srcWidth, int srcHeight) { + _sourceRectangle.left = srcX; + _sourceRectangle.top = srcY; + _sourceRectangle.setWidth(srcWidth); + _sourceRectangle.setHeight(srcHeight); + } + + void tint(float aTint, float rTint = 1.0f, float gTint = 1.0f, float bTint = 1.0f) { + _aTint = aTint; + _rTint = rTint; + _gTint = gTint; + _bTint = bTint; + } + + void scale(int width, int height) { + _destinationRectangle.setWidth(width); + _destinationRectangle.setHeight(height); + } + + void rotate(int rotation, int originX, int originY) { + _rotation = rotation; + _originX = originX; + _originY = originY; + } + + void flip(bool verticalFlip, bool horizontalFlip) { + _flipVertically = verticalFlip; + _flipHorizontally = horizontalFlip; + } + + bool operator==(const BlitTransform &other) const { + return _sourceRectangle == other._sourceRectangle && _destinationRectangle == other._destinationRectangle && + _rotation == other._rotation && _originX == other._originX && _originY == other._originY && + _aTint == other._aTint && _rTint == other._rTint && _gTint == other._gTint && _bTint == other._bTint && + _flipHorizontally == other._flipHorizontally && _flipVertically == other._flipVertically; + } + + Common::Rect _sourceRectangle; + Common::Rect _destinationRectangle; + int _rotation; + int _originX, _originY; + float _aTint, _rTint, _gTint, _bTint; + bool _flipHorizontally, _flipVertically; +}; + +struct BlitImage; + +} // end of namespace TinyGL + +/** +@brief Generates a new blit image. +@return returns an opaque pointer to the blit image. +*/ +TinyGL::BlitImage *tglGenBlitImage(); + +/** +@brief Copies a surface data into the provided blit image. +@param pointer to the blit image. +@param referece to the surface that's being copied +@param color key value for alpha color keying +@param boolean that enables alpha color keying +*/ +void tglUploadBlitImage(TinyGL::BlitImage *blitImage, const Graphics::Surface &surface, uint32 colorKey, bool applyColorKey); + +/** +@brief Destroys an instance of blit image. +@param pointer to the blit image. +*/ +void tglDeleteBlitImage(TinyGL::BlitImage *blitImage); + +/** +@brief Getter for current blit image width and height +@param pointer to the blit image. +@param reference to the width variable +@param reference to the height variable +*/ +void tglGetBlitImageSize(TinyGL::BlitImage *blitImage, int &width, int &height); + +/** +@brief Provides a way to check if the image has been updated. +@param pointer to the blit image. +@param boolean that enables alpha color keying +*/ +int tglGetBlitImageVersion(TinyGL::BlitImage *blitImage); + +/** +@brief Blits an image to the color buffer. +@param pointer to the blit image. +@param blit transform information. +*/ +void tglBlit(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform); + +/** +@brief Blits an image to the color buffer. +@param pointer to the blit image. +@param x destination coordinate. +@param y destination coordinate. +*/ +void tglBlit(TinyGL::BlitImage *blitImage, int x, int y); + +/** +@brief Blits an image to the color buffer without performing any type of blending. +@param pointer to the blit image. +@param blit transform information. +*/ +void tglBlitNoBlend(TinyGL::BlitImage *blitImage, const TinyGL::BlitTransform &transform); + +/** +@brief Blits an image to the color buffer without performinc any type of blending, image transformation or tinting. +@param pointer to the blit image. +@param x destination coordinate. +@param y destination coordinate. +*/ +void tglBlitFast(TinyGL::BlitImage *blitImage, int x, int y); + +/** +@brief Blits an image to the depth buffer. +@param pointer to the blit image. +@param x destination coordinate. +@param y destination coordinate. +*/ +void tglBlitZBuffer(TinyGL::BlitImage *blitImage, int x, int y); + +void tglIncBlitImageRef(TinyGL::BlitImage *blitImage); + +#endif // GRAPHICS_TINYGL_ZBLIT_PUBLIC_H diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index 03d6a76acc8..c2dd9cc63cc 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -106,16 +106,6 @@ struct FrameBuffer { FrameBuffer(int xsize, int ysize, const Graphics::PixelFormat &format); ~FrameBuffer(); -private: - - Buffer *genOffscreenBuffer(); - void delOffscreenBuffer(Buffer *buffer); - -public: - - void clear(int clear_z, int z, int clear_color, int r, int g, int b); - void clearRegion(int x, int y, int w, int h,int clear_z, int z, int clear_color, int r, int g, int b); - Graphics::PixelFormat getPixelFormat() { return _pbufFormat; } @@ -132,15 +122,23 @@ public: return _pbufHeight; } - unsigned int *getZBuffer() { + const uint *getZBuffer() { return _zbuf; } - FORCEINLINE void readPixelRGB(int pixel, byte &r, byte &g, byte &b) { - _pbuf.getRGBAt(pixel, r, g, b); + Graphics::Surface *copyToBuffer(const Graphics::PixelFormat &dstFormat) { + Graphics::Surface tmp; + tmp.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat); + return tmp.convertTo(dstFormat); } - FORCEINLINE bool compareDepth(unsigned int &zSrc, unsigned int &zDst) { + void getSurfaceRef(Graphics::Surface &surface) { + surface.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat); + } + +private: + + FORCEINLINE bool compareDepth(uint &zSrc, uint &zDst) { if (!_depthTestEnabled) return true; @@ -177,8 +175,6 @@ public: return false; } -private: - FORCEINLINE bool checkAlphaTest(byte aSrc) { if (!_alphaTestEnabled) return true; @@ -216,15 +212,11 @@ private: return false; } -public: - template FORCEINLINE void writePixel(int pixel, int value) { writePixel(pixel, value, 0); } -private: - template FORCEINLINE void writePixel(int pixel, int value, unsigned int z) { if (kBlendingEnabled == false) { @@ -248,6 +240,29 @@ private: } } + template + FORCEINLINE void putPixelFlat(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, + int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, int &dzdx); + + template + FORCEINLINE void putPixelSmooth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, + int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, + int &dzdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx); + + template + FORCEINLINE void putPixelDepth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, int &dzdx); + + template + FORCEINLINE void putPixelShadow(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, + unsigned int &r, unsigned int &g, unsigned int &b, int &dzdx, unsigned char *pm); + + template + FORCEINLINE void putPixelTextureMappingPerspective(FrameBuffer *buffer, int buf, const Graphics::TexelBuffer *texture, + unsigned int wrap_s, unsigned int wrap_t, unsigned int *pz, int _a, + int x, int y, unsigned int &z, int &t, int &s, + unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, + int &dzdx, int &dsdx, int &dtdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx); + template FORCEINLINE void writePixel(int pixel, int value) { if (_blendingEnabled) { @@ -261,12 +276,12 @@ private: writePixel(pixel, 255, rSrc, gSrc, bSrc); } -public: - FORCEINLINE bool scissorPixel(int x, int y) { return !_clipRectangle.contains(x, y); } +public: + FORCEINLINE void writePixel(int pixel, byte aSrc, byte rSrc, byte gSrc, byte bSrc) { if (_alphaTestEnabled) { writePixel(pixel, aSrc, rSrc, gSrc, bSrc); @@ -275,6 +290,8 @@ public: } } +private: + template FORCEINLINE void writePixel(int pixel, byte aSrc, byte rSrc, byte gSrc, byte bSrc) { if (_blendingEnabled) { @@ -401,93 +418,92 @@ public: } } - Graphics::Surface *copyToBuffer(const Graphics::PixelFormat &dstFormat) { - Graphics::Surface tmp; - tmp.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat); - return tmp.convertTo(dstFormat); - } +public: - void getSurfaceRef(Graphics::Surface &surface) { - surface.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat); - } + void clear(int clear_z, int z, int clear_color, int r, int g, int b); + void clearRegion(int x, int y, int w, int h,int clear_z, int z, int clear_color, int r, int g, int b); - void setScissorRectangle(const Common::Rect &rect) { + FORCEINLINE void setScissorRectangle(const Common::Rect &rect) { _clipRectangle = rect; _enableScissor = true; } - void resetScissorRectangle() { + FORCEINLINE void resetScissorRectangle() { _enableScissor = false; } - void setShadowMaskBuf(byte *shadowBuffer) { + FORCEINLINE void setShadowMaskBuf(byte *shadowBuffer) { _shadowMaskBuf = shadowBuffer; } - void setShadowRGB(int r, int g, int b) { + FORCEINLINE void setShadowRGB(int r, int g, int b) { _shadowColorR = r; _shadowColorG = g; _shadowColorB = b; } - void enableBlending(bool enable) { + + FORCEINLINE void enableBlending(bool enable) { _blendingEnabled = enable; } - void enableDepthTest(bool enable) { - _depthTestEnabled = enable; - } - - void setOffsetStates(int offsetStates) { - _offsetStates = offsetStates; - } - - void setOffsetFactor(float offsetFactor) { - _offsetFactor = offsetFactor; - } - - void setOffsetUnits(float offsetUnits) { - _offsetUnits = offsetUnits; - } - - void setBlendingFactors(int sFactor, int dFactor) { + FORCEINLINE void setBlendingFactors(int sFactor, int dFactor) { _sourceBlendingFactor = sFactor; _destinationBlendingFactor = dFactor; } - void enableAlphaTest(bool enable) { + FORCEINLINE void enableAlphaTest(bool enable) { _alphaTestEnabled = enable; } - void setAlphaTestFunc(int func, int ref) { + FORCEINLINE void setAlphaTestFunc(int func, int ref) { _alphaTestFunc = func; _alphaTestRefVal = ref; } - void setDepthFunc(int func) { + FORCEINLINE void enableDepthTest(bool enable) { + _depthTestEnabled = enable; + } + + FORCEINLINE void setDepthFunc(int func) { _depthFunc = func; } - void enableDepthWrite(bool enable) { + FORCEINLINE void enableDepthWrite(bool enable) { _depthWrite = enable; } - void setTexture(const Graphics::TexelBuffer *texture, unsigned int wraps, unsigned int wrapt) { + FORCEINLINE void setOffsetStates(int offsetStates) { + _offsetStates = offsetStates; + } + + FORCEINLINE void setOffsetFactor(float offsetFactor) { + _offsetFactor = offsetFactor; + } + + FORCEINLINE void setOffsetUnits(float offsetUnits) { + _offsetUnits = offsetUnits; + } + + FORCEINLINE void setTexture(const Graphics::TexelBuffer *texture, unsigned int wraps, unsigned int wrapt) { _currentTexture = texture; _wrapS = wraps; _wrapT = wrapt; } - void setTextureSizeAndMask(int textureSize, int textureSizeMask) { + FORCEINLINE void setTextureSizeAndMask(int textureSize, int textureSizeMask) { _textureSize = textureSize; _textureSizeMask = textureSizeMask; } private: + /** * Blit the buffer to the screen buffer, checking the depth of the pixels. * Eack pixel is copied if and only if its depth value is bigger than the * depth value of the screen pixel, so if it is 'above'. */ + Buffer *genOffscreenBuffer(); + void delOffscreenBuffer(Buffer *buffer); void blitOffscreenBuffer(Buffer *buffer); void selectOffscreenBuffer(Buffer *buffer); void clearOffscreenBuffer(Buffer *buffer); @@ -538,10 +554,10 @@ private: FORCEINLINE void putPixel(unsigned int pixelOffset, int color, int x, int y); template - void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2); + FORCEINLINE void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2); template - void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2); + FORCEINLINE void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2); Buffer _offscreenBuffer; diff --git a/graphics/tinygl/zdirtyrect.cpp b/graphics/tinygl/zdirtyrect.cpp index 7f2ef7b216d..28248d1d0c6 100644 --- a/graphics/tinygl/zdirtyrect.cpp +++ b/graphics/tinygl/zdirtyrect.cpp @@ -20,15 +20,10 @@ * */ -/* - * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard, - * which is licensed under the zlib-license (see LICENSE). - * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later). - */ - #include "graphics/tinygl/zdirtyrect.h" #include "graphics/tinygl/zgl.h" #include "graphics/tinygl/gl.h" + #include "common/debug.h" #include "common/math.h" diff --git a/graphics/tinygl/zdirtyrect.h b/graphics/tinygl/zdirtyrect.h index 489ee7cadf6..92fd8b189da 100644 --- a/graphics/tinygl/zdirtyrect.h +++ b/graphics/tinygl/zdirtyrect.h @@ -20,19 +20,14 @@ * */ -/* - * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard, - * which is licensed under the zlib-license (see LICENSE). - * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later). - */ - -#ifndef GRAPHICS_TINYGL_ZRECT_H_ -#define GRAPHICS_TINYGL_ZRECT_H_ +#ifndef GRAPHICS_TINYGL_ZRECT_H +#define GRAPHICS_TINYGL_ZRECT_H #include "common/rect.h" -#include "graphics/tinygl/zblit.h" #include "common/array.h" +#include "graphics/tinygl/zblit.h" + namespace TinyGL { namespace Internal { diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index 50d82fe5822..2fa60c502ed 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -35,6 +35,8 @@ #include "common/list.h" #include "common/scummsys.h" +#include "graphics/pixelformat.h" +#include "graphics/surface.h" #include "graphics/tinygl/gl.h" #include "graphics/tinygl/zbuffer.h" #include "graphics/tinygl/zmath.h" @@ -486,13 +488,6 @@ GLContext *gl_get_context(); // matrix.c void gl_print_matrix(const float *m); -void getSurfaceRef(Graphics::Surface &surface); - -Graphics::Surface *copyToBuffer(const Graphics::PixelFormat &dstFormat); - -void createContext(int screenW, int screenH, Graphics::PixelFormat pixelFormat, int textureSize, bool dirtyRectsEnable = true); -void destroyContext(); - #ifdef DEBUG #define dprintf fprintf #else diff --git a/graphics/tinygl/ztriangle.cpp b/graphics/tinygl/ztriangle.cpp index 2eea5888933..d96634dda0e 100644 --- a/graphics/tinygl/ztriangle.cpp +++ b/graphics/tinygl/ztriangle.cpp @@ -36,8 +36,8 @@ namespace TinyGL { static const int NB_INTERP = 8; template -FORCEINLINE static void putPixelFlat(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, - int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, int &dzdx) { +FORCEINLINE void FrameBuffer::putPixelFlat(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, + int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, int &dzdx) { if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) { buffer->writePixel(buf + _a, a >> (ZB_POINT_ALPHA_BITS - 8), r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z); } @@ -45,9 +45,9 @@ FORCEINLINE static void putPixelFlat(FrameBuffer *buffer, int buf, unsigned int } template -FORCEINLINE static void putPixelSmooth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, - int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, - int &dzdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx) { +FORCEINLINE void FrameBuffer::putPixelSmooth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, + int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, + int &dzdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx) { if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) { buffer->writePixel(buf + _a, a >> (ZB_POINT_ALPHA_BITS - 8), r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z); } @@ -59,7 +59,7 @@ FORCEINLINE static void putPixelSmooth(FrameBuffer *buffer, int buf, unsigned in } template -FORCEINLINE static void putPixelDepth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, int &dzdx) { +FORCEINLINE void FrameBuffer::putPixelDepth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, int &dzdx) { if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) { if (kDepthWrite) { pz[_a] = z; @@ -69,7 +69,8 @@ FORCEINLINE static void putPixelDepth(FrameBuffer *buffer, int buf, unsigned int } template -FORCEINLINE static void putPixelShadow(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, int &dzdx, unsigned char *pm) { +FORCEINLINE void FrameBuffer::putPixelShadow(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, + unsigned int &r, unsigned int &g, unsigned int &b, int &dzdx, unsigned char *pm) { if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a]) && pm[_a]) { buffer->writePixel(buf + _a, 255, r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z); } @@ -77,10 +78,11 @@ FORCEINLINE static void putPixelShadow(FrameBuffer *buffer, int buf, unsigned in } template -FORCEINLINE static void putPixelTextureMappingPerspective(FrameBuffer *buffer, int buf, - const Graphics::TexelBuffer *texture, unsigned int wrap_s, unsigned int wrap_t, unsigned int *pz, int _a, - int x, int y, unsigned int &z, int &t, int &s, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, - int &dzdx, int &dsdx, int &dtdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx) { +FORCEINLINE void FrameBuffer::putPixelTextureMappingPerspective(FrameBuffer *buffer, int buf, const Graphics::TexelBuffer *texture, + unsigned int wrap_s, unsigned int wrap_t, unsigned int *pz, int _a, + int x, int y, unsigned int &z, int &t, int &s, + unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, + int &dzdx, int &dsdx, int &dtdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx) { if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) { uint8 c_a, c_r, c_g, c_b; texture->getARGBAt(wrap_s, wrap_t, s, t, c_a, c_r, c_g, c_b);