Skip to content

Commit

Permalink
Merge pull request #1409 from lioncash/err
Browse files Browse the repository at this point in the history
OGL: Get rid of error macros
  • Loading branch information
skidau committed Oct 28, 2014
2 parents 3f7a6e3 + 49b94e5 commit 726a3ac
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 161 deletions.
3 changes: 0 additions & 3 deletions Source/Core/VideoBackends/OGL/FramebufferManager.cpp
Expand Up @@ -135,7 +135,6 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_resolvedColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_resolvedDepthTexture, 0);
GL_REPORT_FBO_ERROR();
}

// Create XFB framebuffer; targets will be created elsewhere.
Expand All @@ -146,7 +145,6 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureType, m_efbColor, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_textureType, m_efbDepth, 0);
GL_REPORT_FBO_ERROR();

// EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f
glViewport(0, 0, m_targetWidth, m_targetHeight);
Expand Down Expand Up @@ -400,7 +398,6 @@ void XFBSource::CopyEFB(float Gamma)

// Bind texture.
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GL_REPORT_FBO_ERROR();

glBlitFramebuffer(
0, 0, texWidth, texHeight,
Expand Down
43 changes: 0 additions & 43 deletions Source/Core/VideoBackends/OGL/GLUtil.cpp
Expand Up @@ -113,46 +113,3 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade
return programID;
}


GLenum OpenGL_ReportGLError(const char *function, const char *file, int line)
{
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL error 0x%x\n",
file, line, function, err);
}
return err;
}

bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
{
GLenum fbo_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fbo_status != GL_FRAMEBUFFER_COMPLETE)
{
const char *error = "unknown error";
switch (fbo_status)
{
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
error = "INCOMPLETE_ATTACHMENT";
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
error = "INCOMPLETE_MISSING_ATTACHMENT";
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
error = "INCOMPLETE_DRAW_BUFFER";
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
error = "INCOMPLETE_READ_BUFFER";
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
error = "UNSUPPORTED";
break;
}
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL FBO error - %s\n",
file, line, function, error);
return false;
}
return true;
}

14 changes: 0 additions & 14 deletions Source/Core/VideoBackends/OGL/GLUtil.h
Expand Up @@ -18,20 +18,6 @@ void InitInterface();
// Helpers
GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader);

// Error reporting - use the convenient macros.
GLenum OpenGL_ReportGLError(const char *function, const char *file, int line);
bool OpenGL_ReportFBOError(const char *function, const char *file, int line);

#if defined(_DEBUG) || defined(DEBUGFAST)
#define GL_REPORT_ERROR() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__)
#define GL_REPORT_ERRORD() OpenGL_ReportGLError(__FUNCTION__, __FILE__, __LINE__)
#define GL_REPORT_FBO_ERROR() OpenGL_ReportFBOError(__FUNCTION__, __FILE__, __LINE__)
#else
__forceinline GLenum GL_REPORT_ERROR() { return GL_NO_ERROR; }
#define GL_REPORT_ERRORD() (void)GL_NO_ERROR
#define GL_REPORT_FBO_ERROR() (void)true
#endif

// this should be removed in future, but as long as glsl is unstable, we should really read this messages
#if defined(_DEBUG) || defined(DEBUGFAST)
#define DEBUG_GLSL 1
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
Expand Up @@ -357,7 +357,7 @@ GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const char* code)
glDeleteShader(result);
return 0;
}
(void)GL_REPORT_ERROR();

return result;
}

Expand Down
59 changes: 16 additions & 43 deletions Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -878,8 +878,6 @@ void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight, color);

GL_REPORT_ERRORD();
}

TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
Expand Down Expand Up @@ -1015,7 +1013,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)

glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, depthMap);
GL_REPORT_ERRORD();

UpdateEFBCache(type, cacheRectIdx, efbPixelRc, targetPixelRc, depthMap);

Expand Down Expand Up @@ -1073,7 +1070,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
else
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, colorMap);
GL_REPORT_ERRORD();

UpdateEFBCache(type, cacheRectIdx, efbPixelRc, targetPixelRc, colorMap);

Expand Down Expand Up @@ -1409,8 +1405,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
std::swap(flipped_trc.top, flipped_trc.bottom);
}

GL_REPORT_ERRORD();

// Copy the framebuffer to screen.
const XFBSource* xfbSource = nullptr;

Expand Down Expand Up @@ -1501,7 +1495,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
if (GL_REPORT_ERROR() == GL_NO_ERROR && w > 0 && h > 0)
if (w > 0 && h > 0)
{
if (!bLastFrameDumped)
{
Expand Down Expand Up @@ -1559,29 +1553,27 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
frame_data.resize(3 * w * h);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
if (GL_REPORT_ERROR() == GL_NO_ERROR)

if (!bLastFrameDumped)
{
if (!bLastFrameDumped)
movie_file_name = File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump.raw";
pFrameDump.Open(movie_file_name, "wb");
if (!pFrameDump)
{
movie_file_name = File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump.raw";
pFrameDump.Open(movie_file_name, "wb");
if (!pFrameDump)
{
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
}
else
{
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h), 2000);
}
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
}
if (pFrameDump)
else
{
FlipImageData(&frame_data[0], w, h);
pFrameDump.WriteBytes(&frame_data[0], w * 3 * h);
pFrameDump.Flush();
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h), 2000);
}
bLastFrameDumped = true;
}
if (pFrameDump)
{
FlipImageData(&frame_data[0], w, h);
pFrameDump.WriteBytes(&frame_data[0], w * 3 * h);
pFrameDump.Flush();
}
bLastFrameDumped = true;
}
else
{
Expand Down Expand Up @@ -1638,32 +1630,24 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
// ---------------------------------------------------------------------
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENSWAP))
{
GL_REPORT_ERRORD();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

DrawDebugInfo();
DrawDebugText();

GL_REPORT_ERRORD();

// Do our OSD callbacks
OSD::DoCallbacks(OSD::OSD_ONFRAME);
OSD::DrawMessages();
GL_REPORT_ERRORD();
}
// Copy the rendered frame to the real window
GLInterface->Swap();

GL_REPORT_ERRORD();

// Clear framebuffer
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENSWAP))
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GL_REPORT_ERRORD();
}

if (s_vsync != g_ActiveConfig.IsVSync())
Expand All @@ -1678,11 +1662,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
// Render to the framebuffer.
FramebufferManager::SetFramebuffer(0);

GL_REPORT_ERRORD();

RestoreAPIState();

GL_REPORT_ERRORD();
g_Config.iSaveTargetId = 0;

UpdateActiveConfig();
Expand Down Expand Up @@ -1875,14 +1856,6 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle

glReadPixels(back_rc.left, back_rc.bottom, W, H, GL_RGBA, GL_UNSIGNED_BYTE, data);

// Show failure message
if (GL_REPORT_ERROR() != GL_NO_ERROR)
{
delete[] data;
OSD::AddMessage("Error capturing or saving screenshot.", 2000);
return false;
}

// Turn image upside down
FlipImageData(data, W, H, 4);
bool success = TextureToPng(data, W*4, filename, W, H, false);
Expand Down
22 changes: 0 additions & 22 deletions Source/Core/VideoBackends/OGL/TextureCache.cpp
Expand Up @@ -60,13 +60,6 @@ bool SaveTexture(const std::string& filename, u32 textarget, u32 tex, int virtua
glBindTexture(textarget, 0);
TextureCache::SetStage();

const GLenum err = GL_REPORT_ERROR();
if (GL_NO_ERROR != err)
{
PanicAlert("Can't save texture, GL Error: %d", err);
return false;
}

return TextureToPng(data.data(), width * 4, filename, width, height, true);
}

Expand All @@ -91,7 +84,6 @@ TextureCache::TCacheEntry::~TCacheEntry()
TextureCache::TCacheEntry::TCacheEntry()
{
glGenTextures(1, &texture);
GL_REPORT_ERRORD();

framebuffer = 0;
}
Expand Down Expand Up @@ -214,7 +206,6 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
//width, height, 0, expanded_width * expanded_height/2, temp);
}
TextureCache::SetStage();
GL_REPORT_ERRORD();
}

TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
Expand All @@ -223,7 +214,6 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
TCacheEntry *const entry = new TCacheEntry;
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D, entry->texture);
GL_REPORT_ERRORD();

const GLenum
gl_format = GL_RGBA,
Expand All @@ -238,12 +228,9 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
glGenFramebuffers(1, &entry->framebuffer);
FramebufferManager::SetFramebuffer(entry->framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, entry->texture, 0);
GL_REPORT_FBO_ERROR();

SetStage();

GL_REPORT_ERRORD();

return entry;
}

Expand All @@ -259,14 +246,10 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
FramebufferManager::ResolveAndGetDepthTarget(srcRect) :
FramebufferManager::ResolveAndGetRenderTarget(srcRect);

GL_REPORT_ERRORD();

if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
{
FramebufferManager::SetFramebuffer(framebuffer);

GL_REPORT_ERRORD();

glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D, read_texture);

Expand All @@ -293,11 +276,8 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);
glUniform4f(uniform_location, static_cast<float>(R.left), static_cast<float>(R.top),
static_cast<float>(R.right), static_cast<float>(R.bottom));
GL_REPORT_ERRORD();

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

GL_REPORT_ERRORD();
}

if (false == g_ActiveConfig.bCopyEFBToTexture)
Expand Down Expand Up @@ -325,8 +305,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo

FramebufferManager::SetFramebuffer(0);

GL_REPORT_ERRORD();

if (g_ActiveConfig.bDumpEFBTarget)
{
static int count = 0;
Expand Down
12 changes: 0 additions & 12 deletions Source/Core/VideoBackends/OGL/TextureConverter.cpp
Expand Up @@ -221,7 +221,6 @@ static void EncodeToRamUsingShader(GLuint srcTexture,
// switch to texture converter frame buffer
// attach render buffer as color destination
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[0]);
GL_REPORT_ERRORD();

// set source texture
glActiveTexture(GL_TEXTURE0+9);
Expand All @@ -238,14 +237,10 @@ static void EncodeToRamUsingShader(GLuint srcTexture,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}

GL_REPORT_ERRORD();

glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

GL_REPORT_ERRORD();

// .. and then read back the results.
// TODO: make this less slow.

Expand Down Expand Up @@ -280,9 +275,6 @@ static void EncodeToRamUsingShader(GLuint srcTexture,
{
glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr);
}

GL_REPORT_ERRORD();

}

int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
Expand Down Expand Up @@ -355,7 +347,6 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
FramebufferManager::SetFramebuffer(0);
TextureCache::DisableStage(0);
g_renderer->RestoreAPIState();
GL_REPORT_ERRORD();
}


Expand All @@ -376,8 +367,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[1]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTexture, 0);

GL_REPORT_FBO_ERROR();

// activate source texture
// set srcAddr as data for source texture
glActiveTexture(GL_TEXTURE0+9);
Expand All @@ -392,7 +381,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
FramebufferManager::SetFramebuffer(0);

g_renderer->RestoreAPIState();
GL_REPORT_ERRORD();
}

} // namespace
Expand Down

0 comments on commit 726a3ac

Please sign in to comment.