- 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 char *extString = NULL;
// ClearImage/Rear-plane (FBO)
GLenum oglClearImageTextureID[2] = {0}; // 0 - image, 1 - depth
GLuint oglClearImageBuffers = 0;
@ -308,7 +309,6 @@ static void createShaders()
glGetShaderInfoLog == NULL)
NOSHADERS("Shaders aren't supported by your system.");*/
const char *extString = (const char*)glGetString(GL_EXTENSIONS);
if ((strstr(extString, "GL_ARB_shader_objects") == NULL) ||
(strstr(extString, "GL_ARB_vertex_shader") == NULL) ||
(strstr(extString, "GL_ARB_fragment_shader") == NULL))
@ -366,12 +366,15 @@ static void OGLReset()
// memset(GPU_screenStencil,0,sizeof(GPU_screenStencil));
memset(GPU_screen3D,0,sizeof(GPU_screen3D));
if (!oglFBOdisabled)
{
memset(oglClearImageColor, 0, 256*192*sizeof(u32));
memset(oglClearImageDepth, 0, 256*192*sizeof(float));
memset(oglClearImageColorTemp, 0, 256*192*sizeof(u16));
memset(oglClearImageDepthTemp, 0, 256*192*sizeof(u16));
oglClearImageScrollOld = 0;
}
}
//static class OGLTexCacheUser : public ITexCacheUser
//{
@ -430,6 +433,8 @@ static char OGLInit(void)
for (u8 i = 0; i < 255; i++)
material_8bit_to_float[i] = (float)(i<<2)/255.f;
extString = (char*)glGetString(GL_EXTENSIONS);
expandFreeTextures();
glPixelStorei(GL_PACK_ALIGNMENT,8);
@ -537,6 +542,11 @@ static char OGLInit(void)
gfx3d.state.invalidateToon = false;
}
// FBO
oglFBOdisabled = (strstr(extString, "GL_ARB_framebuffer_object") == NULL)?true:false;
if (!oglFBOdisabled)
{
// ClearImage/Rear-plane
glGenTextures (2, &oglClearImageTextureID[0]);
glActiveTexture(GL_TEXTURE2);
@ -557,8 +567,7 @@ static char OGLInit(void)
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);
// FBO
oglFBOdisabled = false;
// FBO - init
glGenFramebuffersEXT(1, &oglClearImageBuffers);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oglClearImageBuffers);
@ -572,7 +581,7 @@ static char OGLInit(void)
INFO("Successfully created OpenGL Framebuffer object (FBO)\n");
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;
}
@ -582,6 +591,9 @@ static char OGLInit(void)
oglClearImageColorTemp = new u16[256*192];
oglClearImageDepth = new float[256*192];
oglClearImageDepthTemp = new u16[256*192];
}
else
INFO("OpenGL: graphics card not supports Framebuffer objects (FBO) - ClearImage emulation disabled\n");
glActiveTexture(GL_TEXTURE0);
@ -624,6 +636,8 @@ static void OGLClose()
glDeleteTextures(1, &oglToonTableTextureID);
// FBO
if (!oglFBOdisabled)
{
glDeleteTextures(2, &oglClearImageTextureID[0]);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &oglClearImageBuffers);
@ -651,6 +665,7 @@ static void OGLClose()
delete [] oglClearImageDepthTemp;
oglClearImageDepthTemp = NULL;
}
}
ENDGL();
}
@ -952,6 +967,7 @@ static void GL_ReadFramebuffer()
// Harry Potter and the Order of the Phoenix
static void oglClearImageFBO()
{
if (oglFBOdisabled) return;
//printf("enableClearImage\n");
u16* clearImage = (u16*)MMU.texInfo.textureSlotAddr[2];
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
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;
if (!AllocConsole())
{
HMODULE lib = LoadLibrary("kernel32.dll");
if(lib)
{
@ -95,26 +94,22 @@ void OpenConsole()
_TAttachConsole _AttachConsole = (_TAttachConsole)GetProcAddress(lib,"AttachConsole");
if(_AttachConsole)
{
if(_AttachConsole(-1))
if(!_AttachConsole(-1))
{
FreeLibrary(lib);
return;
}
attached = true;
}
FreeLibrary(lib);
}
//if we failed to attach, then alloc a new console
if(!attached)
}
else
{
if (!AllocConsole()) return;
SetConsoleCP(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:
SetConsoleTitleW(SkipEverythingButProgramInCommandLine(GetCommandLineW()).c_str());