OpenGL:
- fix program crash when graphics card not support FBO; WinPort: - fix create console in Windows XP;
This commit is contained in:
parent
9bc148b9cc
commit
0b689ec20d
|
@ -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));
|
||||||
|
|
||||||
memset(oglClearImageColor, 0, 256*192*sizeof(u32));
|
if (!oglFBOdisabled)
|
||||||
memset(oglClearImageDepth, 0, 256*192*sizeof(float));
|
{
|
||||||
memset(oglClearImageColorTemp, 0, 256*192*sizeof(u16));
|
memset(oglClearImageColor, 0, 256*192*sizeof(u32));
|
||||||
memset(oglClearImageDepthTemp, 0, 256*192*sizeof(u16));
|
memset(oglClearImageDepth, 0, 256*192*sizeof(float));
|
||||||
oglClearImageScrollOld = 0;
|
memset(oglClearImageColorTemp, 0, 256*192*sizeof(u16));
|
||||||
|
memset(oglClearImageDepthTemp, 0, 256*192*sizeof(u16));
|
||||||
|
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,51 +542,58 @@ static char OGLInit(void)
|
||||||
gfx3d.state.invalidateToon = false;
|
gfx3d.state.invalidateToon = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearImage/Rear-plane
|
|
||||||
glGenTextures (2, &oglClearImageTextureID[0]);
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, oglClearImageTextureID[0]);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, oglClearImageTextureID[1]);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
||||||
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
|
// FBO
|
||||||
oglFBOdisabled = false;
|
oglFBOdisabled = (strstr(extString, "GL_ARB_framebuffer_object") == NULL)?true:false;
|
||||||
glGenFramebuffersEXT(1, &oglClearImageBuffers);
|
|
||||||
|
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oglClearImageBuffers);
|
if (!oglFBOdisabled)
|
||||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, oglClearImageTextureID[0], 0);
|
|
||||||
|
|
||||||
//glDrawBuffer(GL_NONE);
|
|
||||||
//glReadBuffer(GL_NONE);
|
|
||||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, oglClearImageTextureID[1], 0);
|
|
||||||
|
|
||||||
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)==GL_FRAMEBUFFER_COMPLETE_EXT)
|
|
||||||
INFO("Successfully created OpenGL Framebuffer object (FBO)\n");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
INFO("Failed to created OpenGL Framebuffer object (FBO): ClearImage disabled\n");
|
// ClearImage/Rear-plane
|
||||||
oglFBOdisabled = true;
|
glGenTextures (2, &oglClearImageTextureID[0]);
|
||||||
|
glActiveTexture(GL_TEXTURE2);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, oglClearImageTextureID[0]);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, oglClearImageTextureID[1]);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
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 - init
|
||||||
|
glGenFramebuffersEXT(1, &oglClearImageBuffers);
|
||||||
|
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oglClearImageBuffers);
|
||||||
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, oglClearImageTextureID[0], 0);
|
||||||
|
|
||||||
|
//glDrawBuffer(GL_NONE);
|
||||||
|
//glReadBuffer(GL_NONE);
|
||||||
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, oglClearImageTextureID[1], 0);
|
||||||
|
|
||||||
|
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)==GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||||
|
INFO("Successfully created OpenGL Framebuffer object (FBO)\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
INFO("Failed to created OpenGL Framebuffer objects (FBO): ClearImage emulation disabled\n");
|
||||||
|
oglFBOdisabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
|
||||||
|
oglClearImageColor = new u32[256*192];
|
||||||
|
oglClearImageColorTemp = new u16[256*192];
|
||||||
|
oglClearImageDepth = new float[256*192];
|
||||||
|
oglClearImageDepthTemp = new u16[256*192];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
INFO("OpenGL: graphics card not supports Framebuffer objects (FBO) - ClearImage emulation disabled\n");
|
||||||
|
|
||||||
oglClearImageColor = new u32[256*192];
|
|
||||||
oglClearImageColorTemp = new u16[256*192];
|
|
||||||
oglClearImageDepth = new float[256*192];
|
|
||||||
oglClearImageDepthTemp = new u16[256*192];
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
@ -624,32 +636,35 @@ static void OGLClose()
|
||||||
glDeleteTextures(1, &oglToonTableTextureID);
|
glDeleteTextures(1, &oglToonTableTextureID);
|
||||||
|
|
||||||
// FBO
|
// FBO
|
||||||
glDeleteTextures(2, &oglClearImageTextureID[0]);
|
if (!oglFBOdisabled)
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
||||||
glDeleteFramebuffersEXT(1, &oglClearImageBuffers);
|
|
||||||
|
|
||||||
if (oglClearImageColor)
|
|
||||||
{
|
{
|
||||||
delete [] oglClearImageColor;
|
glDeleteTextures(2, &oglClearImageTextureID[0]);
|
||||||
oglClearImageColor = NULL;
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
}
|
glDeleteFramebuffersEXT(1, &oglClearImageBuffers);
|
||||||
|
|
||||||
if (oglClearImageDepth)
|
if (oglClearImageColor)
|
||||||
{
|
{
|
||||||
delete [] oglClearImageDepth;
|
delete [] oglClearImageColor;
|
||||||
oglClearImageDepth = NULL;
|
oglClearImageColor = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oglClearImageColorTemp)
|
if (oglClearImageDepth)
|
||||||
{
|
{
|
||||||
delete [] oglClearImageColorTemp;
|
delete [] oglClearImageDepth;
|
||||||
oglClearImageColorTemp = NULL;
|
oglClearImageDepth = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oglClearImageDepthTemp)
|
if (oglClearImageColorTemp)
|
||||||
{
|
{
|
||||||
delete [] oglClearImageDepthTemp;
|
delete [] oglClearImageColorTemp;
|
||||||
oglClearImageDepthTemp = NULL;
|
oglClearImageColorTemp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oglClearImageDepthTemp)
|
||||||
|
{
|
||||||
|
delete [] oglClearImageDepthTemp;
|
||||||
|
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];
|
||||||
|
|
|
@ -76,7 +76,7 @@ void OpenConsole()
|
||||||
//is FILE_TYPE_PIPE (3) for pipe
|
//is FILE_TYPE_PIPE (3) for pipe
|
||||||
//i think it is FILE_TYPE_CHAR (2) for console
|
//i think it is FILE_TYPE_CHAR (2) for console
|
||||||
|
|
||||||
//SOMETHING LIKE THIS MIGHT BE NEEDED ONE DAY
|
//SOMETHING LIKE THIS MIGHT BE NEEDED ONE DAY
|
||||||
//disable stdout buffering unless we know for sure we've been redirected to the disk
|
//disable stdout buffering unless we know for sure we've been redirected to the disk
|
||||||
//the runtime will be smart and set buffering when we may have in fact chosen to pipe the output to a console and dont want it buffered
|
//the runtime will be smart and set buffering when we may have in fact chosen to pipe the output to a console and dont want it buffered
|
||||||
//if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) != FILE_TYPE_DISK)
|
//if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) != FILE_TYPE_DISK)
|
||||||
|
@ -84,37 +84,32 @@ 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;
|
||||||
HMODULE lib = LoadLibrary("kernel32.dll");
|
if (!AllocConsole())
|
||||||
if(lib)
|
|
||||||
{
|
{
|
||||||
typedef BOOL (WINAPI *_TAttachConsole)(DWORD dwProcessId);
|
HMODULE lib = LoadLibrary("kernel32.dll");
|
||||||
_TAttachConsole _AttachConsole = (_TAttachConsole)GetProcAddress(lib,"AttachConsole");
|
if(lib)
|
||||||
if(_AttachConsole)
|
|
||||||
{
|
{
|
||||||
if(_AttachConsole(-1))
|
typedef BOOL (WINAPI *_TAttachConsole)(DWORD dwProcessId);
|
||||||
|
_TAttachConsole _AttachConsole = (_TAttachConsole)GetProcAddress(lib,"AttachConsole");
|
||||||
|
if(_AttachConsole)
|
||||||
|
{
|
||||||
|
if(!_AttachConsole(-1))
|
||||||
|
{
|
||||||
|
FreeLibrary(lib);
|
||||||
|
return;
|
||||||
|
}
|
||||||
attached = true;
|
attached = true;
|
||||||
|
}
|
||||||
|
FreeLibrary(lib);
|
||||||
}
|
}
|
||||||
FreeLibrary(lib);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
//if we failed to attach, then alloc a new console
|
|
||||||
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());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue