[Scummvm-git-logs] scummvm master -> 57e9b44a11823e0685deecf12b701693c75b157a
OMGPizzaGuy
noreply at scummvm.org
Fri Dec 16 05:35:20 UTC 2022
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
0bba925e9f ULTIMA8: Avoid color unpacking in minimap generation by using the RGB palette directly
4088b9a4f0 ULTIMA8: Combine RenderSurface and BaseSoftRenderSurface
57e9b44a11 ULTIMA8: Remove unneeded variables from render surface
Commit: 0bba925e9f732dc814d1daaefae93231bd9bf5a6
https://github.com/scummvm/scummvm/commit/0bba925e9f732dc814d1daaefae93231bd9bf5a6
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-15T23:34:49-06:00
Commit Message:
ULTIMA8: Avoid color unpacking in minimap generation by using the RGB palette directly
Changed paths:
engines/ultima/ultima8/world/minimap.cpp
diff --git a/engines/ultima/ultima8/world/minimap.cpp b/engines/ultima/ultima8/world/minimap.cpp
index 6adc096cd55..c7f03c8e828 100644
--- a/engines/ultima/ultima8/world/minimap.cpp
+++ b/engines/ultima/ultima8/world/minimap.cpp
@@ -136,8 +136,10 @@ uint32 MiniMap::sampleAtPoint(const Item *item, int x, int y) {
if (!frame->hasPoint(i - sx, j - sy))
continue;
- byte r2, g2, b2;
- UNPACK_RGB8(pal->_native_untransformed[frame->getPixelAtPoint(i - sx, j - sy)], r2, g2, b2);
+ uint8 p = frame->getPixelAtPoint(i - sx, j - sy);
+ byte r2 = pal->_palette[p * 3 + 0];
+ byte g2 = pal->_palette[p * 3 + 1];
+ byte b2 = pal->_palette[p * 3 + 2];
r += RenderSurface::_gamma22toGamma10[r2];
g += RenderSurface::_gamma22toGamma10[g2];
b += RenderSurface::_gamma22toGamma10[b2];
Commit: 4088b9a4f0069eb94a81887d76e506afa93cefde
https://github.com/scummvm/scummvm/commit/4088b9a4f0069eb94a81887d76e506afa93cefde
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-15T23:34:49-06:00
Commit Message:
ULTIMA8: Combine RenderSurface and BaseSoftRenderSurface
In Pentgram RenderSurface was intended to be an interface with the possiblity of alternate implementations to the software-render derived classes. Removing this will allow for further removal of now-redundant code.
Changed paths:
R engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
R engines/ultima/ultima8/graphics/base_soft_render_surface.h
engines/ultima/module.mk
engines/ultima/ultima8/graphics/render_surface.cpp
engines/ultima/ultima8/graphics/render_surface.h
engines/ultima/ultima8/graphics/skf_player.h
engines/ultima/ultima8/graphics/soft_render_surface.cpp
engines/ultima/ultima8/graphics/soft_render_surface.h
diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index ef4975bda08..3a5fc5ed3a6 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -413,7 +413,6 @@ MODULE_OBJS := \
ultima8/games/u8_game.o \
ultima8/graphics/anim_dat.o \
ultima8/graphics/avi_player.o \
- ultima8/graphics/base_soft_render_surface.o \
ultima8/graphics/cycle_process.o \
ultima8/graphics/frame_id.o \
ultima8/graphics/fade_to_modal_process.o \
diff --git a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp b/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
deleted file mode 100644
index af6f1cbbdcf..00000000000
--- a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
+++ /dev/null
@@ -1,368 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "ultima/ultima8/misc/pent_include.h"
-#include "ultima/ultima8/graphics/soft_render_surface.h"
-#include "ultima/ultima8/graphics/palette.h"
-#include "ultima/ultima8/graphics/texture.h"
-#include "graphics/screen.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-///////////////////////////
-// //
-// BaseSoftRenderSurface //
-// //
-///////////////////////////
-
-//
-// BaseSoftRenderSurface::BaseSoftRenderSurface(Graphics::Surface *s)
-//
-// Desc: Constructor for BaseSoftRenderSurface from a managed surface
-//
-BaseSoftRenderSurface::BaseSoftRenderSurface(Graphics::ManagedSurface *s) :
- _pixels(nullptr), _pixels00(nullptr), _bytesPerPixel(0), _bitsPerPixel(0), _formatType(0),
- _ox(0), _oy(0), _width(0), _height(0), _pitch(0),
- _flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
- _surface(s) {
- _clipWindow.setWidth(_width = _surface->w);
- _clipWindow.setHeight(_height = _surface->h);
- _pitch = _surface->pitch;
- _bitsPerPixel = _surface->format.bpp();
- _bytesPerPixel = _surface->format.bytesPerPixel;
-
- // TODO: Slight hack - set the global surface format only once.
- if (!RenderSurface::_format->bytesPerPixel) {
- RenderSurface::_format->bytesPerPixel = _bytesPerPixel;
- RenderSurface::_format->rLoss = _surface->format.rLoss;
- RenderSurface::_format->gLoss = _surface->format.gLoss;
- RenderSurface::_format->bLoss = _surface->format.bLoss;
- RenderSurface::_format->aLoss = _surface->format.aLoss;
- RenderSurface::_format->rLoss16 = _format->rLoss + 8;
- RenderSurface::_format->gLoss16 = _format->gLoss + 8;
- RenderSurface::_format->bLoss16 = _format->bLoss + 8;
- RenderSurface::_format->aLoss16 = _format->aLoss + 8;
- RenderSurface::_format->rShift = _surface->format.rShift;
- RenderSurface::_format->gShift = _surface->format.gShift;
- RenderSurface::_format->bShift = _surface->format.bShift;
- RenderSurface::_format->aShift = _surface->format.aShift;
- RenderSurface::_format->rMask = _surface->format.rMax() << _surface->format.rShift;
- RenderSurface::_format->gMask = _surface->format.gMax() << _surface->format.gShift;
- RenderSurface::_format->bMask = _surface->format.bMax() << _surface->format.bShift;
- RenderSurface::_format->aMask = _surface->format.aMax() << _surface->format.aShift;
- }
-
- SetPixelsPointer();
-
- // Trickery to get the alpha channel
- if (_format->aMask == 0 && _bytesPerPixel == 4) {
- uint32 mask = ~(_format->rMask | _format->gMask | _format->bMask);
-
- // Using all bits????
- if (!mask) return;
-
- // Check the mask to make sure that it's 'sane'
- int i;
- int last = 0;
- int first = 0;
- int zero = 32;
-
- for (i = 0; i < 32; i++) {
- if ((1 << i) & mask) {
- last = first = i;
- break;
- }
- }
-
- for (; i < 32; i++) {
- if ((1 << i) & mask)
- last = i;
- else if (i < zero)
- zero = i;
- }
-
- // something screwy going on
- if (zero < last) return;
-
- // Set it
- _format->aShift = first;
- _format->aLoss = 8 - (last + 1 - first);
- _format->aLoss16 = _format->aLoss + 8;
- _format->aMask = mask;
- }
-}
-
-
-
-//
-// BaseSoftRenderSurface::~BaseSoftRenderSurface()
-//
-// Desc: Destructor
-//
-BaseSoftRenderSurface::~BaseSoftRenderSurface() {
-}
-
-
-//
-// BaseSoftRenderSurface::BeginPainting()
-//
-// Desc: Prepare the surface for drawing this frame (in effect lock it for drawing)
-// Returns: Non Zero on error
-//
-bool BaseSoftRenderSurface::BeginPainting() {
- if (!_lockCount) {
-
- if (_surface) {
- // Pixels pointer
- Graphics::Surface s = _surface->getSubArea(Common::Rect(0, 0, _surface->w, _surface->h));
- _pixels00 = static_cast<uint8 *>(s.getPixels());
-
- _pitch = _surface->pitch;
- if (_flipped) _pitch = -_pitch;
- }
- // else, nothing to lock.
- }
-
- _lockCount++;
-
- if (_pixels00 == nullptr) {
- error("Error: Surface Locked with NULL BaseSoftRenderSurface::_pixels pointer!");
- return false;
- }
-
- // Origin offset pointers
- SetPixelsPointer();
-
- // No error
- return true;
-}
-
-
-//
-// BaseSoftRenderSurface::EndPainting()
-//
-// Desc: Prepare the surface for drawing this frame (in effect lock it for drawing)
-// Returns: Non Zero on error
-//
-bool BaseSoftRenderSurface::EndPainting() {
- // Already Unlocked
- if (!_lockCount) {
- error("Error: BeginPainting()/EndPainting() Mismatch!");
- return false;
- }
-
- // Decrement counter
- --_lockCount;
-
- if (!_lockCount) {
- if (_surface) {
- // Clear pointers
- _pixels = _pixels00 = 0;
-
- // Render the screen if this is it (slight hack..)
- Graphics::Screen *screen = dynamic_cast<Graphics::Screen *>(_surface);
- if (screen)
- screen->update();
-
- }
- // else, nothing to unlock.
- }
-
- // No error
- return true;
-}
-
-//
-// void BaseSoftRenderSurface::CreateNativePalette(Palette* palette)
-//
-// Desc: Create a palette of colours native to the surface
-//
-void BaseSoftRenderSurface::CreateNativePalette(Palette *palette, int maxindex) {
- if (maxindex == 0)
- maxindex = 256;
- for (int i = 0; i < maxindex; i++) {
- int32 r, g, b;
-
- // Normal palette
- palette->_native_untransformed[i] = PACK_RGB8(palette->_palette[i * 3 + 0],
- palette->_palette[i * 3 + 1],
- palette->_palette[i * 3 + 2]);
-
- r = palette->_matrix[0] * palette->_palette[i * 3 + 0] +
- palette->_matrix[1] * palette->_palette[i * 3 + 1] +
- palette->_matrix[2] * palette->_palette[i * 3 + 2] +
- palette->_matrix[3] * 255;
- if (r < 0) r = 0;
- if (r > 0x7F800) r = 0x7F800;
-
- g = palette->_matrix[4] * palette->_palette[i * 3 + 0] +
- palette->_matrix[5] * palette->_palette[i * 3 + 1] +
- palette->_matrix[6] * palette->_palette[i * 3 + 2] +
- palette->_matrix[7] * 255;
- if (g < 0) g = 0;
- if (g > 0x7F800) g = 0x7F800;
-
- b = palette->_matrix[8] * palette->_palette[i * 3 + 0] +
- palette->_matrix[9] * palette->_palette[i * 3 + 1] +
- palette->_matrix[10] * palette->_palette[i * 3 + 2] +
- palette->_matrix[11] * 255;
- if (b < 0) b = 0;
- if (b > 0x7F800) b = 0x7F800;
-
- // Transformed normal palette
- // FIXME - Wont work on non SDL SRS Implementations
- palette->_native[i] = PACK_RGB8(static_cast<uint8>(r >> 11),
- static_cast<uint8>(g >> 11),
- static_cast<uint8>(b >> 11));
-
- // Transformed XFORM palette (Uses the TEX32 format)
- if (TEX32_A(palette->_xform_untransformed[i])) {
- r = palette->_matrix[0] * TEX32_R(palette->_xform_untransformed[i]) +
- palette->_matrix[1] * TEX32_G(palette->_xform_untransformed[i]) +
- palette->_matrix[2] * TEX32_B(palette->_xform_untransformed[i]) +
- palette->_matrix[3] * 255;
- if (r < 0) r = 0;
- if (r > 0x7F800) r = 0x7F800;
-
- g = palette->_matrix[4] * TEX32_R(palette->_xform_untransformed[i]) +
- palette->_matrix[5] * TEX32_G(palette->_xform_untransformed[i]) +
- palette->_matrix[6] * TEX32_B(palette->_xform_untransformed[i]) +
- palette->_matrix[7] * 255;
- if (g < 0) g = 0;
- if (g > 0x7F800) g = 0x7F800;
-
- b = palette->_matrix[8] * TEX32_R(palette->_xform_untransformed[i]) +
- palette->_matrix[9] * TEX32_G(palette->_xform_untransformed[i]) +
- palette->_matrix[10] * TEX32_B(palette->_xform_untransformed[i]) +
- palette->_matrix[11] * 255;
- if (b < 0) b = 0;
- if (b > 0x7F800) b = 0x7F800;
-
- palette->_xform[i] = TEX32_PACK_RGBA(static_cast<uint8>(r >> 11),
- static_cast<uint8>(g >> 11),
- static_cast<uint8>(b >> 11),
- TEX32_A(palette->_xform_untransformed[i]));
- } else
- palette->_xform[i] = 0;
- }
-}
-
-//
-// void BaseSoftRenderSurface::GetSurfaceDims(Rect &r)
-//
-// Desc: Get the Surface Dimentions (and logical origin)
-// r: Rect object to fill
-//
-void BaseSoftRenderSurface::GetSurfaceDims(Rect &r) const {
- r.moveTo(_ox, _oy);
- r.setWidth(_width);
- r.setHeight(_height);
-}
-
-//
-// void BaseSoftRenderSurface::SetOrigin(int32 x, int32 y)
-//
-// Desc: Set the Phyiscal Pixel to be the logical origin
-//
-void BaseSoftRenderSurface::SetOrigin(int32 x, int32 y) {
- // Adjust the clipping window
- _clipWindow.translate(_ox - x, _oy - y);
-
- // Set the origin
- _ox = x;
- _oy = y;
-
- // The new pointers
- SetPixelsPointer();
-}
-
-//
-// void BaseSoftRenderSurface::GetOrigin(int32 &x, int32 &y)
-//
-// Desc: Get the Phyiscal Pixel that is the logical origin
-//
-void BaseSoftRenderSurface::GetOrigin(int32 &x, int32 &y) const {
- // Set the origin
- x = _ox;
- y = _oy;
-}
-
-//
-// void BaseSoftRenderSurface::GetClippingRect(Rect &r)
-//
-// Desc: Get the Clipping Rectangle
-// r: Rect object to fill
-//
-void BaseSoftRenderSurface::GetClippingRect(Rect &r) const {
- r = _clipWindow;
-}
-
-//
-// void BaseSoftRenderSurface::GetClippingRect(Rect &r)
-//
-// Desc: Set the Clipping Rectangle
-// r: Rect object that contains new Clipping Rectangle
-//
-void BaseSoftRenderSurface::SetClippingRect(const Rect &r) {
- // What we need to do is to clip the clipping rect to the phyiscal screen
- _clipWindow = r;
- _clipWindow.clip(Rect(-_ox, -_oy, -_ox + _width, -_oy + _height));
-}
-
-//
-// void BaseSoftRenderSurface::SetFlipped(bool _flipped)
-//
-// Desc: Flip the surface
-//
-void BaseSoftRenderSurface::SetFlipped(bool wantFlipped) {
- // Flipping is not terrible complex
- // But is a bit of a pain to set up
-
- // First we check to see if we are currently _flipped
- if (wantFlipped == _flipped) return;
-
- _flipped = wantFlipped;
-
- // What we 'need' to do is negate the pitches, and flip the clipping window
- // We keep the 'origin' in the same position relative to the clipping window
-
- _oy -= _clipWindow.top;
- _clipWindow.setHeight(_height - _clipWindow.top + _clipWindow.height());
- _oy += _clipWindow.top;
-
- _pitch = -_pitch;
-
- SetPixelsPointer();
-
-}
-
-//
-// bool BaseSoftRenderSurface::IsFlipped() const
-//
-// Desc: Has the render surface been _flipped?
-//
-bool BaseSoftRenderSurface::IsFlipped() const {
- return _flipped;
-}
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
diff --git a/engines/ultima/ultima8/graphics/base_soft_render_surface.h b/engines/ultima/ultima8/graphics/base_soft_render_surface.h
deleted file mode 100644
index 8a85f5419e4..00000000000
--- a/engines/ultima/ultima8/graphics/base_soft_render_surface.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef ULTIMA8_GRAPHICS_BASESOFTRENDERSURFACE_H
-#define ULTIMA8_GRAPHICS_BASESOFTRENDERSURFACE_H
-
-#include "ultima/ultima8/graphics/render_surface.h"
-#include "ultima/ultima8/misc/rect.h"
-#include "graphics/managed_surface.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-//
-// Class BaseSoftRenderSurface
-//
-// Desc: The base abstact class for software rendering in Pentagram
-//
-class BaseSoftRenderSurface : public RenderSurface {
-protected:
- // Frame buffer
- uint8 *_pixels; // Pointer to logical pixel 0,0
- uint8 *_pixels00; // Pointer to physical pixel 0,0
-
- // Pixel Format (also see 'Colour shifting values' later)
- int _bytesPerPixel; // 2 or 4
- int _bitsPerPixel; // 16 or 32
- int _formatType; // 16, 555, 565, 32 or 888
-
- // Dimensions
- int32 _ox, _oy; // Physical Pixel for Logical Origin
- int32 _width, _height; // Width and height
- int32 _pitch; // Frame buffer pitch (bytes) (could be negated)
- bool _flipped;
-
- // Clipping Rectangle
- Rect _clipWindow;
-
- // Locking count
- uint32 _lockCount; // Number of locks on surface
-
- Graphics::ManagedSurface *_surface;
-
- // Create from a managed surface
- BaseSoftRenderSurface(Graphics::ManagedSurface *);
-
- // Update the Pixels Pointer
- void SetPixelsPointer() {
- uint8 *pix00 = _pixels00;
-
- if (_flipped) {
- pix00 += -_pitch * (_height - 1);
- }
-
- _pixels = pix00 + _ox * _bytesPerPixel + _oy * _pitch;
- }
-
-public:
-
- // Virtual Destructor
- ~BaseSoftRenderSurface() override;
-
- //
- // Being/End Painting
- //
-
- // Begin painting to the buffer. MUST BE CALLED BEFORE DOING ANYTHING TO THE SURFACE!
- // Can be called multiple times
- // Returns Error Code on error. Check return code.....
- bool BeginPainting() override;
-
- // Finish paining to the buffer. MUST BE CALLED FOR EACH CALL TO BeginPainting()
- // Returns Error Code on error. Check return code.....
- bool EndPainting() override;
-
- //
- // Surface Properties
- //
-
- // Set the Origin of the Surface
- void SetOrigin(int32 x, int32 y) override;
-
- // Set the Origin of the Surface
- void GetOrigin(int32 &x, int32 &y) const override;
-
- // Get the Surface Dimensions
- void GetSurfaceDims(Rect &) const override;
-
- // Get Clipping Rectangle
- void GetClippingRect(Rect &) const override;
-
- // Set Clipping Rectangle
- void SetClippingRect(const Rect &) override;
-
- // Flip the surface
- void SetFlipped(bool flipped) override;
-
- // Has the render surface been flipped?
- bool IsFlipped() const override;
-
- //
- // Surface Palettes
- //
- // TODO: Make a Palette class
- // TODO: Handle Ultima8 and Crusader Xforms
- //
-
- // Set The Surface Palette
- // virtual void SetPalette(uint8 palette[768]);
-
- // Set The Surface Palette to be the one used by another surface
- // TODO: virtual void SetPalette(RenderSurface &);
-
- // Get The Surface Palette
- // TODO: virtual void GetPalette(uint8 palette[768]);
-
- void CreateNativePalette(Palette *palette, int maxindex = 0) override;
-
- Graphics::ManagedSurface *getRawSurface() const override {
- return _surface;
- }
-};
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index a2e54a35ec2..f8b588592ad 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -21,6 +21,8 @@
#include "ultima/ultima8/misc/pent_include.h"
#include "ultima/ultima8/graphics/soft_render_surface.h"
+#include "ultima/ultima8/graphics/palette.h"
+#include "ultima/ultima8/graphics/texture.h"
#include "ultima/ultima8/ultima8.h"
#include "common/system.h"
#include "engines/util.h"
@@ -34,6 +36,340 @@ U8PixelFormat *RenderSurface::_format = nullptr;
uint8 RenderSurface::_gamma10toGamma22[256];
uint8 RenderSurface::_gamma22toGamma10[256];
+RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _pixels00(nullptr), _bytesPerPixel(0), _bitsPerPixel(0), _formatType(0),
+ _ox(0), _oy(0), _width(0), _height(0), _pitch(0),
+ _flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
+ _surface(s) {
+ _clipWindow.setWidth(_width = _surface->w);
+ _clipWindow.setHeight(_height = _surface->h);
+ _pitch = _surface->pitch;
+ _bitsPerPixel = _surface->format.bpp();
+ _bytesPerPixel = _surface->format.bytesPerPixel;
+
+ // TODO: Slight hack - set the global surface format only once.
+ if (!RenderSurface::_format->bytesPerPixel) {
+ RenderSurface::_format->bytesPerPixel = _bytesPerPixel;
+ RenderSurface::_format->rLoss = _surface->format.rLoss;
+ RenderSurface::_format->gLoss = _surface->format.gLoss;
+ RenderSurface::_format->bLoss = _surface->format.bLoss;
+ RenderSurface::_format->aLoss = _surface->format.aLoss;
+ RenderSurface::_format->rLoss16 = _format->rLoss + 8;
+ RenderSurface::_format->gLoss16 = _format->gLoss + 8;
+ RenderSurface::_format->bLoss16 = _format->bLoss + 8;
+ RenderSurface::_format->aLoss16 = _format->aLoss + 8;
+ RenderSurface::_format->rShift = _surface->format.rShift;
+ RenderSurface::_format->gShift = _surface->format.gShift;
+ RenderSurface::_format->bShift = _surface->format.bShift;
+ RenderSurface::_format->aShift = _surface->format.aShift;
+ RenderSurface::_format->rMask = _surface->format.rMax() << _surface->format.rShift;
+ RenderSurface::_format->gMask = _surface->format.gMax() << _surface->format.gShift;
+ RenderSurface::_format->bMask = _surface->format.bMax() << _surface->format.bShift;
+ RenderSurface::_format->aMask = _surface->format.aMax() << _surface->format.aShift;
+ }
+
+ SetPixelsPointer();
+
+ // Trickery to get the alpha channel
+ if (_format->aMask == 0 && _bytesPerPixel == 4) {
+ uint32 mask = ~(_format->rMask | _format->gMask | _format->bMask);
+
+ // Using all bits????
+ if (!mask)
+ return;
+
+ // Check the mask to make sure that it's 'sane'
+ int i;
+ int last = 0;
+ int first = 0;
+ int zero = 32;
+
+ for (i = 0; i < 32; i++) {
+ if ((1 << i) & mask) {
+ last = first = i;
+ break;
+ }
+ }
+
+ for (; i < 32; i++) {
+ if ((1 << i) & mask)
+ last = i;
+ else if (i < zero)
+ zero = i;
+ }
+
+ // something screwy going on
+ if (zero < last)
+ return;
+
+ // Set it
+ _format->aShift = first;
+ _format->aLoss = 8 - (last + 1 - first);
+ _format->aLoss16 = _format->aLoss + 8;
+ _format->aMask = mask;
+ }
+}
+
+//
+// RenderSurface::~RenderSurface()
+//
+// Desc: Destructor
+//
+RenderSurface::~RenderSurface() {
+}
+
+//
+// RenderSurface::BeginPainting()
+//
+// Desc: Prepare the surface for drawing this frame (in effect lock it for drawing)
+// Returns: Non Zero on error
+//
+bool RenderSurface::BeginPainting() {
+ if (!_lockCount) {
+
+ if (_surface) {
+ // Pixels pointer
+ Graphics::Surface s = _surface->getSubArea(Common::Rect(0, 0, _surface->w, _surface->h));
+ _pixels00 = static_cast<uint8 *>(s.getPixels());
+
+ _pitch = _surface->pitch;
+ if (_flipped)
+ _pitch = -_pitch;
+ }
+ // else, nothing to lock.
+ }
+
+ _lockCount++;
+
+ if (_pixels00 == nullptr) {
+ error("Error: Surface Locked with NULL RenderSurface::_pixels pointer!");
+ return false;
+ }
+
+ // Origin offset pointers
+ SetPixelsPointer();
+
+ // No error
+ return true;
+}
+
+//
+// RenderSurface::EndPainting()
+//
+// Desc: Prepare the surface for drawing this frame (in effect lock it for drawing)
+// Returns: Non Zero on error
+//
+bool RenderSurface::EndPainting() {
+ // Already Unlocked
+ if (!_lockCount) {
+ error("Error: BeginPainting()/EndPainting() Mismatch!");
+ return false;
+ }
+
+ // Decrement counter
+ --_lockCount;
+
+ if (!_lockCount) {
+ if (_surface) {
+ // Clear pointers
+ _pixels = _pixels00 = 0;
+
+ // Render the screen if this is it (slight hack..)
+ Graphics::Screen *screen = dynamic_cast<Graphics::Screen *>(_surface);
+ if (screen)
+ screen->update();
+ }
+ // else, nothing to unlock.
+ }
+
+ // No error
+ return true;
+}
+
+//
+// void RenderSurface::CreateNativePalette(Palette* palette)
+//
+// Desc: Create a palette of colours native to the surface
+//
+void RenderSurface::CreateNativePalette(Palette *palette, int maxindex) {
+ if (maxindex == 0)
+ maxindex = 256;
+ for (int i = 0; i < maxindex; i++) {
+ int32 r, g, b;
+
+ // Normal palette
+ palette->_native_untransformed[i] = PACK_RGB8(palette->_palette[i * 3 + 0],
+ palette->_palette[i * 3 + 1],
+ palette->_palette[i * 3 + 2]);
+
+ r = palette->_matrix[0] * palette->_palette[i * 3 + 0] +
+ palette->_matrix[1] * palette->_palette[i * 3 + 1] +
+ palette->_matrix[2] * palette->_palette[i * 3 + 2] +
+ palette->_matrix[3] * 255;
+ if (r < 0)
+ r = 0;
+ if (r > 0x7F800)
+ r = 0x7F800;
+
+ g = palette->_matrix[4] * palette->_palette[i * 3 + 0] +
+ palette->_matrix[5] * palette->_palette[i * 3 + 1] +
+ palette->_matrix[6] * palette->_palette[i * 3 + 2] +
+ palette->_matrix[7] * 255;
+ if (g < 0)
+ g = 0;
+ if (g > 0x7F800)
+ g = 0x7F800;
+
+ b = palette->_matrix[8] * palette->_palette[i * 3 + 0] +
+ palette->_matrix[9] * palette->_palette[i * 3 + 1] +
+ palette->_matrix[10] * palette->_palette[i * 3 + 2] +
+ palette->_matrix[11] * 255;
+ if (b < 0)
+ b = 0;
+ if (b > 0x7F800)
+ b = 0x7F800;
+
+ // Transformed normal palette
+ // FIXME - Wont work on non SDL SRS Implementations
+ palette->_native[i] = PACK_RGB8(static_cast<uint8>(r >> 11),
+ static_cast<uint8>(g >> 11),
+ static_cast<uint8>(b >> 11));
+
+ // Transformed XFORM palette (Uses the TEX32 format)
+ if (TEX32_A(palette->_xform_untransformed[i])) {
+ r = palette->_matrix[0] * TEX32_R(palette->_xform_untransformed[i]) +
+ palette->_matrix[1] * TEX32_G(palette->_xform_untransformed[i]) +
+ palette->_matrix[2] * TEX32_B(palette->_xform_untransformed[i]) +
+ palette->_matrix[3] * 255;
+ if (r < 0)
+ r = 0;
+ if (r > 0x7F800)
+ r = 0x7F800;
+
+ g = palette->_matrix[4] * TEX32_R(palette->_xform_untransformed[i]) +
+ palette->_matrix[5] * TEX32_G(palette->_xform_untransformed[i]) +
+ palette->_matrix[6] * TEX32_B(palette->_xform_untransformed[i]) +
+ palette->_matrix[7] * 255;
+ if (g < 0)
+ g = 0;
+ if (g > 0x7F800)
+ g = 0x7F800;
+
+ b = palette->_matrix[8] * TEX32_R(palette->_xform_untransformed[i]) +
+ palette->_matrix[9] * TEX32_G(palette->_xform_untransformed[i]) +
+ palette->_matrix[10] * TEX32_B(palette->_xform_untransformed[i]) +
+ palette->_matrix[11] * 255;
+ if (b < 0)
+ b = 0;
+ if (b > 0x7F800)
+ b = 0x7F800;
+
+ palette->_xform[i] = TEX32_PACK_RGBA(static_cast<uint8>(r >> 11),
+ static_cast<uint8>(g >> 11),
+ static_cast<uint8>(b >> 11),
+ TEX32_A(palette->_xform_untransformed[i]));
+ } else
+ palette->_xform[i] = 0;
+ }
+}
+
+//
+// void RenderSurface::GetSurfaceDims(Rect &r)
+//
+// Desc: Get the Surface Dimentions (and logical origin)
+// r: Rect object to fill
+//
+void RenderSurface::GetSurfaceDims(Rect &r) const {
+ r.moveTo(_ox, _oy);
+ r.setWidth(_width);
+ r.setHeight(_height);
+}
+
+//
+// void RenderSurface::SetOrigin(int32 x, int32 y)
+//
+// Desc: Set the Phyiscal Pixel to be the logical origin
+//
+void RenderSurface::SetOrigin(int32 x, int32 y) {
+ // Adjust the clipping window
+ _clipWindow.translate(_ox - x, _oy - y);
+
+ // Set the origin
+ _ox = x;
+ _oy = y;
+
+ // The new pointers
+ SetPixelsPointer();
+}
+
+//
+// void RenderSurface::GetOrigin(int32 &x, int32 &y)
+//
+// Desc: Get the Phyiscal Pixel that is the logical origin
+//
+void RenderSurface::GetOrigin(int32 &x, int32 &y) const {
+ // Set the origin
+ x = _ox;
+ y = _oy;
+}
+
+//
+// void RenderSurface::GetClippingRect(Rect &r)
+//
+// Desc: Get the Clipping Rectangle
+// r: Rect object to fill
+//
+void RenderSurface::GetClippingRect(Rect &r) const {
+ r = _clipWindow;
+}
+
+//
+// void RenderSurface::GetClippingRect(Rect &r)
+//
+// Desc: Set the Clipping Rectangle
+// r: Rect object that contains new Clipping Rectangle
+//
+void RenderSurface::SetClippingRect(const Rect &r) {
+ // What we need to do is to clip the clipping rect to the phyiscal screen
+ _clipWindow = r;
+ _clipWindow.clip(Rect(-_ox, -_oy, -_ox + _width, -_oy + _height));
+}
+
+//
+// void RenderSurface::SetFlipped(bool _flipped)
+//
+// Desc: Flip the surface
+//
+void RenderSurface::SetFlipped(bool wantFlipped) {
+ // Flipping is not terrible complex
+ // But is a bit of a pain to set up
+
+ // First we check to see if we are currently _flipped
+ if (wantFlipped == _flipped)
+ return;
+
+ _flipped = wantFlipped;
+
+ // What we 'need' to do is negate the pitches, and flip the clipping window
+ // We keep the 'origin' in the same position relative to the clipping window
+
+ _oy -= _clipWindow.top;
+ _clipWindow.setHeight(_height - _clipWindow.top + _clipWindow.height());
+ _oy += _clipWindow.top;
+
+ _pitch = -_pitch;
+
+ SetPixelsPointer();
+}
+
+//
+// bool RenderSurface::IsFlipped() const
+//
+// Desc: Has the render surface been _flipped?
+//
+bool RenderSurface::IsFlipped() const {
+ return _flipped;
+}
+
//
// RenderSurface::SetVideoMode()
//
@@ -88,9 +424,6 @@ RenderSurface *RenderSurface::CreateSecondaryRenderSurface(uint32 width, uint32
return surf;
}
-RenderSurface::~RenderSurface() {
-}
-
Graphics::PixelFormat RenderSurface::getPixelFormat() {
return g_system->getScreenFormat();
}
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index dfde77fe4a4..4ba0eccd110 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -24,6 +24,7 @@
#include "graphics/pixelformat.h"
#include "graphics/managed_surface.h"
+#include "ultima/ultima8/misc/rect.h"
namespace Ultima {
namespace Ultima8 {
@@ -62,6 +63,44 @@ struct U8PixelFormat : Graphics::PixelFormat {
// Desc: The base abstact class for rendering in Pentagram
//
class RenderSurface {
+protected:
+ // Frame buffer
+ uint8 *_pixels; // Pointer to logical pixel 0,0
+ uint8 *_pixels00; // Pointer to physical pixel 0,0
+
+ // Pixel Format (also see 'Colour shifting values' later)
+ int _bytesPerPixel; // 2 or 4
+ int _bitsPerPixel; // 16 or 32
+ int _formatType; // 16, 555, 565, 32 or 888
+
+ // Dimensions
+ int32 _ox, _oy; // Physical Pixel for Logical Origin
+ int32 _width, _height; // Width and height
+ int32 _pitch; // Frame buffer pitch (bytes) (could be negated)
+ bool _flipped;
+
+ // Clipping Rectangle
+ Rect _clipWindow;
+
+ // Locking count
+ uint32 _lockCount; // Number of locks on surface
+
+ Graphics::ManagedSurface *_surface;
+
+ // Create from a managed surface
+ RenderSurface(Graphics::ManagedSurface *);
+
+ // Update the Pixels Pointer
+ void SetPixelsPointer() {
+ uint8 *pix00 = _pixels00;
+
+ if (_flipped) {
+ pix00 += -_pitch * (_height - 1);
+ }
+
+ _pixels = pix00 + _ox * _bytesPerPixel + _oy * _pitch;
+ }
+
public:
static U8PixelFormat *_format;
@@ -86,40 +125,42 @@ public:
//! Begin painting to the buffer. MUST BE CALLED BEFORE DOING ANYTHING TO THE SURFACE!
// \note Can be called multiple times
// \return true on success, false on failure
- virtual bool BeginPainting() = 0;
+ virtual bool BeginPainting();
//! Finish paining to the buffer.
// \note MUST BE CALLED FOR EACH CALL TO BeginPainting()
// \return true on success, false on failure
- virtual bool EndPainting() = 0;
+ virtual bool EndPainting();
//
// Surface Properties
//
//! Set the Origin of the Surface
- virtual void SetOrigin(int32 x, int32 y) = 0;
+ virtual void SetOrigin(int32 x, int32 y);
//! Set the Origin of the Surface
- virtual void GetOrigin(int32 &x, int32 &y) const = 0;
+ virtual void GetOrigin(int32 &x, int32 &y) const;
//! Get the Surface Dimensions
- virtual void GetSurfaceDims(Rect &) const = 0;
+ virtual void GetSurfaceDims(Rect &) const;
//! Get Clipping Rectangle
- virtual void GetClippingRect(Rect &) const = 0;
+ virtual void GetClippingRect(Rect &) const;
//! Set Clipping Rectangle
- virtual void SetClippingRect(const Rect &) = 0;
+ virtual void SetClippingRect(const Rect &);
//! Flip the surface
- virtual void SetFlipped(bool flipped) = 0;
+ virtual void SetFlipped(bool flipped);
//! Has the render surface been flipped?
- virtual bool IsFlipped() const = 0;
+ virtual bool IsFlipped() const;
//! Get a reference to the underlying surface that's being encapsulated
- virtual Graphics::ManagedSurface *getRawSurface() const = 0;
+ virtual Graphics::ManagedSurface *getRawSurface() const {
+ return _surface;
+ };
//
// Surface Palettes
@@ -136,7 +177,7 @@ public:
// Get The Surface Palette
// TODO: virtual void GetPalette(uint8 palette[768]) = 0;
- virtual void CreateNativePalette(Palette *palette, int maxindex = 0) = 0;
+ virtual void CreateNativePalette(Palette *palette, int maxindex = 0);
//
diff --git a/engines/ultima/ultima8/graphics/skf_player.h b/engines/ultima/ultima8/graphics/skf_player.h
index 3f996b07f2f..14e32689ecc 100644
--- a/engines/ultima/ultima8/graphics/skf_player.h
+++ b/engines/ultima/ultima8/graphics/skf_player.h
@@ -24,7 +24,7 @@
#include "ultima/shared/std/containers.h"
#include "ultima/ultima8/graphics/movie_player.h"
-#include "ultima/ultima8/graphics/base_soft_render_surface.h"
+#include "ultima/ultima8/graphics/render_surface.h"
namespace Ultima {
namespace Ultima8 {
@@ -63,7 +63,7 @@ private:
unsigned int _timer;
unsigned int _frameRate;
uint8 _fadeColour, _fadeLevel;
- BaseSoftRenderSurface *_buffer;
+ RenderSurface *_buffer;
RenderedText *_subs;
int _subtitleY;
bool _introMusicHack;
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.cpp b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
index 31789cece10..38cd1eaf9e4 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.cpp
@@ -43,7 +43,7 @@ namespace Ultima8 {
// Desc: Create a SoftRenderSurface from a managed surface
//
template<class uintX> SoftRenderSurface<uintX>::SoftRenderSurface(Graphics::ManagedSurface *s)
- : BaseSoftRenderSurface(s) {
+ : RenderSurface(s) {
}
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.h b/engines/ultima/ultima8/graphics/soft_render_surface.h
index 79e3981fe1f..f7fe40d303e 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.h
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.h
@@ -22,7 +22,7 @@
#ifndef ULTIMA8_GRAPHICS_SOFTRENDERSURFACE_H
#define ULTIMA8_GRAPHICS_SOFTRENDERSURFACE_H
-#include "ultima/ultima8/graphics/base_soft_render_surface.h"
+#include "ultima/ultima8/graphics/render_surface.h"
#include "graphics/managed_surface.h"
namespace Ultima {
@@ -33,7 +33,7 @@ namespace Ultima8 {
//
// Desc: The class for software rendering in Pentagram
//
-template<class uintX> class SoftRenderSurface : public BaseSoftRenderSurface {
+template<class uintX> class SoftRenderSurface : public RenderSurface {
public:
// Create from a managed surface
Commit: 57e9b44a11823e0685deecf12b701693c75b157a
https://github.com/scummvm/scummvm/commit/57e9b44a11823e0685deecf12b701693c75b157a
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-15T23:34:49-06:00
Commit Message:
ULTIMA8: Remove unneeded variables from render surface
Changed paths:
engines/ultima/ultima8/graphics/render_surface.cpp
engines/ultima/ultima8/graphics/render_surface.h
diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index f8b588592ad..e7433d940e7 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -36,19 +36,17 @@ U8PixelFormat *RenderSurface::_format = nullptr;
uint8 RenderSurface::_gamma10toGamma22[256];
uint8 RenderSurface::_gamma22toGamma10[256];
-RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _pixels00(nullptr), _bytesPerPixel(0), _bitsPerPixel(0), _formatType(0),
- _ox(0), _oy(0), _width(0), _height(0), _pitch(0),
- _flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
- _surface(s) {
+RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _pixels00(nullptr),
+ _ox(0), _oy(0), _width(0), _height(0), _pitch(0),
+ _flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
+ _surface(s) {
_clipWindow.setWidth(_width = _surface->w);
_clipWindow.setHeight(_height = _surface->h);
_pitch = _surface->pitch;
- _bitsPerPixel = _surface->format.bpp();
- _bytesPerPixel = _surface->format.bytesPerPixel;
// TODO: Slight hack - set the global surface format only once.
if (!RenderSurface::_format->bytesPerPixel) {
- RenderSurface::_format->bytesPerPixel = _bytesPerPixel;
+ RenderSurface::_format->bytesPerPixel = _surface->format.bytesPerPixel;
RenderSurface::_format->rLoss = _surface->format.rLoss;
RenderSurface::_format->gLoss = _surface->format.gLoss;
RenderSurface::_format->bLoss = _surface->format.bLoss;
@@ -70,7 +68,7 @@ RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _p
SetPixelsPointer();
// Trickery to get the alpha channel
- if (_format->aMask == 0 && _bytesPerPixel == 4) {
+ if (_format->aMask == 0 && _surface->format.bytesPerPixel == 4) {
uint32 mask = ~(_format->rMask | _format->gMask | _format->bMask);
// Using all bits????
@@ -117,6 +115,17 @@ RenderSurface::RenderSurface(Graphics::ManagedSurface *s) : _pixels(nullptr), _p
RenderSurface::~RenderSurface() {
}
+void RenderSurface::SetPixelsPointer()
+{
+ uint8 *pix00 = _pixels00;
+
+ if (_flipped) {
+ pix00 += -_pitch * (_height - 1);
+ }
+
+ _pixels = pix00 + _ox * _surface->format.bytesPerPixel + _oy * _pitch;
+}
+
//
// RenderSurface::BeginPainting()
//
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 4ba0eccd110..8a9ea9d1a97 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -60,7 +60,7 @@ struct U8PixelFormat : Graphics::PixelFormat {
//
// RenderSurface
//
-// Desc: The base abstact class for rendering in Pentagram
+// Desc: The base class for rendering in Pentagram
//
class RenderSurface {
protected:
@@ -68,11 +68,6 @@ protected:
uint8 *_pixels; // Pointer to logical pixel 0,0
uint8 *_pixels00; // Pointer to physical pixel 0,0
- // Pixel Format (also see 'Colour shifting values' later)
- int _bytesPerPixel; // 2 or 4
- int _bitsPerPixel; // 16 or 32
- int _formatType; // 16, 555, 565, 32 or 888
-
// Dimensions
int32 _ox, _oy; // Physical Pixel for Logical Origin
int32 _width, _height; // Width and height
@@ -91,15 +86,7 @@ protected:
RenderSurface(Graphics::ManagedSurface *);
// Update the Pixels Pointer
- void SetPixelsPointer() {
- uint8 *pix00 = _pixels00;
-
- if (_flipped) {
- pix00 += -_pitch * (_height - 1);
- }
-
- _pixels = pix00 + _ox * _bytesPerPixel + _oy * _pitch;
- }
+ void SetPixelsPointer();
public:
static U8PixelFormat *_format;
More information about the Scummvm-git-logs
mailing list