- fix program crash when graphics card not support FBO;
WinPort:
- fix create console in Windows XP;
This commit is contained in:
mtabachenko 2012-10-06 10:21:01 +00:00
parent 9bc148b9cc
commit 0b689ec20d
2 changed files with 101 additions and 90 deletions

View File

@ -95,6 +95,7 @@ static bool isTranslucent;
static u32 textureFormat=0, texturePalette=0; static u32 textureFormat=0, texturePalette=0;
static char *extString = NULL;
// ClearImage/Rear-plane (FBO) // ClearImage/Rear-plane (FBO)
GLenum oglClearImageTextureID[2] = {0}; // 0 - image, 1 - depth GLenum oglClearImageTextureID[2] = {0}; // 0 - image, 1 - depth
GLuint oglClearImageBuffers = 0; GLuint oglClearImageBuffers = 0;
@ -308,7 +309,6 @@ static void createShaders()
glGetShaderInfoLog == NULL) glGetShaderInfoLog == NULL)
NOSHADERS("Shaders aren't supported by your system.");*/ NOSHADERS("Shaders aren't supported by your system.");*/
const char *extString = (const char*)glGetString(GL_EXTENSIONS);
if ((strstr(extString, "GL_ARB_shader_objects") == NULL) || if ((strstr(extString, "GL_ARB_shader_objects") == NULL) ||
(strstr(extString, "GL_ARB_vertex_shader") == NULL) || (strstr(extString, "GL_ARB_vertex_shader") == NULL) ||
(strstr(extString, "GL_ARB_fragment_shader") == NULL)) (strstr(extString, "GL_ARB_fragment_shader") == NULL))
@ -366,11 +366,14 @@ static void OGLReset()
// memset(GPU_screenStencil,0,sizeof(GPU_screenStencil)); // memset(GPU_screenStencil,0,sizeof(GPU_screenStencil));
memset(GPU_screen3D,0,sizeof(GPU_screen3D)); memset(GPU_screen3D,0,sizeof(GPU_screen3D));
if (!oglFBOdisabled)
{
memset(oglClearImageColor, 0, 256*192*sizeof(u32)); memset(oglClearImageColor, 0, 256*192*sizeof(u32));
memset(oglClearImageDepth, 0, 256*192*sizeof(float)); memset(oglClearImageDepth, 0, 256*192*sizeof(float));
memset(oglClearImageColorTemp, 0, 256*192*sizeof(u16)); memset(oglClearImageColorTemp, 0, 256*192*sizeof(u16));
memset(oglClearImageDepthTemp, 0, 256*192*sizeof(u16)); memset(oglClearImageDepthTemp, 0, 256*192*sizeof(u16));
oglClearImageScrollOld = 0; oglClearImageScrollOld = 0;
}
} }
//static class OGLTexCacheUser : public ITexCacheUser //static class OGLTexCacheUser : public ITexCacheUser
@ -430,6 +433,8 @@ static char OGLInit(void)
for (u8 i = 0; i < 255; i++) for (u8 i = 0; i < 255; i++)
material_8bit_to_float[i] = (float)(i<<2)/255.f; material_8bit_to_float[i] = (float)(i<<2)/255.f;
extString = (char*)glGetString(GL_EXTENSIONS);
expandFreeTextures(); expandFreeTextures();
glPixelStorei(GL_PACK_ALIGNMENT,8); glPixelStorei(GL_PACK_ALIGNMENT,8);
@ -537,6 +542,11 @@ static char OGLInit(void)
gfx3d.state.invalidateToon = false; gfx3d.state.invalidateToon = false;
} }
// FBO
oglFBOdisabled = (strstr(extString, "GL_ARB_framebuffer_object") == NULL)?true:false;
if (!oglFBOdisabled)
{
// ClearImage/Rear-plane // ClearImage/Rear-plane
glGenTextures (2, &oglClearImageTextureID[0]); glGenTextures (2, &oglClearImageTextureID[0]);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
@ -557,8 +567,7 @@ static char OGLInit(void)
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 256, 192, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 256, 192, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
// FBO // FBO - init
oglFBOdisabled = false;
glGenFramebuffersEXT(1, &oglClearImageBuffers); glGenFramebuffersEXT(1, &oglClearImageBuffers);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oglClearImageBuffers); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oglClearImageBuffers);
@ -572,7 +581,7 @@ static char OGLInit(void)
INFO("Successfully created OpenGL Framebuffer object (FBO)\n"); INFO("Successfully created OpenGL Framebuffer object (FBO)\n");
else else
{ {
INFO("Failed to created OpenGL Framebuffer object (FBO): ClearImage disabled\n"); INFO("Failed to created OpenGL Framebuffer objects (FBO): ClearImage emulation disabled\n");
oglFBOdisabled = true; oglFBOdisabled = true;
} }
@ -582,6 +591,9 @@ static char OGLInit(void)
oglClearImageColorTemp = new u16[256*192]; oglClearImageColorTemp = new u16[256*192];
oglClearImageDepth = new float[256*192]; oglClearImageDepth = new float[256*192];
oglClearImageDepthTemp = new u16[256*192]; oglClearImageDepthTemp = new u16[256*192];
}
else
INFO("OpenGL: graphics card not supports Framebuffer objects (FBO) - ClearImage emulation disabled\n");
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@ -624,6 +636,8 @@ static void OGLClose()
glDeleteTextures(1, &oglToonTableTextureID); glDeleteTextures(1, &oglToonTableTextureID);
// FBO // FBO
if (!oglFBOdisabled)
{
glDeleteTextures(2, &oglClearImageTextureID[0]); glDeleteTextures(2, &oglClearImageTextureID[0]);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &oglClearImageBuffers); glDeleteFramebuffersEXT(1, &oglClearImageBuffers);
@ -651,6 +665,7 @@ static void OGLClose()
delete [] oglClearImageDepthTemp; delete [] oglClearImageDepthTemp;
oglClearImageDepthTemp = NULL; oglClearImageDepthTemp = NULL;
} }
}
ENDGL(); ENDGL();
} }
@ -952,6 +967,7 @@ static void GL_ReadFramebuffer()
// Harry Potter and the Order of the Phoenix // Harry Potter and the Order of the Phoenix
static void oglClearImageFBO() static void oglClearImageFBO()
{ {
if (oglFBOdisabled) return;
//printf("enableClearImage\n"); //printf("enableClearImage\n");
u16* clearImage = (u16*)MMU.texInfo.textureSlotAddr[2]; u16* clearImage = (u16*)MMU.texInfo.textureSlotAddr[2];
u16* clearDepth = (u16*)MMU.texInfo.textureSlotAddr[3]; u16* clearDepth = (u16*)MMU.texInfo.textureSlotAddr[3];

View File

@ -84,10 +84,9 @@ void OpenConsole()
//stdout is already connected to something. keep using it and dont let the console interfere //stdout is already connected to something. keep using it and dont let the console interfere
bool shouldRedirectStdout = fileType == FILE_TYPE_UNKNOWN; bool shouldRedirectStdout = fileType == FILE_TYPE_UNKNOWN;
//attach to an existing console (if we can; this is circuitous because AttachConsole wasnt added until XP)
//remember to abstract this late bound function notion if we end up having to do this anywhere else
bool attached = false; bool attached = false;
if (!AllocConsole())
{
HMODULE lib = LoadLibrary("kernel32.dll"); HMODULE lib = LoadLibrary("kernel32.dll");
if(lib) if(lib)
{ {
@ -95,26 +94,22 @@ void OpenConsole()
_TAttachConsole _AttachConsole = (_TAttachConsole)GetProcAddress(lib,"AttachConsole"); _TAttachConsole _AttachConsole = (_TAttachConsole)GetProcAddress(lib,"AttachConsole");
if(_AttachConsole) if(_AttachConsole)
{ {
if(_AttachConsole(-1)) if(!_AttachConsole(-1))
{
FreeLibrary(lib);
return;
}
attached = true; attached = true;
} }
FreeLibrary(lib); FreeLibrary(lib);
} }
}
//if we failed to attach, then alloc a new console else
if(!attached)
{ {
if (!AllocConsole()) return;
SetConsoleCP(GetACP()); SetConsoleCP(GetACP());
SetConsoleOutputCP(GetACP()); SetConsoleOutputCP(GetACP());
} }
//old console title:
//char buf[256] = {0};
//sprintf(buf,"CONSOLE - %s", EMU_DESMUME_NAME_AND_VERSION());
//SetConsoleTitle(TEXT(buf));
//newer and improved console title: //newer and improved console title:
SetConsoleTitleW(SkipEverythingButProgramInCommandLine(GetCommandLineW()).c_str()); SetConsoleTitleW(SkipEverythingButProgramInCommandLine(GetCommandLineW()).c_str());