mirror of
https://github.com/libretro/snes9x.git
synced 2024-12-02 14:26:38 +00:00
Win32: update cg shader handling, output compile errors
This commit is contained in:
parent
42afceb287
commit
82fe0f7819
@ -341,6 +341,26 @@ bool CDirect3D::SetShader(const TCHAR *file)
|
||||
}
|
||||
}
|
||||
|
||||
void CDirect3D::checkForCgError(const char *situation)
|
||||
{
|
||||
char buffer[4096];
|
||||
CGerror error = cgGetError();
|
||||
const char *string = cgGetErrorString(error);
|
||||
|
||||
if (error != CG_NO_ERROR) {
|
||||
sprintf(buffer,
|
||||
"Situation: %s\n"
|
||||
"Error: %s\n\n"
|
||||
"Cg compiler output...\n", situation, string);
|
||||
MessageBoxA(0, buffer,
|
||||
"Cg error", MB_OK|MB_ICONEXCLAMATION);
|
||||
if (error == CG_COMPILER_ERROR) {
|
||||
MessageBoxA(0, cgGetLastListing(cgContext),
|
||||
"Cg compilation error", MB_OK|MB_ICONEXCLAMATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CDirect3D::SetShaderCG(const TCHAR *file)
|
||||
{
|
||||
TCHAR errorMsg[MAX_PATH + 50];
|
||||
@ -371,14 +391,16 @@ bool CDirect3D::SetShaderCG(const TCHAR *file)
|
||||
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||
vertexProfile, "main_vertex", vertexOptions);
|
||||
|
||||
checkForCgError("Compiling vertex program");
|
||||
|
||||
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||
pixelProfile, "main_fragment", pixelOptions);
|
||||
|
||||
checkForCgError("Compiling fragment program");
|
||||
|
||||
delete [] fileContents;
|
||||
|
||||
if(!cgVertexProgram && !cgFragmentProgram) {
|
||||
_stprintf(errorMsg,TEXT("No vertex or fragment program in file:\n%s"),file);
|
||||
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
|
||||
if(!cgVertexProgram || !cgFragmentProgram) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -591,12 +613,6 @@ void CDirect3D::SetShaderVars()
|
||||
}
|
||||
}
|
||||
} else if(shader_type == D3D_SHADER_CG) {
|
||||
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
||||
|
||||
CGparameter cgpVideoSize = cgGetNamedParameter(cgFragmentProgram, "IN.video_size");
|
||||
CGparameter cgpTextureSize = cgGetNamedParameter(cgFragmentProgram, "IN.texture_size");
|
||||
CGparameter cgpOutputSize = cgGetNamedParameter(cgFragmentProgram, "IN.output_size");
|
||||
|
||||
D3DXMATRIX mvpMat;
|
||||
D3DXVECTOR2 videoSize;
|
||||
D3DXVECTOR2 textureSize;
|
||||
@ -609,14 +625,25 @@ void CDirect3D::SetShaderVars()
|
||||
|
||||
D3DXMatrixIdentity(&mvpMat);
|
||||
|
||||
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
||||
|
||||
if(cgpModelViewProj)
|
||||
cgD3D9SetUniformMatrix(cgpModelViewProj,&mvpMat);
|
||||
if(cgpVideoSize)
|
||||
cgD3D9SetUniform(cgpVideoSize,&videoSize);
|
||||
if(cgpTextureSize)
|
||||
cgD3D9SetUniform(cgpTextureSize,&textureSize);
|
||||
if(cgpOutputSize)
|
||||
cgD3D9SetUniform(cgpOutputSize,&outputSize);
|
||||
|
||||
#define setProgramUniform(program,varname,floats)\
|
||||
{\
|
||||
CGparameter cgp = cgGetNamedParameter(program, varname);\
|
||||
if(cgp)\
|
||||
cgD3D9SetUniform(cgp,floats);\
|
||||
}\
|
||||
|
||||
setProgramUniform(cgFragmentProgram,"IN.video_size",&videoSize);
|
||||
setProgramUniform(cgFragmentProgram,"IN.texture_size",&textureSize);
|
||||
setProgramUniform(cgFragmentProgram,"IN.output_size",&outputSize);
|
||||
|
||||
setProgramUniform(cgVertexProgram,"IN.video_size",&videoSize);
|
||||
setProgramUniform(cgVertexProgram,"IN.texture_size",&textureSize);
|
||||
setProgramUniform(cgVertexProgram,"IN.output_size",&outputSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,6 +239,7 @@ private:
|
||||
void SetShaderVars();
|
||||
bool SetShader(const TCHAR *file);
|
||||
bool SetShaderHLSL(const TCHAR *file);
|
||||
void checkForCgError(const char *situation);
|
||||
bool SetShaderCG(const TCHAR *file);
|
||||
|
||||
public:
|
||||
|
@ -282,14 +282,25 @@ void COpenGL::Render(SSurface Src)
|
||||
} else if(shader_type == OGL_SHADER_CG) {
|
||||
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
||||
|
||||
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
|
||||
CGparameter cgpVideoSize = cgGetNamedParameter(cgFragmentProgram, "IN.video_size");
|
||||
CGparameter cgpTextureSize = cgGetNamedParameter(cgFragmentProgram, "IN.texture_size");
|
||||
CGparameter cgpOutputSize = cgGetNamedParameter(cgFragmentProgram, "IN.output_size");
|
||||
|
||||
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
cgGLSetParameter2fv(cgpVideoSize, inputSize);
|
||||
cgGLSetParameter2fv(cgpTextureSize, textureSize);
|
||||
cgGLSetParameter2fv(cgpOutputSize, outputSize);
|
||||
#define setProgram2fv(program,varname,floats)\
|
||||
{\
|
||||
CGparameter cgp = cgGetNamedParameter(program, varname);\
|
||||
if(cgp)\
|
||||
cgGLSetParameter2fv(cgp,floats);\
|
||||
}\
|
||||
|
||||
setProgram2fv(cgFragmentProgram,"IN.video_size",inputSize);
|
||||
setProgram2fv(cgFragmentProgram,"IN.texture_size",textureSize);
|
||||
setProgram2fv(cgFragmentProgram,"IN.output_size",outputSize);
|
||||
setProgram2fv(cgVertexProgram,"IN.video_size",inputSize);
|
||||
setProgram2fv(cgVertexProgram,"IN.texture_size",textureSize);
|
||||
setProgram2fv(cgVertexProgram,"IN.output_size",outputSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,6 +498,26 @@ bool COpenGL::SetShaders(const TCHAR *file)
|
||||
}
|
||||
}
|
||||
|
||||
void COpenGL::checkForCgError(const char *situation)
|
||||
{
|
||||
char buffer[4096];
|
||||
CGerror error = cgGetError();
|
||||
const char *string = cgGetErrorString(error);
|
||||
|
||||
if (error != CG_NO_ERROR) {
|
||||
sprintf(buffer,
|
||||
"Situation: %s\n"
|
||||
"Error: %s\n\n"
|
||||
"Cg compiler output...\n", situation, string);
|
||||
MessageBoxA(0, buffer,
|
||||
"Cg error", MB_OK|MB_ICONEXCLAMATION);
|
||||
if (error == CG_COMPILER_ERROR) {
|
||||
MessageBoxA(0, cgGetLastListing(cgContext),
|
||||
"Cg compilation error", MB_OK|MB_ICONEXCLAMATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool COpenGL::SetShadersCG(const TCHAR *file)
|
||||
{
|
||||
TCHAR errorMsg[MAX_PATH + 50];
|
||||
@ -520,14 +551,16 @@ bool COpenGL::SetShadersCG(const TCHAR *file)
|
||||
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||
vertexProfile, "main_vertex", NULL);
|
||||
|
||||
checkForCgError("Compiling vertex program");
|
||||
|
||||
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||
fragmentProfile, "main_fragment", NULL);
|
||||
|
||||
checkForCgError("Compiling fragment program");
|
||||
|
||||
delete [] fileContents;
|
||||
|
||||
if(!cgVertexProgram && !cgFragmentProgram) {
|
||||
_stprintf(errorMsg,TEXT("No vertex or fragment program in file:\n%s"),file);
|
||||
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
|
||||
if(!cgVertexProgram || !cgFragmentProgram) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -246,6 +246,7 @@ private:
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
||||
|
||||
bool SetShaders(const TCHAR *file);
|
||||
void checkForCgError(const char *situation);
|
||||
bool SetShadersCG(const TCHAR *file);
|
||||
bool SetShadersGLSL(const TCHAR *glslFileName);
|
||||
bool LoadShaderFunctions();
|
||||
|
Loading…
Reference in New Issue
Block a user