TINYGL: Rearrange access to TinyGL

This commit is contained in:
Paweł Kołodziejski 2021-12-08 14:52:18 +01:00
parent 5abcf1cb6b
commit 3b9f9804ee
No known key found for this signature in database
GPG Key ID: 0BDADC9E74440FF7
32 changed files with 328 additions and 270 deletions

View File

@ -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 };

View File

@ -25,7 +25,7 @@
#include "engines/grim/gfx_base.h"
#include "graphics/tinygl/zgl.h"
#include "graphics/tinygl/tinygl.h"
namespace Graphics {
struct Surface;

View File

@ -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 {

View File

@ -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 {

View File

@ -21,7 +21,8 @@
*/
#include "engines/myst3/gfx_tinygl_texture.h"
#include "graphics/tinygl/zblit.h"
#include "graphics/tinygl/tinygl.h"
namespace Myst3 {

View File

@ -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 {

View File

@ -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"

View File

@ -28,7 +28,7 @@
#include "math/vector3d.h"
#include "graphics/tinygl/zgl.h"
#include "graphics/tinygl/tinygl.h"
#include "engines/playground3d/gfx.h"

View File

@ -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"

View File

@ -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 {

View File

@ -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"

View File

@ -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"

View File

@ -21,7 +21,6 @@
*/
#include "engines/stark/gfx/tinyglbitmap.h"
#include "engines/stark/gfx/driver.h"
#include "graphics/surface.h"

View File

@ -25,7 +25,7 @@
#include "engines/stark/gfx/texture.h"
#include "graphics/tinygl/zgl.h"
#include "graphics/tinygl/tinygl.h"
namespace Stark {
namespace Gfx {

View File

@ -21,7 +21,6 @@
*/
#include "engines/stark/gfx/tinyglfade.h"
#include "engines/stark/gfx/tinygl.h"
namespace Stark {

View File

@ -25,7 +25,7 @@
#include "engines/stark/gfx/faderenderer.h"
#include "graphics/tinygl/zgl.h"
#include "graphics/tinygl/tinygl.h"
namespace Stark {
namespace Gfx {

View File

@ -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"

View File

@ -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"

View File

@ -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 {

View File

@ -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"

View File

@ -21,7 +21,6 @@
*/
#include "engines/stark/gfx/tinygltexture.h"
#include "engines/stark/gfx/driver.h"
#include "graphics/surface.h"

View File

@ -25,7 +25,7 @@
#include "engines/stark/gfx/texture.h"
#include "graphics/tinygl/zgl.h"
#include "graphics/tinygl/tinygl.h"
namespace Stark {
namespace Gfx {

View File

@ -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

41
graphics/tinygl/tinygl.h Normal file
View File

@ -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

View File

@ -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 <math.h>
namespace TinyGL {

View File

@ -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.

View File

@ -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

View File

@ -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 <bool kEnableAlphaTest, bool kBlendingEnabled>
FORCEINLINE void writePixel(int pixel, int value) {
writePixel<kEnableAlphaTest, kBlendingEnabled, false>(pixel, value, 0);
}
private:
template <bool kEnableAlphaTest, bool kBlendingEnabled, bool kDepthWrite>
FORCEINLINE void writePixel(int pixel, int value, unsigned int z) {
if (kBlendingEnabled == false) {
@ -248,6 +240,29 @@ private:
}
}
template <bool kDepthWrite, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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 <bool kDepthWrite, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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 <bool kDepthWrite, bool kEnableScissor>
FORCEINLINE void putPixelDepth(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, int &dzdx);
template <bool kDepthWrite, bool kAlphaTestEnabled, bool kEnableScissor, bool kBlendingEnabled>
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 <bool kDepthWrite, bool kLightsMode, bool kSmoothMode, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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 <bool kEnableAlphaTest>
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<true>(pixel, aSrc, rSrc, gSrc, bSrc);
@ -275,6 +290,8 @@ public:
}
}
private:
template <bool kEnableAlphaTest>
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 <bool kInterpRGB, bool kInterpZ, bool kDepthWrite>
void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
FORCEINLINE void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
template <bool kInterpRGB, bool kInterpZ, bool kDepthWrite, bool kEnableScissor>
void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
FORCEINLINE void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
Buffer _offscreenBuffer;

View File

@ -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"

View File

@ -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 {

View File

@ -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

View File

@ -36,8 +36,8 @@ namespace TinyGL {
static const int NB_INTERP = 8;
template <bool kDepthWrite, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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<kEnableAlphaTest, kEnableBlending, kDepthWrite>(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 <bool kDepthWrite, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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<kEnableAlphaTest, kEnableBlending, kDepthWrite>(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 <bool kDepthWrite, bool kEnableScissor>
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 <bool kDepthWrite, bool kAlphaTestEnabled, bool kEnableScissor, bool kBlendingEnabled>
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<kAlphaTestEnabled, kBlendingEnabled, kDepthWrite>(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 <bool kDepthWrite, bool kLightsMode, bool kSmoothMode, bool kEnableAlphaTest, bool kEnableScissor, bool kEnableBlending>
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);