mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Fix GL error when CopyToRDRAM a buffer with zero width or height.
This commit is contained in:
parent
1bf3b6e85a
commit
3d6a897c97
|
@ -935,7 +935,8 @@ void FrameBufferToRDRAM::Destroy() {
|
||||||
|
|
||||||
void FrameBufferToRDRAM::CopyToRDRAM(u32 _address)
|
void FrameBufferToRDRAM::CopyToRDRAM(u32 _address)
|
||||||
{
|
{
|
||||||
if (VI.width == 0 || frameBufferList().getCurrent() == NULL) // H width is zero or no current buffer. Don't copy
|
const u32 numPixels = VI.width * VI.height;
|
||||||
|
if (numPixels == 0 || frameBufferList().getCurrent() == NULL) // Incorrect buffer size or no current buffer. Don't copy
|
||||||
return;
|
return;
|
||||||
FrameBuffer *pBuffer = frameBufferList().findBuffer(_address);
|
FrameBuffer *pBuffer = frameBufferList().findBuffer(_address);
|
||||||
if (pBuffer == NULL || pBuffer->m_width < VI.width || pBuffer->m_isOBScreen)
|
if (pBuffer == NULL || pBuffer->m_width < VI.width || pBuffer->m_isOBScreen)
|
||||||
|
@ -967,13 +968,13 @@ void FrameBufferToRDRAM::CopyToRDRAM(u32 _address)
|
||||||
#ifndef GLES2
|
#ifndef GLES2
|
||||||
PBOBinder binder(GL_PIXEL_PACK_BUFFER, m_PBO);
|
PBOBinder binder(GL_PIXEL_PACK_BUFFER, m_PBO);
|
||||||
glReadPixels(0, 0, VI.width, VI.height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
glReadPixels(0, 0, VI.width, VI.height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||||
GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, VI.width * VI.height * 4, GL_MAP_READ_BIT);
|
GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, numPixels * 4, GL_MAP_READ_BIT);
|
||||||
if(pixelData == NULL)
|
if(pixelData == NULL)
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
m_curIndex = 0;
|
m_curIndex = 0;
|
||||||
const u32 nextIndex = 0;
|
const u32 nextIndex = 0;
|
||||||
GLubyte* pixelData = (GLubyte* )malloc(VI.width*VI.height*4);
|
GLubyte* pixelData = (GLubyte* )malloc(numPixels * 4);
|
||||||
if(pixelData == NULL)
|
if(pixelData == NULL)
|
||||||
return;
|
return;
|
||||||
glReadPixels( 0, 0, VI.width, VI.height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData );
|
glReadPixels( 0, 0, VI.width, VI.height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData );
|
||||||
|
@ -1112,7 +1113,8 @@ void DepthBufferToRDRAM::Destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
|
bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
|
||||||
if (VI.width == 0) // H width is zero. Don't copy
|
const u32 numPixels = VI.width * VI.height;
|
||||||
|
if (numPixels == 0) // Incorrect buffer size. Don't copy
|
||||||
return false;
|
return false;
|
||||||
FrameBuffer *pBuffer = frameBufferList().findBuffer(_address);
|
FrameBuffer *pBuffer = frameBufferList().findBuffer(_address);
|
||||||
if (pBuffer == NULL || pBuffer->m_width < VI.width || pBuffer->m_pDepthBuffer == NULL || !pBuffer->m_pDepthBuffer->m_cleared)
|
if (pBuffer == NULL || pBuffer->m_width < VI.width || pBuffer->m_pDepthBuffer == NULL || !pBuffer->m_pDepthBuffer->m_cleared)
|
||||||
|
@ -1120,7 +1122,7 @@ bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
|
||||||
|
|
||||||
DepthBuffer * pDepthBuffer = pBuffer->m_pDepthBuffer;
|
DepthBuffer * pDepthBuffer = pBuffer->m_pDepthBuffer;
|
||||||
const u32 address = pDepthBuffer->m_address;
|
const u32 address = pDepthBuffer->m_address;
|
||||||
if (address + VI.width*VI.height*2 > RDRAMSize)
|
if (address + numPixels * 2 > RDRAMSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (config.video.multisampling == 0)
|
if (config.video.multisampling == 0)
|
||||||
|
@ -1142,7 +1144,7 @@ bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO);
|
||||||
glReadPixels(0, 0, VI.width, VI.height, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
glReadPixels(0, 0, VI.width, VI.height, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
||||||
|
|
||||||
GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, VI.width * VI.height * 4, GL_MAP_READ_BIT);
|
GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, numPixels * 4, GL_MAP_READ_BIT);
|
||||||
if(pixelData == NULL)
|
if(pixelData == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user