Skip to content

Commit

Permalink
Engine: small fixes to comments regarding color depth in code
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Aug 15, 2024
1 parent 6d6dc4d commit 9c09ae9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
9 changes: 4 additions & 5 deletions Engine/ac/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ void tint_image (Bitmap *ds, Bitmap *srcimg, int red, int grn, int blu, int ligh

if ((srcimg->GetColorDepth() != ds->GetColorDepth()) ||
(srcimg->GetColorDepth() <= 8)) {
debug_script_warn("Image tint failed - images must both be hi-color");
debug_script_warn("Image tint failed - images must both be same color depth and not 8-bit");
// the caller expects something to have been copied
ds->Blit(srcimg, 0, 0, 0, 0, srcimg->GetWidth(), srcimg->GetHeight());
return;
Expand Down Expand Up @@ -2261,10 +2261,9 @@ PBitmap draw_room_background(Viewport *view)

// For the sake of software renderer, if there is any kind of camera transform required
// except screen offset, we tell it to draw on separate bitmap first with zero transformation.
// There are few reasons for this, primary is that Allegro does not support StretchBlt
// between different colour depths (i.e. it won't correctly stretch blit 16-bit rooms to
// 32-bit virtual screen).
// Also see comment to ALSoftwareGraphicsDriver::RenderToBackBuffer().
// There have been few reasons for this in the past, primary being that Allegro does not support
// StretchBlt between different colour depths, but that one may be not relevant now.
// See Also: comment inside ALSoftwareGraphicsDriver::RenderToBackBuffer().
const int view_index = view->GetID();
Bitmap *ds = gfxDriver->GetMemoryBackBuffer();
// If separate bitmap was prepared for this view/camera pair then use it, draw untransformed
Expand Down
1 change: 1 addition & 0 deletions Engine/ac/global_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern RGB palette[256];
void CyclePalette(int strt,int eend) {
// hi-color game must invalidate screen since the palette changes
// the effect of the drawing operations
// FIXME: this is likely wrong, it should also/instead test the graphic driver capabilities?
if (game.color_depth > 1)
invalidate_screen();

Expand Down
14 changes: 4 additions & 10 deletions Engine/gfx/ali3dogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,10 @@ bool OGLGraphicsDriver::GetCopyOfScreenIntoBitmap(Bitmap *destination,
Rect copy_from = src_rect ? *src_rect : _srcRect;
if (!at_native_res)
copy_from = _scaling.ScaleRange(copy_from);

// TODO: following implementation currently only reads GL pixels in 32-bit RGBA.
// this **should** work regardless of actual display mode because OpenGL is
// responsible to convert and fill pixel buffer correctly.
// If you like to support writing directly into 16-bit bitmap, please take
// care of ammending the pixel reading code below.
const int read_in_colordepth = 32;
if (destination->GetColorDepth() != read_in_colordepth || destination->GetSize() != copy_from.GetSize())
if (destination->GetColorDepth() != _mode.ColorDepth || destination->GetSize() != copy_from.GetSize())
{
if (want_fmt)
*want_fmt = GraphicResolution(copy_from.GetWidth(), copy_from.GetHeight(), read_in_colordepth);
*want_fmt = GraphicResolution(copy_from.GetWidth(), copy_from.GetHeight(), _mode.ColorDepth);
return false;
}

Expand Down Expand Up @@ -946,7 +939,8 @@ bool OGLGraphicsDriver::GetCopyOfScreenIntoBitmap(Bitmap *destination,
}

// Retrieve the backbuffer pixels
const int bpp = read_in_colordepth / 8;
// NOTE: this is currently hardcoded to read from a 32-bit display mode
const int bpp = 32 / 8;
const int buf_sz = copy_from.GetWidth() * copy_from.GetHeight() * bpp;
std::vector<uint8_t> buffer(buf_sz);
glReadPixels(copy_from.Left, copy_from.Top, copy_from.GetWidth(), copy_from.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &buffer.front());
Expand Down

0 comments on commit 9c09ae9

Please sign in to comment.