[Scummvm-git-logs] scummvm master -> 10f6a79ce8175d8ad4d9a995e68fec9b190e8df4
aquadran
noreply at scummvm.org
Tue Dec 7 19:40:39 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:
10f6a79ce8 TINYGL: More work on accessing FrameBuffer class
Commit: 10f6a79ce8175d8ad4d9a995e68fec9b190e8df4
https://github.com/scummvm/scummvm/commit/10f6a79ce8175d8ad4d9a995e68fec9b190e8df4
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-12-07T20:40:32+01:00
Commit Message:
TINYGL: More work on accessing FrameBuffer class
Changed paths:
graphics/tinygl/init.cpp
graphics/tinygl/vertex.cpp
graphics/tinygl/zblit.cpp
graphics/tinygl/zbuffer.h
graphics/tinygl/zdirtyrect.cpp
diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp
index eda9131a62..fcf5c8d251 100644
--- a/graphics/tinygl/init.cpp
+++ b/graphics/tinygl/init.cpp
@@ -65,19 +65,17 @@ void createContext(int screenW, int screenH, Graphics::PixelFormat pixelFormat,
void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat, int textureSize, bool dirtyRectsEnable) {
GLViewport *v;
+ _enableDirtyRectangles = dirtyRectsEnable;
+
+ fb = new TinyGL::FrameBuffer(screenW, screenH, pixelFormat);
+ renderRect = Common::Rect(0, 0, screenW, screenH);
+
if ((textureSize & (textureSize - 1)))
error("glInit: texture size not power of two: %d", textureSize);
-
if (textureSize <= 1 || textureSize > 4096)
error("glInit: texture size not allowed: %d", textureSize);
-
- _enableDirtyRectangles = dirtyRectsEnable;
-
- FrameBuffer *zbuffer = fb = new TinyGL::FrameBuffer(screenW, screenH, pixelFormat);
-
- fb->_textureSize = _textureSize = textureSize;
- fb->_textureSizeMask = (textureSize - 1) << ZB_POINT_ST_FRAC_BITS;
- renderRect = Common::Rect(0, 0, zbuffer->xsize, zbuffer->ysize);
+ _textureSize = textureSize;
+ fb->setTextureSizeAndMask(textureSize, (textureSize - 1) << ZB_POINT_ST_FRAC_BITS);
// allocate GLVertex array
vertex_max = POLYGON_MAX_VERTEX;
@@ -87,8 +85,8 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
v = &viewport;
v->xmin = 0;
v->ymin = 0;
- v->xsize = zbuffer->xsize;
- v->ysize = zbuffer->ysize;
+ v->xsize = screenW;
+ v->ysize = screenH;
v->updated = 1;
// shared state
diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp
index 223633bec5..f1b7352713 100644
--- a/graphics/tinygl/vertex.cpp
+++ b/graphics/tinygl/vertex.cpp
@@ -75,7 +75,7 @@ void GLContext::gl_eval_viewport() {
v = &viewport;
// v->ymin needs to be upside down for transformation
- int ymin = fb->ysize - v->ysize - v->ymin;
+ int ymin = fb->getPixelBufferHeight() - v->ysize - v->ymin;
v->trans.X = (float)(((v->xsize - 0.5) / 2.0) + v->xmin);
v->trans.Y = (float)(((v->ysize - 0.5) / 2.0) + ymin);
v->trans.Z = (float)(((zsize - 0.5) / 2.0) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2);
diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp
index 76abdeecd7..ca2d50801c 100644
--- a/graphics/tinygl/zblit.cpp
+++ b/graphics/tinygl/zblit.cpp
@@ -108,7 +108,7 @@ public:
Graphics::PixelBuffer _buf; // This is needed for the conversion.
Line() : _x(0), _y(0), _length(0), _pixels(nullptr) { }
- Line(int x, int y, int length, byte *pixels, const Graphics::PixelFormat &textureFormat) : _buf(TinyGL::gl_get_context()->fb->cmode, length, DisposeAfterUse::NO),
+ Line(int x, int y, int length, byte *pixels, const Graphics::PixelFormat &textureFormat) : _buf(gl_get_context()->fb->getPixelFormat(), length, DisposeAfterUse::NO),
_x(x), _y(y), _length(length) {
// Performing texture to screen conversion.
Graphics::PixelBuffer srcBuf(textureFormat, pixels);
@@ -202,15 +202,17 @@ public:
if (clipBlitImage(c, srcX, srcY, srcWidth, srcHeight, width, height, dstX, dstY, clampWidth, clampHeight) == false)
return;
+ int fbWidth = c->fb->getPixelBufferWidth();
+
Graphics::PixelBuffer srcBuf(_surface.format, (byte *)const_cast<void *>(_surface.getPixels())); // Blit image buffer
Graphics::PixelBuffer dstBuf(_surface.format, (byte *)c->fb->getZBuffer()); // TinyGL z buffer
srcBuf.shiftBy(srcY * _surface.w);
- dstBuf.shiftBy(dstY * c->fb->xsize);
+ dstBuf.shiftBy(dstY * fbWidth);
for (int y = 0; y < clampHeight; y++) {
dstBuf.copyBuffer(dstX, srcX, clampWidth, srcBuf);
- dstBuf.shiftBy(c->fb->xsize);
+ dstBuf.shiftBy(fbWidth);
srcBuf.shiftBy(_surface.w);
}
}
@@ -325,13 +327,15 @@ FORCEINLINE void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, i
if (aTint <= 0.0f)
return;
+ int fbWidth = c->fb->getPixelBufferWidth();
+
Graphics::PixelBuffer srcBuf(_surface.format, (byte *)_surface.getPixels());
srcBuf.shiftBy(srcX + (srcY * _surface.w));
- Graphics::PixelBuffer dstBuf(c->fb->cmode, c->fb->getPixelBuffer());
- dstBuf.shiftBy(dstY * c->fb->xsize + dstX);
+ Graphics::PixelBuffer dstBuf(c->fb->getPixelFormat(), c->fb->getPixelBuffer());
+ dstBuf.shiftBy(dstY * fbWidth + dstX);
- int kBytesPerPixel = c->fb->cmode.bytesPerPixel;
+ int kBytesPerPixel = c->fb->getPixelFormat().bytesPerPixel;
uint32 lineIndex = 0;
int maxY = srcY + clampHeight;
@@ -350,17 +354,17 @@ FORCEINLINE void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, i
int skipEnd = (l._x + l._length > maxX) ? (l._x + l._length - maxX) : 0;
length -= skipEnd;
if (kDisableColoring && (kEnableAlphaBlending == false || kDisableBlending)) {
- memcpy(dstBuf.getRawBuffer((l._y - srcY) * c->fb->xsize + MAX(l._x - srcX, 0)),
+ memcpy(dstBuf.getRawBuffer((l._y - srcY) * fbWidth + MAX(l._x - srcX, 0)),
l._pixels + skipStart * kBytesPerPixel, length * kBytesPerPixel);
} else {
int xStart = MAX(l._x - srcX, 0);
if (kDisableColoring) {
- dstBuf.copyBuffer(xStart + (l._y - srcY) * c->fb->xsize, skipStart, length, l._buf);
+ dstBuf.copyBuffer(xStart + (l._y - srcY) * fbWidth, skipStart, length, l._buf);
} else {
for(int x = xStart; x < xStart + length; x++) {
byte aDst, rDst, gDst, bDst;
srcBuf.getARGBAt((l._y - srcY) * _surface.w + x, aDst, rDst, gDst, bDst);
- c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
@@ -378,7 +382,7 @@ FORCEINLINE void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, i
int skipEnd = (l._x + l._length > maxX) ? (l._x + l._length - maxX) : 0;
length -= skipEnd;
if (kDisableColoring && (kEnableAlphaBlending == false || kDisableBlending)) {
- memcpy(dstBuf.getRawBuffer((l._y - srcY) * c->fb->xsize + MAX(l._x - srcX, 0)),
+ memcpy(dstBuf.getRawBuffer((l._y - srcY) * fbWidth + MAX(l._x - srcX, 0)),
l._pixels + skipStart * kBytesPerPixel, length * kBytesPerPixel);
} else {
int xStart = MAX(l._x - srcX, 0);
@@ -387,12 +391,12 @@ FORCEINLINE void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, i
srcBuf.getARGBAt((l._y - srcY) * _surface.w + x, aDst, rDst, gDst, bDst);
if (kDisableColoring) {
if (aDst != 0xFF) {
- c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * fbWidth, aDst, rDst, gDst, bDst);
} else {
- dstBuf.setPixelAt(x + (l._y - srcY) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ dstBuf.setPixelAt(x + (l._y - srcY) * fbWidth, aDst, rDst, gDst, bDst);
}
} else {
- c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ c->fb->writePixel((dstX + x) + (dstY + (l._y - srcY)) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
}
@@ -420,7 +424,8 @@ FORCEINLINE void BlitImage::tglBlitSimple(int dstX, int dstY, int srcX, int srcY
srcBuf.shiftBy((srcY * _surface.w));
}
- Graphics::PixelBuffer dstBuf(c->fb->cmode, c->fb->getPixelBuffer());
+ Graphics::PixelBuffer dstBuf(c->fb->getPixelFormat(), c->fb->getPixelBuffer());
+ int fbWidth = c->fb->getPixelBufferWidth();
for (int y = 0; y < clampHeight; y++) {
for (int x = 0; x < clampWidth; ++x) {
@@ -434,15 +439,15 @@ FORCEINLINE void BlitImage::tglBlitSimple(int dstX, int dstY, int srcX, int srcY
// Those branches are needed to favor speed: avoiding writePixel always yield a huge performance boost when blitting images.
if (kDisableColoring) {
if (kDisableBlending && aDst != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
}
} else {
if (kDisableBlending && aDst * aTint != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
}
@@ -468,7 +473,8 @@ FORCEINLINE void BlitImage::tglBlitScale(int dstX, int dstY, int width, int heig
Graphics::PixelBuffer srcBuf(_surface.format, (byte *)_surface.getPixels());
srcBuf.shiftBy(srcX + (srcY * _surface.w));
- Graphics::PixelBuffer dstBuf(c->fb->cmode, c->fb->getPixelBuffer());
+ Graphics::PixelBuffer dstBuf(c->fb->getPixelFormat(), c->fb->getPixelBuffer());
+ int fbWidth = c->fb->getPixelBufferWidth();
for (int y = 0; y < clampHeight; y++) {
for (int x = 0; x < clampWidth; ++x) {
@@ -490,15 +496,15 @@ FORCEINLINE void BlitImage::tglBlitScale(int dstX, int dstY, int width, int heig
if (kDisableColoring) {
if (kDisableBlending && aDst != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
}
} else {
if (kDisableBlending && aDst * aTint != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
}
@@ -556,18 +562,19 @@ FORCEINLINE void BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int
Graphics::PixelBuffer srcBuf(_surface.format, (byte *)_surface.getPixels());
srcBuf.shiftBy(srcX + (srcY * _surface.w));
+ int fbWidth = c->fb->getPixelBufferWidth();
- Graphics::PixelBuffer dstBuf(c->fb->cmode, c->fb->getPixelBuffer());
+ Graphics::PixelBuffer dstBuf(c->fb->getPixelFormat(), c->fb->getPixelBuffer());
// Transform destination rectangle accordingly.
Common::Rect destinationRectangle = rotateRectangle(dstX, dstY, width, height, rotation, originX, originY);
- if (dstX + destinationRectangle.width() > c->fb->xsize)
- clampWidth = c->fb->xsize - dstX;
+ if (dstX + destinationRectangle.width() > fbWidth)
+ clampWidth = fbWidth - dstX;
else
clampWidth = destinationRectangle.width();
- if (dstY + destinationRectangle.height() > c->fb->ysize)
- clampHeight = c->fb->ysize - dstY;
+ if (dstY + destinationRectangle.height() > c->fb->getPixelBufferHeight())
+ clampHeight = c->fb->getPixelBufferHeight() - dstY;
else
clampHeight = destinationRectangle.height();
@@ -612,15 +619,15 @@ FORCEINLINE void BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int
srcBuf.getARGBAt(dy * _surface.w + dx, aDst, rDst, gDst, bDst);
if (kDisableColoring) {
if (kDisableBlending && aDst != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst, rDst, gDst, bDst);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst, rDst, gDst, bDst);
}
} else {
if (kDisableBlending && aDst * aTint != 0) {
- dstBuf.setPixelAt((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ dstBuf.setPixelAt((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
} else {
- c->fb->writePixel((dstX + x) + (dstY + y) * c->fb->xsize, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
+ c->fb->writePixel((dstX + x) + (dstY + y) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
}
diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h
index 98b1c64d50..a7c854d07f 100644
--- a/graphics/tinygl/zbuffer.h
+++ b/graphics/tinygl/zbuffer.h
@@ -107,17 +107,31 @@ struct FrameBuffer {
~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 cmode;
+ }
+
byte *getPixelBuffer() {
return pbuf.getRawBuffer();
}
+ int getPixelBufferWidth() {
+ return xsize;
+ }
+
+ int getPixelBufferHeight() {
+ return ysize;
+ }
+
unsigned int *getZBuffer() {
return _zbuf;
}
@@ -164,6 +178,7 @@ public:
}
private:
+
FORCEINLINE bool checkAlphaTest(byte aSrc) {
if (!_alphaTestEnabled)
return true;
@@ -202,12 +217,14 @@ private:
}
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) {
@@ -245,6 +262,7 @@ private:
}
public:
+
FORCEINLINE bool scissorPixel(int x, int y) {
return !_clipRectangle.contains(x, y);
}
@@ -397,12 +415,15 @@ public:
_clipRectangle = rect;
_enableScissor = true;
}
+
void resetScissorRectangle() {
_enableScissor = false;
}
+
void setShadowMaskBuf(byte *shadowBuffer) {
_shadowMaskBuf = shadowBuffer;
}
+
void setShadowRGB(int r, int g, int b) {
_shadowColorR = r;
_shadowColorG = g;
@@ -456,6 +477,11 @@ public:
_wrapT = wrapt;
}
+ void setTextureSizeAndMask(int textureSize, int textureSizeMask) {
+ _textureSize = textureSize;
+ _textureSizeMask = textureSizeMask;
+ }
+
private:
/**
* Blit the buffer to the screen buffer, checking the depth of the pixels.
@@ -482,6 +508,7 @@ private:
void fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2);
public:
+
void fillTriangleTextureMappingPerspectiveSmooth(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2);
void fillTriangleTextureMappingPerspectiveFlat(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2);
void fillTriangleDepthOnly(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2);
@@ -493,30 +520,14 @@ public:
void plot(ZBufferPoint *p);
void fillLine(ZBufferPoint *p1, ZBufferPoint *p2);
void fillLineZ(ZBufferPoint *p1, ZBufferPoint *p2);
+
private:
+
void fillLineFlatZ(ZBufferPoint *p1, ZBufferPoint *p2);
void fillLineInterpZ(ZBufferPoint *p1, ZBufferPoint *p2);
void fillLineFlat(ZBufferPoint *p1, ZBufferPoint *p2);
void fillLineInterp(ZBufferPoint *p1, ZBufferPoint *p2);
- Common::Rect _clipRectangle;
- bool _enableScissor;
-public:
- int xsize, ysize;
- int linesize; // line size, in bytes
- Graphics::PixelFormat cmode;
-private:
- int pixelbytes;
-
- Buffer buffer;
-
- unsigned char *dctable;
- int *ctable;
-public:
- int _textureSize;
- int _textureSizeMask;
-
-private:
template <bool kDepthWrite>
FORCEINLINE void putPixel(unsigned int pixelOffset, int color, int x, int y, unsigned int z);
@@ -532,9 +543,22 @@ private:
template <bool kInterpRGB, bool kInterpZ, bool kDepthWrite, bool kEnableScissor>
void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
+ Buffer buffer;
+
unsigned int *_zbuf;
Graphics::PixelBuffer pbuf;
+ int xsize, ysize;
+ int linesize; // line size, in bytes
+ Graphics::PixelFormat cmode;
+ int pixelbytes;
+
+ int _textureSize;
+ int _textureSizeMask;
+
+ Common::Rect _clipRectangle;
+ bool _enableScissor;
+
const Graphics::TexelBuffer *_currentTexture;
unsigned int _wrapS, _wrapT;
byte *_shadowMaskBuf;
diff --git a/graphics/tinygl/zdirtyrect.cpp b/graphics/tinygl/zdirtyrect.cpp
index 899f52ed4d..3d765adffc 100644
--- a/graphics/tinygl/zdirtyrect.cpp
+++ b/graphics/tinygl/zdirtyrect.cpp
@@ -304,8 +304,8 @@ void RasterizationDrawCall::computeDirtyRegion() {
if (!clip_code) {
GLContext *c = gl_get_context();
- int xmax = c->fb->xsize - 1;
- int ymax = c->fb->ysize - 1;
+ int xmax = c->fb->getPixelBufferWidth() - 1;
+ int ymax = c->fb->getPixelBufferHeight() - 1;
int left = xmax, right = 0, top = ymax, bottom = 0;
for (int i = 0; i < _vertexCount; i++) {
TinyGL::GLVertex *v = &_vertex[i];
More information about the Scummvm-git-logs
mailing list