mirror of https://github.com/snes9xgit/snes9x.git
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)
|
bool CDirect3D::SetShaderCG(const TCHAR *file)
|
||||||
{
|
{
|
||||||
TCHAR errorMsg[MAX_PATH + 50];
|
TCHAR errorMsg[MAX_PATH + 50];
|
||||||
|
@ -371,14 +391,16 @@ bool CDirect3D::SetShaderCG(const TCHAR *file)
|
||||||
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||||
vertexProfile, "main_vertex", vertexOptions);
|
vertexProfile, "main_vertex", vertexOptions);
|
||||||
|
|
||||||
|
checkForCgError("Compiling vertex program");
|
||||||
|
|
||||||
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||||
pixelProfile, "main_fragment", pixelOptions);
|
pixelProfile, "main_fragment", pixelOptions);
|
||||||
|
|
||||||
|
checkForCgError("Compiling fragment program");
|
||||||
|
|
||||||
delete [] fileContents;
|
delete [] fileContents;
|
||||||
|
|
||||||
if(!cgVertexProgram && !cgFragmentProgram) {
|
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);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,12 +613,6 @@ void CDirect3D::SetShaderVars()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(shader_type == D3D_SHADER_CG) {
|
} 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;
|
D3DXMATRIX mvpMat;
|
||||||
D3DXVECTOR2 videoSize;
|
D3DXVECTOR2 videoSize;
|
||||||
D3DXVECTOR2 textureSize;
|
D3DXVECTOR2 textureSize;
|
||||||
|
@ -609,14 +625,25 @@ void CDirect3D::SetShaderVars()
|
||||||
|
|
||||||
D3DXMatrixIdentity(&mvpMat);
|
D3DXMatrixIdentity(&mvpMat);
|
||||||
|
|
||||||
|
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
||||||
|
|
||||||
if(cgpModelViewProj)
|
if(cgpModelViewProj)
|
||||||
cgD3D9SetUniformMatrix(cgpModelViewProj,&mvpMat);
|
cgD3D9SetUniformMatrix(cgpModelViewProj,&mvpMat);
|
||||||
if(cgpVideoSize)
|
|
||||||
cgD3D9SetUniform(cgpVideoSize,&videoSize);
|
#define setProgramUniform(program,varname,floats)\
|
||||||
if(cgpTextureSize)
|
{\
|
||||||
cgD3D9SetUniform(cgpTextureSize,&textureSize);
|
CGparameter cgp = cgGetNamedParameter(program, varname);\
|
||||||
if(cgpOutputSize)
|
if(cgp)\
|
||||||
cgD3D9SetUniform(cgpOutputSize,&outputSize);
|
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();
|
void SetShaderVars();
|
||||||
bool SetShader(const TCHAR *file);
|
bool SetShader(const TCHAR *file);
|
||||||
bool SetShaderHLSL(const TCHAR *file);
|
bool SetShaderHLSL(const TCHAR *file);
|
||||||
|
void checkForCgError(const char *situation);
|
||||||
bool SetShaderCG(const TCHAR *file);
|
bool SetShaderCG(const TCHAR *file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -282,14 +282,25 @@ void COpenGL::Render(SSurface Src)
|
||||||
} else if(shader_type == OGL_SHADER_CG) {
|
} else if(shader_type == OGL_SHADER_CG) {
|
||||||
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
CGparameter cgpModelViewProj = cgGetNamedParameter(cgVertexProgram, "modelViewProj");
|
||||||
|
|
||||||
|
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||||
|
|
||||||
CGparameter cgpVideoSize = cgGetNamedParameter(cgFragmentProgram, "IN.video_size");
|
CGparameter cgpVideoSize = cgGetNamedParameter(cgFragmentProgram, "IN.video_size");
|
||||||
CGparameter cgpTextureSize = cgGetNamedParameter(cgFragmentProgram, "IN.texture_size");
|
CGparameter cgpTextureSize = cgGetNamedParameter(cgFragmentProgram, "IN.texture_size");
|
||||||
CGparameter cgpOutputSize = cgGetNamedParameter(cgFragmentProgram, "IN.output_size");
|
CGparameter cgpOutputSize = cgGetNamedParameter(cgFragmentProgram, "IN.output_size");
|
||||||
|
|
||||||
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
#define setProgram2fv(program,varname,floats)\
|
||||||
cgGLSetParameter2fv(cgpVideoSize, inputSize);
|
{\
|
||||||
cgGLSetParameter2fv(cgpTextureSize, textureSize);
|
CGparameter cgp = cgGetNamedParameter(program, varname);\
|
||||||
cgGLSetParameter2fv(cgpOutputSize, outputSize);
|
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)
|
bool COpenGL::SetShadersCG(const TCHAR *file)
|
||||||
{
|
{
|
||||||
TCHAR errorMsg[MAX_PATH + 50];
|
TCHAR errorMsg[MAX_PATH + 50];
|
||||||
|
@ -520,14 +551,16 @@ bool COpenGL::SetShadersCG(const TCHAR *file)
|
||||||
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||||
vertexProfile, "main_vertex", NULL);
|
vertexProfile, "main_vertex", NULL);
|
||||||
|
|
||||||
|
checkForCgError("Compiling vertex program");
|
||||||
|
|
||||||
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
|
||||||
fragmentProfile, "main_fragment", NULL);
|
fragmentProfile, "main_fragment", NULL);
|
||||||
|
|
||||||
|
checkForCgError("Compiling fragment program");
|
||||||
|
|
||||||
delete [] fileContents;
|
delete [] fileContents;
|
||||||
|
|
||||||
if(!cgVertexProgram && !cgFragmentProgram) {
|
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);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,6 +246,7 @@ private:
|
||||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
||||||
|
|
||||||
bool SetShaders(const TCHAR *file);
|
bool SetShaders(const TCHAR *file);
|
||||||
|
void checkForCgError(const char *situation);
|
||||||
bool SetShadersCG(const TCHAR *file);
|
bool SetShadersCG(const TCHAR *file);
|
||||||
bool SetShadersGLSL(const TCHAR *glslFileName);
|
bool SetShadersGLSL(const TCHAR *glslFileName);
|
||||||
bool LoadShaderFunctions();
|
bool LoadShaderFunctions();
|
||||||
|
|
Loading…
Reference in New Issue