Failure to allocate memory is fatal -> no need to handle this

This commit is contained in:
Jens Hemprich 2007-02-26 13:18:21 +00:00
parent 70e3fd1aec
commit 0bb2b8d61a
1 changed files with 16 additions and 14 deletions

View File

@ -68,23 +68,24 @@ grLfbLock( GrLock_t dwType,
// Alloc readbuffer // Alloc readbuffer
if (Glide.ReadBuffer.Address == NULL) if (Glide.ReadBuffer.Address == NULL)
{ {
Glide.ReadBuffer.Address = (FxU16*) AllocFrameBuffer(Glide.WindowWidth * Glide.WindowHeight, sizeof(FxU16)); Glide.ReadBuffer.Address = (FxU16*) AllocFrameBuffer(Glide.WindowTotalPixels, sizeof(FxU16));
#ifdef OPENGL_DEBUG #ifdef OPENGL_DEBUG
GlideMsg("Allocated Readbuffer(%dx%d) at 0x%x\n", GlideMsg("Allocated Readbuffer(%dx%d) at 0x%x\n",
Glide.WindowWidth, Glide.WindowHeight, Glide.ReadBuffer.Address); Glide.WindowWidth, Glide.WindowHeight, Glide.ReadBuffer.Address);
#endif #endif
} }
// select main memory buffers // select main memory buffers
BufferStruct* targetbuffer = Glide.ReadBuffer.Address ? &Glide.ReadBuffer : &Glide.TempBuffer; // @todo Remove conditions for NULL ReadBuffer (usage of FrameBuffer as source is wrong because it might be 16bit only)
BufferStruct* sourcebuffer = Glide.ReadBuffer.Address ? &Glide.TempBuffer : &Glide.FrameBuffer; BufferStruct* targetbuffer = &Glide.ReadBuffer;
const BufferStruct* sourcebuffer = &Glide.TempBuffer;
if (s_Framebuffer.GetRenderBufferChangedForRead() == true) if (s_Framebuffer.GetRenderBufferChangedForRead() == true)
{ {
// select buffer size // select buffer size
unsigned long bufferwidth = Glide.ReadBuffer.Address ? OpenGL.WindowWidth : Glide.WindowWidth; const unsigned long bufferwidth = OpenGL.WindowWidth;
unsigned long bufferheight = Glide.ReadBuffer.Address ? OpenGL.WindowHeight : Glide.WindowHeight; const unsigned long bufferheight = OpenGL.WindowHeight;
glReadBuffer(dwBuffer == GR_BUFFER_BACKBUFFER ? GL_BACK : GL_FRONT); glReadBuffer(dwBuffer == GR_BUFFER_BACKBUFFER ? GL_BACK : GL_FRONT);
glReportError(); glReportError();
bool scale = bufferwidth != Glide.WindowWidth || bufferheight != Glide.WindowHeight; const bool scale = bufferwidth != Glide.WindowWidth || bufferheight != Glide.WindowHeight;
GLint glWriteMode; GLint glWriteMode;
switch (dwWriteMode) switch (dwWriteMode)
{ {
@ -92,6 +93,7 @@ grLfbLock( GrLock_t dwType,
case GR_LFBWRITEMODE_565: glWriteMode = GL_UNSIGNED_SHORT_5_6_5; break; case GR_LFBWRITEMODE_565: glWriteMode = GL_UNSIGNED_SHORT_5_6_5; break;
default: glWriteMode = GL_UNSIGNED_SHORT_5_6_5; break; default: glWriteMode = GL_UNSIGNED_SHORT_5_6_5; break;
} }
// The read buffer is sized for Glide pixels. As a result we cannot be used it when the read buffer has to be resized
void* destination = (!scale && dwOrigin == GR_ORIGIN_LOWER_LEFT) ? targetbuffer->Address : sourcebuffer->Address; void* destination = (!scale && dwOrigin == GR_ORIGIN_LOWER_LEFT) ? targetbuffer->Address : sourcebuffer->Address;
#ifdef OPENGL_DEBUG #ifdef OPENGL_DEBUG
GlideMsg("Calling glReadPixels(%d, %d, 0x%x)\n", bufferwidth, bufferheight, destination); GlideMsg("Calling glReadPixels(%d, %d, 0x%x)\n", bufferwidth, bufferheight, destination);
@ -105,7 +107,7 @@ grLfbLock( GrLock_t dwType,
#ifdef OPENGL_DEBUG #ifdef OPENGL_DEBUG
if (scale) if (scale)
GlideMsg("Scaling to (%d, %d) from 0x%x to 0x%x\n", GlideMsg("Scaling to (%d, %d) from 0x%x to 0x%x\n",
Glide.WindowWidth, Glide.WindowHeight, sourcebuffer->Address, targetbuffer->Address); Glide.WindowWidth, Glide.WindowHeight, sourcebuffer->Address, targetbuffer->Address);
#endif #endif
if (dwOrigin == GR_ORIGIN_UPPER_LEFT) if (dwOrigin == GR_ORIGIN_UPPER_LEFT)
{ {
@ -114,10 +116,10 @@ grLfbLock( GrLock_t dwType,
if (scale) if (scale)
{ {
// size/copy from OpenGL-sized buffer to Glide-sized buffer? // size/copy from OpenGL-sized buffer to Glide-sized buffer?
FxU16* src; const FxU16* src;
FxU16* dst = targetbuffer->Address; FxU16* dst = targetbuffer->Address;
int xratio = (bufferwidth << 16) / (Glide.WindowWidth); const int xratio = (bufferwidth << 16) / (Glide.WindowWidth);
int yratio = (bufferheight << 16) / (Glide.WindowHeight); const int yratio = (bufferheight << 16) / (Glide.WindowHeight);
int u; int u;
int v = 0; int v = 0;
int x; int x;
@ -155,10 +157,10 @@ grLfbLock( GrLock_t dwType,
if (scale) if (scale)
{ {
// Copy and scale // Copy and scale
FxU16* src; const FxU16* src;
FxU16* dst = targetbuffer->Address; FxU16* dst = targetbuffer->Address;
int xratio = (bufferwidth << 16) / Glide.WindowWidth; const int xratio = (bufferwidth << 16) / Glide.WindowWidth;
int yratio = (bufferheight << 16) / Glide.WindowHeight; const int yratio = (bufferheight << 16) / Glide.WindowHeight;
int u; int u;
int v = 0; int v = 0;
int x; int x;