[Scummvm-git-logs] scummvm master -> bbe8010cd1cd60b58bfb1ac9154e165df63888dc
sev-
noreply at scummvm.org
Sun May 14 21:04:16 UTC 2023
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
d293a659d3 TINYGL: Remove use of Graphics::PixelBuffer from the FrameBuffer class
bbe8010cd1 TINYGL: Remove use of Graphics::PixelBuffer from the Line class
Commit: d293a659d3fe64a8318e409224e08baef94269ab
https://github.com/scummvm/scummvm/commit/d293a659d3fe64a8318e409224e08baef94269ab
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-05-14T23:04:11+02:00
Commit Message:
TINYGL: Remove use of Graphics::PixelBuffer from the FrameBuffer class
Changed paths:
graphics/tinygl/zblit.cpp
graphics/tinygl/zbuffer.cpp
graphics/tinygl/zbuffer.h
diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp
index 0d7393381f9..7b48571332d 100644
--- a/graphics/tinygl/zblit.cpp
+++ b/graphics/tinygl/zblit.cpp
@@ -357,10 +357,12 @@ void BlitImage::tglBlitOpaque(int dstX, int dstY, int srcX, int srcY, int srcWid
if (clipBlitImage(c, srcX, srcY, srcWidth, srcHeight, width, height, dstX, dstY, clampWidth, clampHeight) == false)
return;
- int fbWidth = c->fb->getPixelBufferWidth();
+ int fbPitch = c->fb->getPixelBufferPitch();
+ int fbBpp = c->fb->getPixelBufferBpp();
+ byte *fbBuf = c->fb->getPixelBuffer() + (dstX * fbBpp) + (dstY * fbPitch);
- Graphics::crossBlit(c->fb->getPixelBuffer(dstX + dstY * fbWidth), (const byte *)_surface.getBasePtr(srcX, srcY),
- c->fb->getPixelBufferPitch(), _surface.pitch, clampWidth, clampHeight,
+ Graphics::crossBlit(fbBuf, (const byte *)_surface.getBasePtr(srcX, srcY),
+ fbPitch, _surface.pitch, clampWidth, clampHeight,
c->fb->getPixelFormat(), _surface.format);
}
diff --git a/graphics/tinygl/zbuffer.cpp b/graphics/tinygl/zbuffer.cpp
index 9f045ba63a9..2dd10a13954 100644
--- a/graphics/tinygl/zbuffer.cpp
+++ b/graphics/tinygl/zbuffer.cpp
@@ -86,14 +86,14 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &for
_pbufBpp = _pbufFormat.bytesPerPixel;
_pbufPitch = (_pbufWidth * _pbufBpp + 3) & ~3;
- _pbuf.set(_pbufFormat, new byte[_pbufHeight * _pbufPitch]);
+ _pbuf = (byte *)gl_zalloc(_pbufHeight * _pbufPitch * sizeof(byte));
_zbuf = (uint *)gl_zalloc(_pbufWidth * _pbufHeight * sizeof(uint));
if (enableStencilBuffer)
_sbuf = (byte *)gl_zalloc(_pbufWidth * _pbufHeight * sizeof(byte));
else
_sbuf = nullptr;
- _offscreenBuffer.pbuf = _pbuf.getRawBuffer();
+ _offscreenBuffer.pbuf = _pbuf;
_offscreenBuffer.zbuf = _zbuf;
_currentTexture = nullptr;
@@ -102,7 +102,7 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &for
}
FrameBuffer::~FrameBuffer() {
- _pbuf.free();
+ gl_free(_pbuf);
gl_free(_zbuf);
if (_sbuf)
gl_free(_sbuf);
@@ -136,7 +136,7 @@ void FrameBuffer::clear(int clearZ, int z, int clearColor, int r, int g, int b,
}
}
if (clearColor) {
- byte *pp = _pbuf.getRawBuffer();
+ byte *pp = _pbuf;
uint32 color = _pbufFormat.RGBToColor(r, g, b);
const uint8 *colorc = (uint8 *)&color;
uint i;
@@ -187,7 +187,7 @@ void FrameBuffer::clearRegion(int x, int y, int w, int h, bool clearZ, int z,
}
if (clearColor) {
int height = h;
- byte *pp = _pbuf.getRawBuffer() + y * _pbufPitch + x * _pbufBpp;
+ byte *pp = _pbuf + y * _pbufPitch + x * _pbufBpp;
uint32 color = _pbufFormat.RGBToColor(r, g, b);
const uint8 *colorc = (uint8 *)&color;
uint i;
@@ -238,7 +238,7 @@ void FrameBuffer::blitOffscreenBuffer(Buffer *buf) {
if (buf->used) {
const int pixel_bytes = _pbufBpp;
const int unrolled_pixel_bytes = pixel_bytes * UNROLL_COUNT;
- byte *to = _pbuf.getRawBuffer();
+ byte *to = _pbuf;
byte *from = buf->pbuf;
uint *to_z = _zbuf;
uint *from_z = buf->zbuf;
diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h
index 154917e86ea..3a42a45a2bd 100644
--- a/graphics/tinygl/zbuffer.h
+++ b/graphics/tinygl/zbuffer.h
@@ -29,7 +29,6 @@
#define GRAPHICS_TINYGL_ZBUFFER_H_
#include "graphics/surface.h"
-#include "graphics/tinygl/pixelbuffer.h"
#include "graphics/tinygl/texelbuffer.h"
#include "graphics/tinygl/gl.h"
@@ -112,11 +111,7 @@ struct FrameBuffer {
}
byte *getPixelBuffer() {
- return _pbuf.getRawBuffer();
- }
-
- byte *getPixelBuffer(int pixel) {
- return _pbuf.getRawBuffer(pixel);
+ return _pbuf;
}
int getPixelBufferWidth() {
@@ -131,22 +126,67 @@ struct FrameBuffer {
return _pbufPitch;
}
+ int getPixelBufferBpp() {
+ return _pbufBpp;
+ }
+
const uint *getZBuffer() {
return _zbuf;
}
Graphics::Surface *copyFromFrameBuffer(const Graphics::PixelFormat &dstFormat) {
Graphics::Surface tmp;
- tmp.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat);
+ tmp.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf, _pbufFormat);
return tmp.convertTo(dstFormat);
}
void getSurfaceRef(Graphics::Surface &surface) {
- surface.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf.getRawBuffer(), _pbufFormat);
+ surface.init(_pbufWidth, _pbufHeight, _pbufPitch, _pbuf, _pbufFormat);
}
private:
+ FORCEINLINE void setPixelAt(int pixel, uint32 value) {
+ switch (_pbufBpp) {
+ case 2:
+ ((uint16 *) _pbuf)[pixel] = value;
+ return;
+ case 3:
+ pixel *= 3;
+#if defined(SCUMM_BIG_ENDIAN)
+ _pbuf[pixel + 0] = (value >> 16) & 0xFF;
+ _pbuf[pixel + 1] = (value >> 8) & 0xFF;
+ _pbuf[pixel + 2] = value & 0xFF;
+#elif defined(SCUMM_LITTLE_ENDIAN)
+ _pbuf[pixel + 0] = value & 0xFF;
+ _pbuf[pixel + 1] = (value >> 8) & 0xFF;
+ _pbuf[pixel + 2] = (value >> 16) & 0xFF;
+#endif
+ return;
+ case 4:
+ ((uint32 *) _pbuf)[pixel] = value;
+ return;
+ }
+ error("setPixelAt: Unhandled bytesPerPixel %d", int(_pbufBpp));
+ }
+
+ FORCEINLINE uint32 getPixelAt(int i) const {
+ switch (_pbufBpp) {
+ case 2:
+ return ((uint16 *) _pbuf)[i];
+ case 3:
+ i *= 3;
+#if defined(SCUMM_BIG_ENDIAN)
+ return (_pbuf[i + 0] << 16) | (_pbuf[i + 1] << 8) | _pbuf[i + 2];
+#elif defined(SCUMM_LITTLE_ENDIAN)
+ return _pbuf[i + 0] | (_pbuf[i + 1] << 8) | (_pbuf[i + 2] << 16);
+#endif
+ case 4:
+ return ((uint32 *) _pbuf)[i];
+ }
+ error("getPixelAt: Unhandled bytesPerPixel %d", int(_pbufBpp));
+ }
+
FORCEINLINE bool compareDepth(uint &zSrc, uint &zDst) {
if (!_depthTestEnabled)
return true;
@@ -295,13 +335,13 @@ private:
template <bool kEnableAlphaTest, bool kBlendingEnabled, bool kDepthWrite>
FORCEINLINE void writePixel(int pixel, int value, uint z) {
if (kBlendingEnabled == false) {
- _pbuf.setPixelAt(pixel, value);
+ setPixelAt(pixel, value);
if (kDepthWrite) {
_zbuf[pixel] = z;
}
} else {
byte rSrc, gSrc, bSrc, aSrc;
- _pbuf.getFormat().colorToARGB(value, aSrc, rSrc, gSrc, bSrc);
+ _pbufFormat.colorToARGB(value, aSrc, rSrc, gSrc, bSrc);
writePixel<kEnableAlphaTest, kBlendingEnabled, kDepthWrite>(pixel, aSrc, rSrc, gSrc, bSrc, z);
}
@@ -415,10 +455,10 @@ private:
}
if (!kBlendingEnabled) {
- _pbuf.setPixelAt(pixel, aSrc, rSrc, gSrc, bSrc);
+ setPixelAt(pixel, _pbufFormat.ARGBToColor(aSrc, rSrc, gSrc, bSrc));
} else {
byte rDst, gDst, bDst, aDst;
- _pbuf.getARGBAt(pixel, aDst, rDst, gDst, bDst);
+ _pbufFormat.colorToARGB(getPixelAt(pixel), aDst, rDst, gDst, bDst);
switch (_sourceBlendingFactor) {
case TGL_ZERO:
rSrc = gSrc = bSrc = 0;
@@ -517,7 +557,7 @@ private:
if (finalB > 255) {
finalB = 255;
}
- _pbuf.setPixelAt(pixel, 255, finalR, finalG, finalB);
+ setPixelAt(pixel, _pbufFormat.RGBToColor(finalR, finalG, finalB));
}
}
@@ -701,7 +741,7 @@ private:
void drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2);
Buffer _offscreenBuffer;
- Graphics::PixelBuffer _pbuf;
+ byte *_pbuf;
int _pbufWidth;
int _pbufHeight;
int _pbufPitch;
Commit: bbe8010cd1cd60b58bfb1ac9154e165df63888dc
https://github.com/scummvm/scummvm/commit/bbe8010cd1cd60b58bfb1ac9154e165df63888dc
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-05-14T23:04:11+02:00
Commit Message:
TINYGL: Remove use of Graphics::PixelBuffer from the Line class
Changed paths:
graphics/tinygl/zblit.cpp
diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp
index 7b48571332d..e742b296a32 100644
--- a/graphics/tinygl/zblit.cpp
+++ b/graphics/tinygl/zblit.cpp
@@ -127,18 +127,16 @@ public:
struct Line {
int _x;
int _y;
+ int _bpp;
int _length;
byte *_pixels;
- 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(gl_get_context()->fb->getPixelFormat(), length, DisposeAfterUse::NO),
- _x(x), _y(y), _length(length) {
- // Performing texture to screen conversion.
- Graphics::PixelBuffer srcBuf(textureFormat, pixels);
- _buf.copyBuffer(0, 0, length, srcBuf);
- _pixels = _buf.getRawBuffer();
+ _x(x), _y(y), _bpp(gl_get_context()->fb->getPixelBufferBpp()), _length(length) {
+ _pixels = (byte *)gl_zalloc(_length * _bpp);
+ Graphics::crossBlit(_pixels, pixels, _length * _bpp, _length * _bpp, _length, 1,
+ gl_get_context()->fb->getPixelFormat(), textureFormat);
}
Line &operator=(const Line &other) {
@@ -146,23 +144,22 @@ public:
return *this;
_x = other._x;
_y = other._y;
- if (_length != other._length || _buf.getFormat() != other._buf.getFormat()) {
- _buf.free();
- _buf.create(other._buf.getFormat(), other._length, DisposeAfterUse::NO);
+ if (_length != other._length || _bpp != other._bpp) {
+ _pixels = (byte *)gl_realloc(_pixels, other._length * other._bpp);
_length = other._length;
+ _bpp = other._bpp;
}
- _buf.copyBuffer(0, 0, _length, other._buf);
- _pixels = _buf.getRawBuffer();
+ memcpy(_pixels, other._pixels, _length * _bpp);
return *this;
}
- Line(const Line& other) : _buf(other._buf.getFormat(), other._length, DisposeAfterUse::NO), _x(other._x), _y(other._y), _length(other._length) {
- _buf.copyBuffer(0, 0, _length, other._buf);
- _pixels = _buf.getRawBuffer();
+ Line(const Line& other) : _x(other._x), _y(other._y), _bpp(other._bpp), _length(other._length) {
+ _pixels = (byte *)gl_zalloc(_length * _bpp);
+ memcpy(_pixels, other._pixels, _length * _bpp);
}
~Line() {
- _buf.free();
+ gl_free(_pixels);
}
};
@@ -407,19 +404,15 @@ void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, int srcWidth,
length -= skipStart;
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) * fbWidth + MAX(l._x - srcX, 0)),
+ int xStart = MAX(l._x - srcX, 0);
+ if (kDisableColoring) {
+ memcpy(dstBuf.getRawBuffer((l._y - srcY) * fbWidth + xStart),
l._pixels + skipStart * kBytesPerPixel, length * kBytesPerPixel);
} else {
- int xStart = MAX(l._x - srcX, 0);
- if (kDisableColoring) {
- 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)) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
- }
+ 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)) * fbWidth, aDst * aTint, rDst * rTint, gDst * gTint, bDst * bTint);
}
}
}
@@ -434,11 +427,11 @@ void BlitImage::tglBlitRLE(int dstX, int dstY, int srcX, int srcY, int srcWidth,
length -= skipStart;
int skipEnd = (l._x + l._length > maxX) ? (l._x + l._length - maxX) : 0;
length -= skipEnd;
+ int xStart = MAX(l._x - srcX, 0);
if (kDisableColoring && (kEnableAlphaBlending == false || kDisableBlending)) {
- memcpy(dstBuf.getRawBuffer((l._y - srcY) * fbWidth + MAX(l._x - srcX, 0)),
+ memcpy(dstBuf.getRawBuffer((l._y - srcY) * fbWidth + xStart),
l._pixels + skipStart * kBytesPerPixel, length * kBytesPerPixel);
} else {
- int xStart = MAX(l._x - srcX, 0);
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);
More information about the Scummvm-git-logs
mailing list