2008-07-12 17:40:22 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
#include "Globals.h"
|
|
|
|
#include <list>
|
2008-10-20 22:31:55 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2008-10-22 21:02:37 +00:00
|
|
|
#include "GLUtil.h"
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
#include <Cg/cg.h>
|
|
|
|
#include <Cg/cgGL.h>
|
|
|
|
|
2008-08-17 03:56:07 +00:00
|
|
|
#ifdef _WIN32
|
2008-08-16 21:58:07 +00:00
|
|
|
#include <mmsystem.h>
|
2008-08-17 03:56:07 +00:00
|
|
|
#endif
|
2008-08-16 21:58:07 +00:00
|
|
|
|
2008-10-22 21:23:40 +00:00
|
|
|
#include "Config.h"
|
2008-08-30 22:06:53 +00:00
|
|
|
#include "Profiler.h"
|
2008-10-22 20:54:40 +00:00
|
|
|
#include "Statistics.h"
|
2008-10-17 11:30:14 +00:00
|
|
|
#include "ImageWrite.h"
|
2008-07-17 09:18:03 +00:00
|
|
|
#include "Render.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "TextureMngr.h"
|
|
|
|
#include "rasterfont.h"
|
|
|
|
#include "VertexShader.h"
|
2008-07-17 21:09:18 +00:00
|
|
|
#include "PixelShaderManager.h"
|
2008-11-25 21:15:31 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
2008-07-17 09:18:03 +00:00
|
|
|
#include "VertexLoader.h"
|
2008-08-14 21:34:39 +00:00
|
|
|
#include "XFB.h"
|
2008-10-25 17:47:46 +00:00
|
|
|
#if !defined(OSX64)
|
2008-10-09 18:47:53 +00:00
|
|
|
#include "Debugger/Debugger.h" // for the CDebugger class
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-10-09 18:47:53 +00:00
|
|
|
#include "Logging/Logging.h" // for Logging()
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-08-26 23:32:54 +00:00
|
|
|
#include "OS/Win32.h"
|
2008-07-17 09:18:03 +00:00
|
|
|
#else
|
|
|
|
#endif
|
2008-11-28 13:23:29 +00:00
|
|
|
//#define USE_AA
|
2008-12-02 01:08:21 +00:00
|
|
|
#define AA_AMMOUNT 16
|
2008-07-17 09:18:03 +00:00
|
|
|
struct MESSAGE
|
|
|
|
{
|
|
|
|
MESSAGE() {}
|
|
|
|
MESSAGE(const char* p, u32 dw) { strcpy(str, p); dwTimeStamp = dw; }
|
|
|
|
char str[255];
|
|
|
|
u32 dwTimeStamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
CGcontext g_cgcontext;
|
|
|
|
CGprofile g_cgvProf, g_cgfProf;
|
2008-10-25 17:47:46 +00:00
|
|
|
#if !defined(OSX64)
|
2008-10-09 18:47:53 +00:00
|
|
|
extern CDebugger* m_frame; // the debugging class
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
static int g_MaxTexWidth = 0, g_MaxTexHeight = 0;
|
|
|
|
static RasterFont* s_pfont = NULL;
|
|
|
|
static std::list<MESSAGE> s_listMsgs;
|
|
|
|
static bool s_bFullscreen = false;
|
|
|
|
static bool s_bOutputCgErrors = true;
|
2008-11-28 13:23:29 +00:00
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
static int nZBufferRender = 0; // if > 0, then using zbuffer render
|
|
|
|
static u32 s_uFramebuffer = 0;
|
|
|
|
static u32 s_RenderTargets[1] = {0}, s_DepthTarget = 0, s_ZBufferTarget = 0;
|
2008-08-14 21:34:39 +00:00
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
static bool s_bATIDrawBuffers = false, s_bHaveStencilBuffer = false;
|
|
|
|
static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal;
|
|
|
|
static int s_nCurTarget = 0;
|
|
|
|
bool g_bBlendLogicOp = false;
|
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
float MValueX, MValueY; // Since it can Stretch to fit Window, we need two different multiplication values
|
|
|
|
int frameCount;
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
void HandleCgError(CGcontext ctx, CGerror err, void* appdata);
|
|
|
|
|
|
|
|
bool Renderer::Create2()
|
|
|
|
{
|
|
|
|
bool bSuccess = true;
|
|
|
|
GLenum err = GL_NO_ERROR;
|
|
|
|
g_cgcontext = cgCreateContext();
|
|
|
|
cgGetError();
|
|
|
|
cgSetErrorHandler(HandleCgError, NULL);
|
|
|
|
|
|
|
|
// fill the opengl extension map
|
|
|
|
const char* ptoken = (const char*)glGetString( GL_EXTENSIONS );
|
|
|
|
if (ptoken == NULL) return false;
|
|
|
|
|
|
|
|
__Log("Supported OpenGL Extensions:\n");
|
|
|
|
__Log(ptoken); // write to the log file
|
|
|
|
__Log("\n");
|
|
|
|
|
|
|
|
if( strstr(ptoken, "GL_EXT_blend_logic_op") != NULL )
|
|
|
|
g_bBlendLogicOp = true;
|
2008-09-13 05:41:26 +00:00
|
|
|
if( strstr(ptoken, "ATI_draw_buffers") != NULL && strstr(ptoken, "ARB_draw_buffers") == NULL)
|
|
|
|
//Checks if it ONLY has the ATI_draw_buffers extension, some have both
|
2008-07-17 09:18:03 +00:00
|
|
|
s_bATIDrawBuffers = true;
|
|
|
|
|
|
|
|
s_bFullscreen = g_Config.bFullscreen;
|
|
|
|
|
|
|
|
if (glewInit() != GLEW_OK) {
|
|
|
|
ERROR_LOG("glewInit() failed!\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GLEW_EXT_framebuffer_object) {
|
|
|
|
ERROR_LOG("*********\nGPU: ERROR: Need GL_EXT_framebufer_object for multiple render targets\nGPU: *********\n");
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GLEW_EXT_secondary_color) {
|
|
|
|
ERROR_LOG("*********\nGPU: OGL ERROR: Need GL_EXT_secondary_color\nGPU: *********\n");
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int numvertexattribs=0;
|
2008-08-06 21:07:31 +00:00
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)&numvertexattribs);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
if (numvertexattribs < 11) {
|
|
|
|
ERROR_LOG("*********\nGPU: OGL ERROR: Number of attributes %d not enough\nGPU: *********\n", numvertexattribs);
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (WGLEW_EXT_swap_control)
|
|
|
|
wglSwapIntervalEXT(0);
|
|
|
|
else
|
|
|
|
ERROR_LOG("no support for SwapInterval (framerate clamped to monitor refresh rate)\n");
|
2008-08-13 00:00:39 +00:00
|
|
|
#else
|
|
|
|
#ifdef __linux__
|
2008-07-17 09:18:03 +00:00
|
|
|
if (glXSwapIntervalSGI)
|
2008-08-06 21:07:31 +00:00
|
|
|
glXSwapIntervalSGI(0);
|
2008-07-17 09:18:03 +00:00
|
|
|
else
|
|
|
|
ERROR_LOG("no support for SwapInterval (framerate clamped to monitor refresh rate)\n");
|
2008-08-12 23:17:29 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
#endif
|
2008-08-13 00:00:39 +00:00
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
// check the max texture width and height
|
2008-08-06 21:07:31 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&g_MaxTexWidth);
|
2008-07-17 09:18:03 +00:00
|
|
|
g_MaxTexHeight = g_MaxTexWidth;
|
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
|
|
|
|
|
|
|
if (glDrawBuffers == NULL && !GLEW_ARB_draw_buffers)
|
|
|
|
glDrawBuffers = glDrawBuffersARB;
|
|
|
|
|
2008-08-06 21:07:31 +00:00
|
|
|
glGenFramebuffersEXT( 1, (GLuint *)&s_uFramebuffer);
|
2008-07-17 09:18:03 +00:00
|
|
|
if (s_uFramebuffer == 0) {
|
|
|
|
ERROR_LOG("failed to create the renderbuffer\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
_assert_( glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT );
|
|
|
|
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, s_uFramebuffer );
|
|
|
|
|
|
|
|
// create the framebuffer targets
|
2008-08-06 21:38:18 +00:00
|
|
|
glGenTextures(ARRAYSIZE(s_RenderTargets), (GLuint *)s_RenderTargets);
|
2008-09-08 07:09:34 +00:00
|
|
|
for(u32 i = 0; i < ARRAYSIZE(s_RenderTargets); ++i) {
|
2008-10-05 05:39:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_RenderTargets[i]);
|
2008-07-17 09:18:03 +00:00
|
|
|
// initialize to default
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, nBackbufferWidth, nBackbufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2008-07-17 09:18:03 +00:00
|
|
|
if( glGetError() != GL_NO_ERROR) {
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
}
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2008-11-28 13:23:29 +00:00
|
|
|
#ifdef USE_AA
|
|
|
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_RenderTargets[i]);
|
2008-12-02 01:08:21 +00:00
|
|
|
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, AA_AMMOUNT, GL_RGBA, nBackbufferWidth, nBackbufferHeight);
|
2008-11-28 13:23:29 +00:00
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
s_nCurTarget = 0;
|
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
int nMaxMRT = 0;
|
2008-08-06 21:07:31 +00:00
|
|
|
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, (GLint *)&nMaxMRT);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (nMaxMRT > 1) {
|
2008-07-17 09:18:03 +00:00
|
|
|
// create zbuffer target
|
2008-08-06 21:07:31 +00:00
|
|
|
glGenTextures(1, (GLuint *)&s_ZBufferTarget);
|
2008-10-05 05:39:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_ZBufferTarget);
|
|
|
|
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, nBackbufferWidth, nBackbufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2008-07-17 09:18:03 +00:00
|
|
|
if( glGetError() != GL_NO_ERROR) {
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
}
|
2008-10-05 05:39:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2008-11-28 13:23:29 +00:00
|
|
|
#ifdef USE_AA
|
|
|
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_ZBufferTarget);
|
2008-12-02 01:08:21 +00:00
|
|
|
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, AA_AMMOUNT, GL_RGBA, nBackbufferWidth, nBackbufferHeight);
|
2008-11-28 13:23:29 +00:00
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create the depth buffer
|
2008-08-06 21:07:31 +00:00
|
|
|
glGenRenderbuffersEXT( 1, (GLuint *)&s_DepthTarget);
|
2008-07-17 09:18:03 +00:00
|
|
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, s_DepthTarget);
|
2008-11-28 13:23:29 +00:00
|
|
|
#ifdef USE_AA
|
2008-12-02 01:08:21 +00:00
|
|
|
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, AA_AMMOUNT, GL_DEPTH24_STENCIL8_EXT, nBackbufferWidth, nBackbufferHeight);
|
2008-11-28 13:23:29 +00:00
|
|
|
#else
|
2008-08-14 23:04:24 +00:00
|
|
|
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, nBackbufferWidth, nBackbufferHeight);
|
2008-11-28 13:23:29 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR) {
|
2008-08-14 23:04:24 +00:00
|
|
|
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, nBackbufferWidth, nBackbufferHeight);
|
2008-07-17 09:18:03 +00:00
|
|
|
s_bHaveStencilBuffer = false;
|
2008-10-25 13:27:28 +00:00
|
|
|
} else {
|
|
|
|
s_bHaveStencilBuffer = true;
|
|
|
|
}
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
// set as render targets
|
2008-10-05 05:39:59 +00:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, s_RenderTargets[s_nCurTarget], 0 );
|
2008-07-17 09:18:03 +00:00
|
|
|
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, s_DepthTarget );
|
2008-11-28 13:23:29 +00:00
|
|
|
|
|
|
|
#ifdef USE_AA
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, s_RenderTargets[s_nCurTarget]);
|
|
|
|
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, s_RenderTargets[s_nCurTarget]);
|
|
|
|
|
|
|
|
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, s_DepthTarget);
|
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (s_ZBufferTarget != 0) {
|
2008-07-17 09:18:03 +00:00
|
|
|
// test to make sure it works
|
2008-10-05 05:39:59 +00:00
|
|
|
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, s_ZBufferTarget, 0);
|
2008-07-17 09:18:03 +00:00
|
|
|
bool bFailed = glGetError() != GL_NO_ERROR || glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT;
|
2008-10-05 05:39:59 +00:00
|
|
|
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, 0, 0);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
if( bFailed ) {
|
2008-08-06 21:07:31 +00:00
|
|
|
glDeleteTextures(1, (GLuint *)&s_ZBufferTarget);
|
2008-07-17 09:18:03 +00:00
|
|
|
s_ZBufferTarget = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (s_ZBufferTarget == 0)
|
2008-07-17 09:18:03 +00:00
|
|
|
ERROR_LOG("disabling ztarget mrt feature (max mrt=%d)\n", nMaxMRT);
|
|
|
|
|
|
|
|
//glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, s_DepthTarget );
|
|
|
|
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
nZBufferRender = 0;
|
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
2008-10-25 13:27:28 +00:00
|
|
|
if (err != GL_NO_ERROR)
|
|
|
|
bSuccess = false;
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
s_pfont = new RasterFont();
|
|
|
|
|
2008-08-20 08:01:27 +00:00
|
|
|
SetAA(g_Config.iMultisampleMode);
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
// load the effect, find the best profiles (if any)
|
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE) {
|
|
|
|
ERROR_LOG("arbvp1 not supported\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE) {
|
|
|
|
ERROR_LOG("arbfp1 not supported\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_cgvProf = cgGLGetLatestProfile(CG_GL_VERTEX);
|
|
|
|
g_cgfProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);//CG_PROFILE_ARBFP1;
|
2008-10-13 16:45:17 +00:00
|
|
|
cgGLSetOptimalOptions(g_cgvProf);
|
|
|
|
cgGLSetOptimalOptions(g_cgfProf);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
//ERROR_LOG("max buffer sizes: %d %d\n", cgGetProgramBufferMaxSize(g_cgvProf), cgGetProgramBufferMaxSize(g_cgfProf));
|
|
|
|
int nenvvertparams, nenvfragparams, naddrregisters[2];
|
2008-08-06 21:07:31 +00:00
|
|
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, (GLint *)&nenvvertparams);
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, (GLint *)&nenvfragparams);
|
|
|
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, (GLint *)&naddrregisters[0]);
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, (GLint *)&naddrregisters[1]);
|
2008-07-17 09:18:03 +00:00
|
|
|
__Log("max program env parameters: vert=%d, frag=%d\n", nenvvertparams, nenvfragparams);
|
|
|
|
__Log("max program address register parameters: vert=%d, frag=%d\n", naddrregisters[0], naddrregisters[1]);
|
|
|
|
|
|
|
|
if( nenvvertparams < 238 )
|
|
|
|
ERROR_LOG("not enough vertex shader environment constants!!\n");
|
|
|
|
|
|
|
|
#ifndef _DEBUG
|
|
|
|
cgGLSetDebugMode(GL_FALSE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( cgGetError() != CG_NO_ERROR ) {
|
|
|
|
ERROR_LOG("cg error\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
//glEnable(GL_POLYGON_OFFSET_LINE);
|
|
|
|
//glPolygonOffset(0, 1);
|
|
|
|
if (!Initialize())
|
|
|
|
return false;
|
|
|
|
|
2008-08-14 21:34:39 +00:00
|
|
|
XFB_Init();
|
2008-07-17 09:18:03 +00:00
|
|
|
return glGetError() == GL_NO_ERROR && bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::Shutdown(void)
|
|
|
|
{
|
2008-08-14 21:34:39 +00:00
|
|
|
delete s_pfont;
|
|
|
|
s_pfont = 0;
|
|
|
|
|
|
|
|
XFB_Shutdown();
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-08-14 21:34:39 +00:00
|
|
|
if (g_cgcontext != 0) {
|
2008-07-17 09:18:03 +00:00
|
|
|
cgDestroyContext(g_cgcontext);
|
|
|
|
g_cgcontext = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-14 21:34:39 +00:00
|
|
|
if (s_RenderTargets[0]) {
|
2008-08-06 21:38:18 +00:00
|
|
|
glDeleteTextures(ARRAYSIZE(s_RenderTargets), (GLuint *)s_RenderTargets);
|
2008-07-17 09:18:03 +00:00
|
|
|
memset(s_RenderTargets, 0, sizeof(s_RenderTargets));
|
|
|
|
}
|
2008-08-14 21:34:39 +00:00
|
|
|
if (s_DepthTarget) {
|
2008-08-06 21:07:31 +00:00
|
|
|
glDeleteRenderbuffersEXT(1, (GLuint *)&s_DepthTarget); s_DepthTarget = 0;
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
if (s_uFramebuffer != 0) {
|
2008-08-06 21:07:31 +00:00
|
|
|
glDeleteFramebuffersEXT( 1, (GLuint *)&s_uFramebuffer);
|
2008-07-17 09:18:03 +00:00
|
|
|
s_uFramebuffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Renderer::Initialize()
|
|
|
|
{
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, 0);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
glViewport(0, 0, GetTargetWidth(), GetTargetHeight()); // Reset The Current Viewport
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
|
2008-11-25 10:48:07 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // perspective correct interpolation of colors and tex coords
|
2008-11-25 10:48:07 +00:00
|
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|
|
|
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2008-10-25 13:27:28 +00:00
|
|
|
glScissor(0, 0, nBackbufferWidth, nBackbufferHeight);
|
2008-07-17 09:18:03 +00:00
|
|
|
glBlendColorEXT(0, 0, 0, 0.5f);
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
// legacy multitexturing: select texture channel only.
|
2008-07-17 09:18:03 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
2008-10-25 13:27:28 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
s_RenderMode = Renderer::RM_Normal;
|
|
|
|
|
|
|
|
GLenum err = GL_NO_ERROR;
|
|
|
|
GL_REPORT_ERROR();
|
2008-08-10 21:06:03 +00:00
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
return err == GL_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::AddMessage(const char* pstr, u32 ms)
|
|
|
|
{
|
2008-08-16 21:58:07 +00:00
|
|
|
s_listMsgs.push_back(MESSAGE(pstr, timeGetTime() + ms));
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::ProcessMessages()
|
|
|
|
{
|
2008-08-10 21:06:03 +00:00
|
|
|
GLboolean wasEnabled = glIsEnabled(GL_BLEND);
|
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
if (!wasEnabled) glEnable(GL_BLEND);
|
2008-08-10 21:06:03 +00:00
|
|
|
|
|
|
|
if (s_listMsgs.size() > 0) {
|
2008-07-17 09:18:03 +00:00
|
|
|
int left = 25, top = 15;
|
2008-10-22 21:23:40 +00:00
|
|
|
std::list<MESSAGE>::iterator it = s_listMsgs.begin();
|
2008-10-17 11:30:14 +00:00
|
|
|
while (it != s_listMsgs.end())
|
2008-08-08 22:04:02 +00:00
|
|
|
{
|
2008-08-10 21:06:03 +00:00
|
|
|
int time_left = (int)(it->dwTimeStamp - timeGetTime());
|
|
|
|
int alpha = 255;
|
|
|
|
|
2008-10-17 12:08:28 +00:00
|
|
|
if (time_left < 1024)
|
2008-08-10 21:06:03 +00:00
|
|
|
{
|
2008-10-17 12:08:28 +00:00
|
|
|
alpha = time_left >> 2;
|
|
|
|
if (time_left < 0) alpha = 0;
|
2008-08-10 21:06:03 +00:00
|
|
|
}
|
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
alpha <<= 24;
|
2008-08-10 21:06:03 +00:00
|
|
|
|
|
|
|
RenderText(it->str, left+1, top+1, 0x000000|alpha);
|
|
|
|
RenderText(it->str, left, top, 0xffff30|alpha);
|
2008-07-17 09:18:03 +00:00
|
|
|
top += 15;
|
|
|
|
|
2008-08-10 21:06:03 +00:00
|
|
|
if (time_left <= 0)
|
2008-07-17 09:18:03 +00:00
|
|
|
it = s_listMsgs.erase(it);
|
|
|
|
else ++it;
|
|
|
|
}
|
|
|
|
}
|
2008-08-10 21:06:03 +00:00
|
|
|
|
|
|
|
if(!wasEnabled) glDisable(GL_BLEND);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 21:06:03 +00:00
|
|
|
void Renderer::RenderText(const char* pstr, int left, int top, u32 color)
|
2008-07-17 09:18:03 +00:00
|
|
|
{
|
2008-08-10 21:06:03 +00:00
|
|
|
glColor4f(
|
|
|
|
((color>>16) & 0xff)/255.0f,
|
|
|
|
((color>> 8) & 0xff)/255.0f,
|
|
|
|
((color>> 0) & 0xff)/255.0f,
|
|
|
|
((color>>24) & 0xFF)/255.0f
|
|
|
|
);
|
2008-08-09 09:16:59 +00:00
|
|
|
s_pfont->printMultilineText(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight,0,nBackbufferWidth,nBackbufferHeight);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetAA(int aa)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::ReinitView(int nNewWidth, int nNewHeight)
|
|
|
|
{
|
|
|
|
int oldscreen = s_bFullscreen;
|
|
|
|
|
|
|
|
OpenGL_Shutdown();
|
|
|
|
int oldwidth = nBackbufferWidth, oldheight = nBackbufferHeight;
|
|
|
|
if (!OpenGL_Create(g_VideoInitialize, nNewWidth, nNewHeight)) {//nNewWidth&~7, nNewHeight&~7) ) {
|
|
|
|
ERROR_LOG("Failed to recreate, reverting to old settings\n");
|
|
|
|
if (!OpenGL_Create(g_VideoInitialize, oldwidth, oldheight)) {
|
2008-09-10 01:01:28 +00:00
|
|
|
g_VideoInitialize.pSysMessage("Failed to revert, exiting...\n");
|
2008-07-17 09:18:03 +00:00
|
|
|
// TODO - don't takedown the entire emu
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OpenGL_MakeCurrent();
|
|
|
|
|
|
|
|
if (oldscreen && !g_Config.bFullscreen) { // if transitioning from full screen
|
|
|
|
#ifdef _WIN32
|
|
|
|
RECT rc;
|
|
|
|
rc.left = 0; rc.top = 0;
|
|
|
|
rc.right = nNewWidth; rc.bottom = nNewHeight;
|
|
|
|
AdjustWindowRect(&rc, EmuWindow::g_winstyle, FALSE);
|
|
|
|
|
|
|
|
RECT rcdesktop;
|
|
|
|
GetWindowRect(GetDesktopWindow(), &rcdesktop);
|
|
|
|
|
|
|
|
SetWindowLong( EmuWindow::GetWnd(), GWL_STYLE, EmuWindow::g_winstyle );
|
|
|
|
SetWindowPos(EmuWindow::GetWnd(), HWND_TOP, ((rcdesktop.right-rcdesktop.left)-(rc.right-rc.left))/2,
|
|
|
|
((rcdesktop.bottom-rcdesktop.top)-(rc.bottom-rc.top))/2,
|
|
|
|
rc.right-rc.left, rc.bottom-rc.top, SWP_SHOWWINDOW);
|
|
|
|
UpdateWindow(EmuWindow::GetWnd());
|
|
|
|
#else // linux
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nBackbufferWidth = nNewWidth > 16 ? nNewWidth : 16;
|
|
|
|
nBackbufferHeight = nNewHeight > 16 ? nNewHeight : 16;
|
|
|
|
}
|
|
|
|
int Renderer::GetTargetWidth()
|
|
|
|
{
|
2008-10-24 02:29:05 +00:00
|
|
|
if(g_Config.bStretchToFit)
|
2008-10-09 18:47:53 +00:00
|
|
|
return 640;
|
|
|
|
else
|
|
|
|
return nBackbufferWidth; // return the actual window width
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 23:04:24 +00:00
|
|
|
int Renderer::GetTargetHeight()
|
2008-07-17 09:18:03 +00:00
|
|
|
{
|
2008-10-24 02:29:05 +00:00
|
|
|
if(g_Config.bStretchToFit)
|
2008-10-09 18:47:53 +00:00
|
|
|
return 480;
|
|
|
|
else
|
|
|
|
return nBackbufferHeight; // return the actual window height
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 23:04:24 +00:00
|
|
|
bool Renderer::CanBlendLogicOp()
|
2008-07-17 09:18:03 +00:00
|
|
|
{
|
2008-08-14 23:04:24 +00:00
|
|
|
return g_bBlendLogicOp;
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetRenderTarget(u32 targ)
|
|
|
|
{
|
2008-10-05 05:39:59 +00:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, targ!=0?targ:s_RenderTargets[s_nCurTarget], 0 );
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetDepthTarget(u32 targ)
|
|
|
|
{
|
|
|
|
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, targ != 0 ? targ : s_DepthTarget );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetFramebuffer(u32 fb)
|
|
|
|
{
|
2008-10-25 13:27:28 +00:00
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb != 0 ? fb : s_uFramebuffer);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 Renderer::GetRenderTarget()
|
|
|
|
{
|
|
|
|
return s_RenderTargets[s_nCurTarget];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::ResetGLState()
|
|
|
|
{
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
glDisable(GL_VERTEX_PROGRAM_ARB);
|
|
|
|
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RestoreGLState()
|
|
|
|
{
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (bpmem.genMode.cullmode > 0) glEnable(GL_CULL_FACE);
|
2008-07-17 09:18:03 +00:00
|
|
|
if (bpmem.zmode.testenable) glEnable(GL_DEPTH_TEST);
|
|
|
|
if (bpmem.blendmode.blendenable) glEnable(GL_BLEND);
|
|
|
|
if(bpmem.zmode.updateenable) glDepthMask(GL_TRUE);
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
glEnable(GL_VERTEX_PROGRAM_ARB);
|
|
|
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
2008-07-17 09:18:03 +00:00
|
|
|
SetColorMask();
|
|
|
|
}
|
|
|
|
|
2008-11-30 14:15:34 +00:00
|
|
|
void Renderer::SetColorMask()
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.alphaupdate && bpmem.blendmode.colorupdate)
|
|
|
|
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
|
|
|
|
else if (bpmem.blendmode.alphaupdate)
|
|
|
|
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE);
|
|
|
|
else if (bpmem.blendmode.colorupdate)
|
|
|
|
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =======================================================================================
|
|
|
|
// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
|
|
|
|
// case 0x52 > SetScissorRect()
|
|
|
|
// ---------------
|
|
|
|
// This function handles the OpenGL glScissor() function
|
|
|
|
// ---------------
|
|
|
|
// bpmem.scissorTL.x, y = 342x342
|
|
|
|
// bpmem.scissorBR.x, y = 981x821
|
|
|
|
// Renderer::GetTargetHeight() = the fixed ini file setting
|
|
|
|
// ---------------
|
|
|
|
bool Renderer::SetScissorRect()
|
|
|
|
{
|
|
|
|
int xoff = bpmem.scissorOffset.x * 2 - 342;
|
|
|
|
int yoff = bpmem.scissorOffset.y * 2 - 342;
|
|
|
|
|
|
|
|
float rc_left = bpmem.scissorTL.x - xoff - 342; // left = 0
|
|
|
|
rc_left *= MValueX;
|
|
|
|
if (rc_left < 0) rc_left = 0;
|
|
|
|
|
|
|
|
float rc_top = bpmem.scissorTL.y - yoff - 342; // right = 0
|
|
|
|
rc_top *= MValueY;
|
|
|
|
if (rc_top < 0) rc_top = 0;
|
|
|
|
|
|
|
|
float rc_right = bpmem.scissorBR.x - xoff - 342; // right = 640
|
|
|
|
rc_right *= MValueX;
|
|
|
|
if (rc_right > 640 * MValueX) rc_right = 640 * MValueX;
|
|
|
|
|
|
|
|
float rc_bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480
|
|
|
|
rc_bottom *= MValueY;
|
|
|
|
if (rc_bottom > 480 * MValueY) rc_bottom = 480 * MValueY;
|
|
|
|
|
|
|
|
/*__Log("Scissor: lt=(%d,%d), rb=(%d,%d,%i), off=(%d,%d)\n",
|
|
|
|
rc_left, rc_top,
|
|
|
|
rc_right, rc_bottom, Renderer::GetTargetHeight(),
|
|
|
|
xoff, yoff
|
|
|
|
);*/
|
|
|
|
|
|
|
|
if (rc_right >= rc_left && rc_bottom >= rc_top )
|
|
|
|
{
|
|
|
|
glScissor(
|
|
|
|
(int)rc_left, // x = 0
|
|
|
|
Renderer::GetTargetHeight()-(int)(rc_bottom), // y = 0
|
|
|
|
(int)(rc_right-rc_left), // y = 0
|
|
|
|
(int)(rc_bottom-rc_top) // y = 0
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
bool Renderer::IsUsingATIDrawBuffers()
|
|
|
|
{
|
|
|
|
return s_bATIDrawBuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::HaveStencilBuffer()
|
|
|
|
{
|
|
|
|
return s_bHaveStencilBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetZBufferRender()
|
|
|
|
{
|
|
|
|
nZBufferRender = 10; // give it 10 frames
|
2008-10-25 13:27:28 +00:00
|
|
|
GLenum s_drawbuffers[2] = {
|
|
|
|
GL_COLOR_ATTACHMENT0_EXT,
|
|
|
|
GL_COLOR_ATTACHMENT1_EXT
|
|
|
|
};
|
2008-07-17 09:18:03 +00:00
|
|
|
glDrawBuffers(2, s_drawbuffers);
|
2008-10-25 13:27:28 +00:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, s_ZBufferTarget, 0);
|
2008-07-17 09:18:03 +00:00
|
|
|
_assert_(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::FlushZBufferAlphaToTarget()
|
|
|
|
{
|
|
|
|
ResetGLState();
|
|
|
|
|
|
|
|
SetRenderTarget(0);
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
|
|
|
|
2008-08-14 23:04:24 +00:00
|
|
|
glViewport(0, 0, GetTargetWidth(), GetTargetHeight());
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
// texture map s_RenderTargets[s_curtarget] onto the main buffer
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2008-10-05 05:39:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_ZBufferTarget);
|
2008-07-17 09:18:03 +00:00
|
|
|
TextureMngr::EnableTexRECT(0);
|
|
|
|
// disable all other stages
|
2008-10-25 13:27:28 +00:00
|
|
|
for(int i = 1; i < 8; ++i)
|
|
|
|
TextureMngr::DisableStage(i);
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2008-11-09 00:28:12 +00:00
|
|
|
// setup the stencil to only accept pixels that have been written
|
|
|
|
glStencilFunc(GL_EQUAL, 1, 0xff);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
|
|
|
|
2008-10-24 02:29:05 +00:00
|
|
|
if(g_Config.bStretchToFit)
|
2008-10-09 18:47:53 +00:00
|
|
|
{
|
|
|
|
//TODO: Do Correctly in a bit
|
|
|
|
float FactorW = (float)640 / (float)nBackbufferWidth;
|
|
|
|
float FactorH = (float)480 / (float)nBackbufferHeight;
|
|
|
|
|
|
|
|
float Max = (FactorW < FactorH) ? FactorH : FactorW;
|
|
|
|
float Temp = 1 / Max;
|
|
|
|
FactorW *= Temp;
|
|
|
|
FactorH *= Temp;
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f(0, 0); glVertex2f(-FactorW,-FactorH);
|
|
|
|
glTexCoord2f(0, (float)GetTargetHeight()); glVertex2f(-FactorW,FactorH);
|
|
|
|
glTexCoord2f((float)GetTargetWidth(), (float)GetTargetHeight()); glVertex2f(FactorW,FactorH);
|
|
|
|
glTexCoord2f((float)GetTargetWidth(), 0); glVertex2f(FactorW,-FactorH);
|
|
|
|
|
|
|
|
__Log("%d, %d", FactorW, FactorH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f(0, 0); glVertex2f(-1,-1);
|
|
|
|
glTexCoord2f(0, (float)(GetTargetHeight())); glVertex2f(-1,1);
|
|
|
|
glTexCoord2f((float)(GetTargetWidth()), (float)(GetTargetHeight())); glVertex2f(1,1);
|
|
|
|
glTexCoord2f((float)(GetTargetWidth()), 0); glVertex2f(1,-1);
|
|
|
|
}
|
2008-07-17 09:18:03 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2008-10-05 05:39:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
2008-07-17 09:18:03 +00:00
|
|
|
RestoreGLState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetRenderMode(RenderMode mode)
|
|
|
|
{
|
2008-10-25 13:27:28 +00:00
|
|
|
if (!s_bHaveStencilBuffer && mode == RM_ZBufferAlpha)
|
2008-07-17 09:18:03 +00:00
|
|
|
mode = RM_ZBufferOnly;
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (s_RenderMode == mode)
|
2008-07-17 09:18:03 +00:00
|
|
|
return;
|
|
|
|
|
2008-10-25 13:27:28 +00:00
|
|
|
if (mode == RM_Normal) {
|
2008-07-17 09:18:03 +00:00
|
|
|
// flush buffers
|
|
|
|
if( s_RenderMode == RM_ZBufferAlpha ) {
|
|
|
|
FlushZBufferAlphaToTarget();
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
}
|
|
|
|
SetColorMask();
|
|
|
|
SetRenderTarget(0);
|
|
|
|
SetZBufferRender();
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
}
|
2008-10-25 13:27:28 +00:00
|
|
|
else if (s_RenderMode == RM_Normal) {
|
2008-07-17 09:18:03 +00:00
|
|
|
// setup buffers
|
|
|
|
_assert_(GetZBufferTarget() && bpmem.zmode.updateenable);
|
|
|
|
|
|
|
|
if( mode == RM_ZBufferAlpha ) {
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
glClearStencil(0);
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
|
|
|
glStencilFunc(GL_ALWAYS, 1, 0xff);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_assert_(GetZBufferTarget());
|
|
|
|
_assert_(s_bHaveStencilBuffer);
|
|
|
|
|
|
|
|
if( mode == RM_ZBufferOnly ) {
|
|
|
|
// flush and remove stencil
|
|
|
|
_assert_(s_RenderMode==RM_ZBufferAlpha);
|
|
|
|
FlushZBufferAlphaToTarget();
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
|
|
|
|
SetRenderTarget(s_ZBufferTarget);
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_assert_(mode == RM_ZBufferAlpha&&s_RenderMode==RM_ZBufferOnly);
|
|
|
|
|
|
|
|
// setup stencil
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
glClearStencil(0);
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
|
|
|
glStencilFunc(GL_ALWAYS, 1, 0xff);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_RenderMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::RenderMode Renderer::GetRenderMode()
|
|
|
|
{
|
|
|
|
return s_RenderMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Renderer::GetZBufferTarget()
|
|
|
|
{
|
|
|
|
return nZBufferRender > 0 ? s_ZBufferTarget : 0;
|
|
|
|
}
|
2008-10-09 18:47:53 +00:00
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
void Renderer::Swap(const TRectangle& rc)
|
|
|
|
{
|
|
|
|
OpenGL_Update(); // just updates the render window position and the backbuffer size
|
|
|
|
|
2008-10-22 22:35:29 +00:00
|
|
|
DVSTARTPROFILE();
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
Renderer::SetRenderMode(Renderer::RM_Normal);
|
|
|
|
|
|
|
|
// render to the real buffer now
|
2008-11-28 13:23:29 +00:00
|
|
|
#ifdef USE_AA
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, s_RenderTargets[0]);
|
|
|
|
#else
|
2008-07-17 09:18:03 +00:00
|
|
|
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // switch to the backbuffer
|
2008-11-28 13:23:29 +00:00
|
|
|
#endif
|
2008-08-24 10:10:48 +00:00
|
|
|
glViewport(nXoff, nYoff, nBackbufferWidth, nBackbufferHeight);
|
2008-07-17 09:18:03 +00:00
|
|
|
|
|
|
|
ResetGLState();
|
|
|
|
|
|
|
|
// texture map s_RenderTargets[s_curtarget] onto the main buffer
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2008-10-28 08:14:17 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_RenderTargets[s_nCurTarget]);
|
2008-07-17 09:18:03 +00:00
|
|
|
TextureMngr::EnableTexRECT(0);
|
|
|
|
// disable all other stages
|
|
|
|
for(int i = 1; i < 8; ++i) TextureMngr::DisableStage(i);
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2008-10-28 08:14:17 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2008-07-17 09:18:03 +00:00
|
|
|
glBegin(GL_QUADS);
|
2008-08-15 02:57:20 +00:00
|
|
|
glTexCoord2f(0, 0); glVertex2f(-1,-1);
|
|
|
|
glTexCoord2f(0, (float)GetTargetHeight()); glVertex2f(-1,1);
|
|
|
|
glTexCoord2f((float)GetTargetWidth(), (float)GetTargetHeight()); glVertex2f(1,1);
|
|
|
|
glTexCoord2f((float)GetTargetWidth(), 0); glVertex2f(1,-1);
|
2008-07-17 09:18:03 +00:00
|
|
|
glEnd();
|
|
|
|
|
2008-10-28 08:14:17 +00:00
|
|
|
if (g_Config.bWireFrame)
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
|
2008-10-05 05:39:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
2008-07-17 09:18:03 +00:00
|
|
|
TextureMngr::DisableStage(0);
|
|
|
|
|
2008-10-15 14:07:03 +00:00
|
|
|
SwapBuffers();
|
|
|
|
|
|
|
|
RestoreGLState();
|
2008-11-28 13:23:29 +00:00
|
|
|
#ifdef USE_AA
|
|
|
|
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, s_RenderTargets[s_nCurTarget]);
|
|
|
|
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
|
|
|
|
glBlitFramebufferEXT(0, 0, nBackbufferWidth, nBackbufferHeight, 0, 0, nBackbufferWidth, nBackbufferHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
#endif
|
2008-10-15 14:07:03 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
|
|
|
g_Config.iSaveTargetId = 0;
|
|
|
|
|
|
|
|
// for testing zbuffer targets
|
|
|
|
//Renderer::SetZBufferRender();
|
|
|
|
//SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_ZBufferTarget, GetTargetWidth(), GetTargetHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SwapBuffers()
|
|
|
|
{
|
|
|
|
static int fpscount;
|
2008-08-24 10:10:48 +00:00
|
|
|
static int s_fps;
|
|
|
|
static unsigned long lasttime;
|
|
|
|
++fpscount;
|
|
|
|
if( timeGetTime() - lasttime > 1000 )
|
|
|
|
{
|
|
|
|
lasttime = timeGetTime();
|
|
|
|
s_fps = fpscount;
|
|
|
|
fpscount = 0;
|
|
|
|
}
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-10-09 18:47:53 +00:00
|
|
|
// Write logging data to debugger
|
2008-10-25 17:47:46 +00:00
|
|
|
#if !defined(OSX64)
|
2008-10-09 18:47:53 +00:00
|
|
|
if(m_frame)
|
|
|
|
{
|
|
|
|
Logging(0);
|
|
|
|
}
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-07-17 09:18:03 +00:00
|
|
|
if (g_Config.bOverlayStats) {
|
|
|
|
char st[2048];
|
|
|
|
char *p = st;
|
2008-08-24 10:10:48 +00:00
|
|
|
if(g_Config.bShowFPS)
|
|
|
|
p+=sprintf(p, "FPS: %d\n", s_fps); // So it shows up before the stats and doesn't make anyting ugly
|
2008-07-17 09:18:03 +00:00
|
|
|
p+=sprintf(p,"Num textures created: %i\n",stats.numTexturesCreated);
|
2008-08-08 22:17:03 +00:00
|
|
|
p+=sprintf(p,"Num textures alive: %i\n",stats.numTexturesAlive);
|
2008-07-17 09:18:03 +00:00
|
|
|
p+=sprintf(p,"Num pshaders created: %i\n",stats.numPixelShadersCreated);
|
2008-08-08 22:17:03 +00:00
|
|
|
p+=sprintf(p,"Num pshaders alive: %i\n",stats.numPixelShadersAlive);
|
2008-07-17 09:18:03 +00:00
|
|
|
p+=sprintf(p,"Num vshaders created: %i\n",stats.numVertexShadersCreated);
|
2008-08-08 22:17:03 +00:00
|
|
|
p+=sprintf(p,"Num vshaders alive: %i\n",stats.numVertexShadersAlive);
|
2008-08-08 23:39:48 +00:00
|
|
|
p+=sprintf(p,"Num dlists called: %i\n",stats.numDListsCalled);
|
|
|
|
p+=sprintf(p,"Num dlists called (frame): %i\n",stats.thisFrame.numDListsCalled);
|
2008-08-08 23:22:27 +00:00
|
|
|
// not used.
|
|
|
|
//p+=sprintf(p,"Num dlists created: %i\n",stats.numDListsCreated);
|
|
|
|
//p+=sprintf(p,"Num dlists alive: %i\n",stats.numDListsAlive);
|
|
|
|
//p+=sprintf(p,"Num strip joins: %i\n",stats.numJoins);
|
|
|
|
p+=sprintf(p,"Num primitives: %i\n",stats.thisFrame.numPrims);
|
2008-11-23 17:46:14 +00:00
|
|
|
p+=sprintf(p,"Num primitive joins: %i\n",stats.thisFrame.numPrimitiveJoins);
|
|
|
|
p+=sprintf(p,"Num buffer splits: %i\n",stats.thisFrame.numBufferSplits);
|
|
|
|
p+=sprintf(p,"Num draw calls: %i\n",stats.thisFrame.numDrawCalls);
|
2008-08-08 23:22:27 +00:00
|
|
|
p+=sprintf(p,"Num primitives (DL): %i\n",stats.thisFrame.numDLPrims);
|
2008-08-08 23:32:29 +00:00
|
|
|
p+=sprintf(p,"Num XF loads: %i\n",stats.thisFrame.numXFLoads);
|
|
|
|
p+=sprintf(p,"Num XF loads (DL): %i\n",stats.thisFrame.numXFLoadsInDL);
|
|
|
|
p+=sprintf(p,"Num CP loads: %i\n",stats.thisFrame.numCPLoads);
|
|
|
|
p+=sprintf(p,"Num CP loads (DL): %i\n",stats.thisFrame.numCPLoadsInDL);
|
|
|
|
p+=sprintf(p,"Num BP loads: %i\n",stats.thisFrame.numBPLoads);
|
|
|
|
p+=sprintf(p,"Num BP loads (DL): %i\n",stats.thisFrame.numBPLoadsInDL);
|
2008-10-25 15:53:43 +00:00
|
|
|
p+=sprintf(p,"Num vertex loaders: %i\n",stats.numVertexLoaders);
|
2008-08-08 23:22:27 +00:00
|
|
|
|
2008-11-25 21:15:31 +00:00
|
|
|
|
|
|
|
std::string text = st;
|
|
|
|
VertexLoaderManager::AppendListToString(&text);
|
|
|
|
|
|
|
|
Renderer::RenderText(text.c_str(), 20, 20, 0xFF00FFFF);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
2008-08-24 10:10:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(g_Config.bShowFPS)
|
|
|
|
{
|
|
|
|
char strfps[25];
|
|
|
|
sprintf(strfps, "%d\n", s_fps);
|
|
|
|
Renderer::RenderText(strfps, 20, 20, 0xFF00FFFF);
|
|
|
|
}
|
|
|
|
}
|
2008-07-17 09:18:03 +00:00
|
|
|
|
2008-08-10 21:06:03 +00:00
|
|
|
Renderer::ProcessMessages();
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
#if defined(DVPROFILE)
|
|
|
|
if (g_bWriteProfile) {
|
|
|
|
//g_bWriteProfile = 0;
|
|
|
|
static int framenum = 0;
|
|
|
|
const int UPDATE_FRAMES = 8;
|
|
|
|
if (++framenum >= UPDATE_FRAMES) {
|
|
|
|
DVProfWrite("prof.txt", UPDATE_FRAMES);
|
|
|
|
DVProfClear();
|
|
|
|
framenum = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// copy the rendered from to the real window
|
|
|
|
OpenGL_SwapBuffers();
|
|
|
|
|
2008-08-10 21:06:03 +00:00
|
|
|
glClearColor(0,0,0,0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2008-07-17 09:18:03 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
|
|
|
//clean out old stuff from caches
|
|
|
|
frameCount++;
|
|
|
|
PixelShaderMngr::Cleanup();
|
|
|
|
TextureMngr::Cleanup();
|
|
|
|
|
|
|
|
// New frame
|
|
|
|
stats.ResetFrame();
|
|
|
|
|
|
|
|
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, s_uFramebuffer );
|
2008-10-25 13:27:28 +00:00
|
|
|
|
|
|
|
if (nZBufferRender > 0) {
|
|
|
|
if (--nZBufferRender == 0) {
|
2008-07-17 09:18:03 +00:00
|
|
|
// turn off
|
|
|
|
nZBufferRender = 0;
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
2008-10-25 13:27:28 +00:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, 0, 0);
|
|
|
|
Renderer::SetRenderMode(RM_Normal); // turn off any zwrites
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::SaveRenderTarget(const char* filename, int jpeg)
|
|
|
|
{
|
|
|
|
bool bflip = true;
|
2008-10-25 13:27:28 +00:00
|
|
|
std::vector<u32> data(nBackbufferWidth * nBackbufferHeight);
|
2008-08-14 23:04:24 +00:00
|
|
|
glReadPixels(0, 0, nBackbufferWidth, nBackbufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]);
|
2008-07-17 09:18:03 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (bflip) {
|
|
|
|
// swap scanlines
|
2008-10-22 21:23:40 +00:00
|
|
|
std::vector<u32> scanline(nBackbufferWidth);
|
2008-08-23 15:28:24 +00:00
|
|
|
for(int i = 0; i < nBackbufferHeight/2; ++i) {
|
2008-08-14 23:04:24 +00:00
|
|
|
memcpy(&scanline[0], &data[i*nBackbufferWidth], nBackbufferWidth*4);
|
|
|
|
memcpy(&data[i*nBackbufferWidth], &data[(nBackbufferHeight-i-1)*nBackbufferWidth], nBackbufferWidth*4);
|
|
|
|
memcpy(&data[(nBackbufferHeight-i-1)*nBackbufferWidth], &scanline[0], nBackbufferWidth*4);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-14 23:04:24 +00:00
|
|
|
return SaveTGA(filename, nBackbufferWidth, nBackbufferHeight, &data[0]);
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetCgErrorOutput(bool bOutput)
|
|
|
|
{
|
|
|
|
s_bOutputCgErrors = bOutput;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandleGLError()
|
|
|
|
{
|
|
|
|
const GLubyte* pstr = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
2008-10-25 13:27:28 +00:00
|
|
|
if (pstr != NULL && pstr[0] != 0)
|
|
|
|
{
|
|
|
|
GLint loc = 0;
|
2008-07-17 09:18:03 +00:00
|
|
|
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &loc);
|
|
|
|
ERROR_LOG("program error at %d: ", loc);
|
|
|
|
ERROR_LOG((char*)pstr);
|
|
|
|
ERROR_LOG("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the error status of this framebuffer */
|
|
|
|
GLenum error = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
|
|
|
|
|
|
|
// if error != GL_FRAMEBUFFER_COMPLETE_EXT, there's an error of some sort
|
2008-10-25 13:27:28 +00:00
|
|
|
if (!error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// int w, h;
|
|
|
|
// GLint fmt;
|
|
|
|
// glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_INTERNAL_FORMAT_EXT, &fmt);
|
|
|
|
// glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_WIDTH_EXT, (GLint *)&w);
|
|
|
|
// glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_HEIGHT_EXT, (GLint *)&h);
|
|
|
|
|
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
|
|
|
ERROR_LOG("Error! missing a required image/buffer attachment!\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
|
|
|
ERROR_LOG("Error! has no images/buffers attached!\n");
|
|
|
|
break;
|
|
|
|
// case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
|
|
|
|
// ERROR_LOG("Error! has an image/buffer attached in multiple locations!\n");
|
|
|
|
// break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
|
|
|
ERROR_LOG("Error! has mismatched image/buffer dimensions!\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
|
|
|
ERROR_LOG("Error! colorbuffer attachments have different types!\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
|
|
|
ERROR_LOG("Error! trying to draw to non-attached color buffer!\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
|
|
|
ERROR_LOG("Error! trying to read from a non-attached color buffer!\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
|
|
|
ERROR_LOG("Error! format is not supported by current graphics card/driver!\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR_LOG("*UNKNOWN ERROR* reported from glCheckFramebufferStatusEXT()!\n");
|
|
|
|
break;
|
|
|
|
}
|
2008-07-17 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
|
|
|
|
{
|
2008-10-25 13:27:28 +00:00
|
|
|
if (s_bOutputCgErrors)
|
|
|
|
{
|
2008-07-17 09:18:03 +00:00
|
|
|
ERROR_LOG("Cg error: %s\n", cgGetErrorString(err));
|
|
|
|
const char* listing = cgGetLastListing(g_cgcontext);
|
|
|
|
if (listing != NULL) {
|
|
|
|
ERROR_LOG(" last listing: %s\n", listing);
|
|
|
|
}
|
|
|
|
// glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &loc);
|
|
|
|
// printf("pos: %d\n", loc);
|
|
|
|
}
|
|
|
|
}
|