Initial removal of Nvidia CG. Still some more cleanup to go

This commit is contained in:
Ryan Houdek 2012-12-24 11:09:52 -06:00
parent cf8f936abb
commit 9209253e0d
28 changed files with 197 additions and 2570 deletions

View File

@ -466,23 +466,6 @@ else()
add_subdirectory(Externals/GLew)
include_directories(Externals/GLew/include)
endif(NOT GLEW_FOUND)
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
check_lib(CG Cg Cg/cg.h)
endif()
if(NOT CG_FOUND)
message("Using static Cg from Externals")
include_directories(Externals)
endif(NOT CG_FOUND)
check_lib(CGGL CgGL Cg/cgGL.h)
if(NOT CG_FOUND)
message("CG not found, Building without")
add_definitions(-DHAVE_CG=0)
set(HAVE_CG 0)
else()
add_definitions(-DHAVE_CG=1)
set(HAVE_CG 1)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

Binary file not shown.

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="2.1">
<dict>
<key>CFBundleGetInfoString</key>
<string>NVIDIA Cg version 3.0.0007</string>
<key>CFBundleIdentifier</key>
<string>com.nvidia.cg</string>
<key>CFBundleName</key>
<string>NVIDIA Cg</string>
<key>CFBundleShortVersionString</key>
<string>3.0.0007</string>
<key>IFMajorVersion</key>
<integer>3</integer>
<key>IFMinorVersion</key>
<integer>0</integer>
<key>IFPkgFlagAllowBackRev</key>
<false/>
<key>IFPkgFlagAuthorizationAction</key>
<string>RootAuthorization</string>
<key>IFPkgFlagDefaultLocation</key>
<string>/</string>
<key>IFPkgFlagInstallFat</key>
<false/>
<key>IFPkgFlagIsRequired</key>
<false/>
<key>IFPkgFlagOverwritePermissions</key>
<false/>
<key>IFPkgFlagRelocatable</key>
<false/>
<key>IFPkgFlagRestartAction</key>
<string>NoRestart</string>
<key>IFPkgFlagRootVolumeOnly</key>
<true/>
<key>IFPkgFlagUpdateInstalledLanguages</key>
<false/>
<key>IFPkgFlagUseUserMask</key>
<false/>
<key>IFPkgFormatVersion</key>
<real>0.10000000149011612</real>
</dict>
</plist>

BIN
Externals/Cg/cg.dll vendored

Binary file not shown.

1354
Externals/Cg/cg.h vendored

File diff suppressed because it is too large Load Diff

BIN
Externals/Cg/cg.lib vendored

Binary file not shown.

BIN
Externals/Cg/cgGL.dll vendored

Binary file not shown.

243
Externals/Cg/cgGL.h vendored
View File

@ -1,243 +0,0 @@
/*
*
* Copyright (c) 2002-2010, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA's copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _cggl_h
#define _cggl_h
/*************************************************************************/
/*** CGGL Run-Time Library API ***/
/*************************************************************************/
#include <Cg/cg.h>
#ifdef _WIN32
# ifndef APIENTRY /* From Win32's <windef.h> */
# define CGGL_APIENTRY_DEFINED
# if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
# define APIENTRY __stdcall
# else
# define APIENTRY
# endif
# endif
# ifndef WINGDIAPI /* From Win32's <wingdi.h> and <winnt.h> */
# define CGGL_WINGDIAPI_DEFINED
# define WINGDIAPI __declspec(dllimport)
# endif
#endif /* _WIN32 */
/* Set up CGGL_API for Win32 dllexport or gcc visibility. */
#ifndef CGGL_API
# ifdef CGGL_EXPORTS
# ifdef _WIN32
# define CGGL_API __declspec(dllexport)
# elif defined(__GNUC__) && __GNUC__>=4
# define CGGL_API __attribute__ ((visibility("default")))
# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
# define CGGL_API __global
# else
# define CGGL_API
# endif
# else
# define CGGL_API
# endif
#endif
#ifndef CGGLENTRY
# ifdef _WIN32
# define CGGLENTRY __cdecl
# else
# define CGGLENTRY
# endif
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
/*************************************************************************/
/*** Data types and enumerants ***/
/*************************************************************************/
typedef enum
{
CG_GL_MATRIX_IDENTITY = 0,
CG_GL_MATRIX_TRANSPOSE = 1,
CG_GL_MATRIX_INVERSE = 2,
CG_GL_MATRIX_INVERSE_TRANSPOSE = 3,
CG_GL_MODELVIEW_MATRIX = 4,
CG_GL_PROJECTION_MATRIX = 5,
CG_GL_TEXTURE_MATRIX = 6,
CG_GL_MODELVIEW_PROJECTION_MATRIX = 7,
CG_GL_VERTEX = 8,
CG_GL_FRAGMENT = 9,
CG_GL_GEOMETRY = 10,
CG_GL_TESSELLATION_CONTROL = 11,
CG_GL_TESSELLATION_EVALUATION = 12
} CGGLenum;
#ifdef __cplusplus
extern "C"
{
#endif
/*************************************************************************/
/*** Functions ***/
/*************************************************************************/
#ifndef CGGL_EXPLICIT
CGGL_API CGbool CGGLENTRY cgGLIsProfileSupported(CGprofile profile);
CGGL_API void CGGLENTRY cgGLEnableProfile(CGprofile profile);
CGGL_API void CGGLENTRY cgGLDisableProfile(CGprofile profile);
CGGL_API CGprofile CGGLENTRY cgGLGetLatestProfile(CGGLenum profile_type);
CGGL_API void CGGLENTRY cgGLSetOptimalOptions(CGprofile profile);
CGGL_API char const ** CGGLENTRY cgGLGetOptimalOptions(CGprofile profile);
CGGL_API void CGGLENTRY cgGLLoadProgram(CGprogram program);
CGGL_API void CGGLENTRY cgGLUnloadProgram(CGprogram program);
CGGL_API CGbool CGGLENTRY cgGLIsProgramLoaded(CGprogram program);
CGGL_API void CGGLENTRY cgGLBindProgram(CGprogram program);
CGGL_API void CGGLENTRY cgGLUnbindProgram(CGprofile profile);
CGGL_API GLuint CGGLENTRY cgGLGetProgramID(CGprogram program);
CGGL_API void CGGLENTRY cgGLSetParameter1f(CGparameter param, float x);
CGGL_API void CGGLENTRY cgGLSetParameter2f(CGparameter param, float x, float y);
CGGL_API void CGGLENTRY cgGLSetParameter3f(CGparameter param, float x, float y, float z);
CGGL_API void CGGLENTRY cgGLSetParameter4f(CGparameter param, float x, float y, float z, float w);
CGGL_API void CGGLENTRY cgGLSetParameter1fv(CGparameter param, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameter2fv(CGparameter param, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameter3fv(CGparameter param, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameter4fv(CGparameter param, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameter1d(CGparameter param, double x);
CGGL_API void CGGLENTRY cgGLSetParameter2d(CGparameter param, double x, double y);
CGGL_API void CGGLENTRY cgGLSetParameter3d(CGparameter param, double x, double y, double z);
CGGL_API void CGGLENTRY cgGLSetParameter4d(CGparameter param, double x, double y, double z, double w);
CGGL_API void CGGLENTRY cgGLSetParameter1dv(CGparameter param, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameter2dv(CGparameter param, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameter3dv(CGparameter param, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameter4dv(CGparameter param, const double *v);
CGGL_API void CGGLENTRY cgGLGetParameter1f(CGparameter param, float *v);
CGGL_API void CGGLENTRY cgGLGetParameter2f(CGparameter param, float *v);
CGGL_API void CGGLENTRY cgGLGetParameter3f(CGparameter param, float *v);
CGGL_API void CGGLENTRY cgGLGetParameter4f(CGparameter param, float *v);
CGGL_API void CGGLENTRY cgGLGetParameter1d(CGparameter param, double *v);
CGGL_API void CGGLENTRY cgGLGetParameter2d(CGparameter param, double *v);
CGGL_API void CGGLENTRY cgGLGetParameter3d(CGparameter param, double *v);
CGGL_API void CGGLENTRY cgGLGetParameter4d(CGparameter param, double *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray1f(CGparameter param, long offset, long nelements, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray2f(CGparameter param, long offset, long nelements, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray3f(CGparameter param, long offset, long nelements, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray4f(CGparameter param, long offset, long nelements, const float *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray1d(CGparameter param, long offset, long nelements, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray2d(CGparameter param, long offset, long nelements, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray3d(CGparameter param, long offset, long nelements, const double *v);
CGGL_API void CGGLENTRY cgGLSetParameterArray4d(CGparameter param, long offset, long nelements, const double *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray1f(CGparameter param, long offset, long nelements, float *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray2f(CGparameter param, long offset, long nelements, float *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray3f(CGparameter param, long offset, long nelements, float *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray4f(CGparameter param, long offset, long nelements, float *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray1d(CGparameter param, long offset, long nelements, double *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray2d(CGparameter param, long offset, long nelements, double *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray3d(CGparameter param, long offset, long nelements, double *v);
CGGL_API void CGGLENTRY cgGLGetParameterArray4d(CGparameter param, long offset, long nelements, double *v);
CGGL_API void CGGLENTRY cgGLSetParameterPointer(CGparameter param, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer);
CGGL_API void CGGLENTRY cgGLEnableClientState(CGparameter param);
CGGL_API void CGGLENTRY cgGLDisableClientState(CGparameter param);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterdr(CGparameter param, const double *matrix);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterfr(CGparameter param, const float *matrix);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterdc(CGparameter param, const double *matrix);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterfc(CGparameter param, const float *matrix);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterdr(CGparameter param, double *matrix);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterfr(CGparameter param, float *matrix);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterdc(CGparameter param, double *matrix);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterfc(CGparameter param, float *matrix);
CGGL_API void CGGLENTRY cgGLSetStateMatrixParameter(CGparameter param, CGGLenum matrix, CGGLenum transform);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterArrayfc(CGparameter param, long offset, long nelements, const float *matrices);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterArrayfr(CGparameter param, long offset, long nelements, const float *matrices);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterArraydc(CGparameter param, long offset, long nelements, const double *matrices);
CGGL_API void CGGLENTRY cgGLSetMatrixParameterArraydr(CGparameter param, long offset, long nelements, const double *matrices);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterArrayfc(CGparameter param, long offset, long nelements, float *matrices);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterArrayfr(CGparameter param, long offset, long nelements, float *matrices);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterArraydc(CGparameter param, long offset, long nelements, double *matrices);
CGGL_API void CGGLENTRY cgGLGetMatrixParameterArraydr(CGparameter param, long offset, long nelements, double *matrices);
CGGL_API void CGGLENTRY cgGLSetTextureParameter(CGparameter param, GLuint texobj);
CGGL_API GLuint CGGLENTRY cgGLGetTextureParameter(CGparameter param);
CGGL_API void CGGLENTRY cgGLEnableTextureParameter(CGparameter param);
CGGL_API void CGGLENTRY cgGLDisableTextureParameter(CGparameter param);
CGGL_API GLenum CGGLENTRY cgGLGetTextureEnum(CGparameter param);
CGGL_API void CGGLENTRY cgGLSetManageTextureParameters(CGcontext ctx, CGbool flag);
CGGL_API CGbool CGGLENTRY cgGLGetManageTextureParameters(CGcontext ctx);
CGGL_API void CGGLENTRY cgGLSetupSampler(CGparameter param, GLuint texobj);
CGGL_API void CGGLENTRY cgGLRegisterStates(CGcontext ctx);
CGGL_API void CGGLENTRY cgGLEnableProgramProfiles(CGprogram program);
CGGL_API void CGGLENTRY cgGLDisableProgramProfiles(CGprogram program);
CGGL_API void CGGLENTRY cgGLSetDebugMode(CGbool debug);
CGGL_API CGbuffer CGGLENTRY cgGLCreateBuffer(CGcontext context, int size, const void *data, GLenum bufferUsage);
CGGL_API GLuint CGGLENTRY cgGLGetBufferObject(CGbuffer buffer);
#endif
#ifdef __cplusplus
}
#endif
#ifdef CGGL_APIENTRY_DEFINED
# undef CGGL_APIENTRY_DEFINED
# undef APIENTRY
#endif
#ifdef CGGL_WINGDIAPI_DEFINED
# undef CGGL_WINGDIAPI_DEFINED
# undef WINGDIAPI
#endif
#endif

BIN
Externals/Cg/cgGL.lib vendored

Binary file not shown.

BIN
Externals/Cg64/cg.dll vendored

Binary file not shown.

BIN
Externals/Cg64/cg.lib vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -85,7 +85,7 @@ void PixelShaderManager::Shutdown()
void PixelShaderManager::SetConstants()
{
if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
Dirty();
for (int i = 0; i < 2; ++i)
{

View File

@ -184,7 +184,7 @@ void VertexShaderManager::Dirty()
// TODO: A cleaner way to control the matricies without making a mess in the parameters field
void VertexShaderManager::SetConstants()
{
if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
Dirty();
if (nTransformMatricesChanged[0] >= 0)
{

View File

@ -87,7 +87,6 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Settings", "TexFmtOverlayCenter", &bTexFmtOverlayCenter, 0);
iniFile.Get("Settings", "WireFrame", &bWireFrame, 0);
iniFile.Get("Settings", "DisableFog", &bDisableFog, 0);
iniFile.Get("Settings", "UseGLSL", &bUseGLSL, true);
iniFile.Get("Settings", "EnableOpenCL", &bEnableOpenCL, false);
iniFile.Get("Settings", "OMPDecoder", &bOMPDecoder, false);
@ -143,7 +142,6 @@ void VideoConfig::GameIniLoad(const char *ini_file)
iniFile.GetIfExists("Video_Settings", "DisableFog", &bDisableFog);
iniFile.GetIfExists("Video_Settings", "EnableOpenCL", &bEnableOpenCL);
iniFile.GetIfExists("Video_Settings", "OMPDecoder", &bOMPDecoder);
iniFile.GetIfExists("Video_Settings", "UseGLSL", &bUseGLSL);
iniFile.GetIfExists("Video_Enhancements", "ForceFiltering", &bForceFiltering);
iniFile.GetIfExists("Video_Enhancements", "MaxAnisotropy", &iMaxAnisotropy); // NOTE - this is x in (1 << x)
@ -176,7 +174,6 @@ void VideoConfig::VerifyValidity()
if (!backend_info.bSupports3DVision) b3DVision = false;
if (!backend_info.bSupportsFormatReinterpretation) bEFBEmulateFormatChanges = false;
if (!backend_info.bSupportsPixelLighting) bEnablePixelLighting = false;
if (!backend_info.bSupportsGLSL) bUseGLSL = false;
}
void VideoConfig::Save(const char *ini_file)
@ -218,7 +215,6 @@ void VideoConfig::Save(const char *ini_file)
iniFile.Set("Settings", "Wireframe", bWireFrame);
iniFile.Set("Settings", "DstAlphaPass", bDstAlphaPass);
iniFile.Set("Settings", "DisableFog", bDisableFog);
iniFile.Set("Settings", "UseGLSL", bUseGLSL);
iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL);
iniFile.Set("Settings", "OMPDecoder", bOMPDecoder);
@ -281,7 +277,6 @@ void VideoConfig::GameIniSave(const char* default_ini, const char* game_ini)
SET_IF_DIFFERS("Video_Settings", "DisableFog", bDisableFog);
SET_IF_DIFFERS("Video_Settings", "EnableOpenCL", bEnableOpenCL);
SET_IF_DIFFERS("Video_Settings", "OMPDecoder", bOMPDecoder);
SET_IF_DIFFERS("Video_Settings", "UseGLSL", bUseGLSL);
SET_IF_DIFFERS("Video_Enhancements", "ForceFiltering", bForceFiltering);
SET_IF_DIFFERS("Video_Enhancements", "MaxAnisotropy", iMaxAnisotropy); // NOTE - this is x in (1 << x)

View File

@ -103,7 +103,6 @@ struct VideoConfig
bool bWireFrame;
bool bDstAlphaPass;
bool bDisableFog;
bool bUseGLSL;
// Utility
bool bDumpTextures;

View File

@ -23,12 +23,6 @@ if(wxWidgets_FOUND)
set(LIBS ${LIBS} ${wxWidgets_LIBRARIES})
endif(wxWidgets_FOUND)
if(HAVE_CG AND (APPLE OR WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux"))
set(LIBS ${LIBS} Cg CgGL)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND LIBS "${CMAKE_SOURCE_DIR}/Externals/Cg/Cg.framework")
endif()
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBS ${LIBS} clrun)
endif()

View File

@ -113,13 +113,6 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line);
#define GL_REPORT_PROGRAM_ERROR() (void)0
#endif
#if HAVE_CG && (defined __APPLE__ || defined __linux__ || defined _WIN32)
#include <Cg/cg.h>
#include <Cg/cgGL.h>
extern CGcontext g_cgcontext;
extern CGprofile g_cgvProf, g_cgfProf;
#endif
// Isn't defined if we aren't using GLEW 1.6
#ifndef GL_ONE_MINUS_SRC1_ALPHA
#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB

View File

@ -50,11 +50,6 @@ bool PixelShaderCache::ShaderEnabled;
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
PIXELSHADERUID PixelShaderCache::last_uid;
void (*pSetPSConstant4f)(unsigned int, float, float, float, float);
void (*pSetPSConstant4fv)(unsigned int, const float*);
void (*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
bool (*pCompilePixelShader)(FRAGMENTSHADER&, const char*);
GLuint PixelShaderCache::GetDepthMatrixProgram()
{
return s_DepthMatrixProgram.glprogid;
@ -73,207 +68,88 @@ void PixelShaderCache::Init()
GL_REPORT_ERRORD();
s_displayCompileAlert = true;
char pmatrixprog[2048];
sprintf(pmatrixprog, "#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[7];\n"
"%s\n"
"void main(){\n"
"vec4 Temp0, Temp1;\n"
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
"Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
"Temp0 = Temp0 * " I_COLORS"[%d];\n"
"Temp0 = Temp0 + K0;\n"
"Temp0 = floor(Temp0);\n"
"Temp0 = Temp0 * " I_COLORS"[%d];\n"
"Temp1.x = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.y = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.z = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.w = dot(Temp0, " I_COLORS"[%d]);\n"
"gl_FragData[0] = Temp1 + " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (g_ActiveConfig.bUseGLSL)
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
pSetPSConstant4f = SetGLSLPSConstant4f;
pSetPSConstant4fv = SetGLSLPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv;
pCompilePixelShader = CompileGLSLPixelShader;
}
else
{
pSetPSConstant4f = SetCGPSConstant4f;
pSetPSConstant4fv = SetCGPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv;
pCompilePixelShader = CompileCGPixelShader;
glEnable(GL_FRAGMENT_PROGRAM_ARB);
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
sprintf(pmatrixprog, "#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[5];\n"
"%s\n"
"void main(){\n"
"vec4 R0, R1, R2;\n"
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
"vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
"R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
"R0.x = R2.x * K0.x;\n"
"R0.x = floor(R0).x;\n"
"R0.yzw = (R0 - R0.x).yzw;\n"
"R0.yzw = (R0 * K0.z).yzw;\n"
"R0.y = floor(R0).y;\n"
"R0.zw = (R0 - R0.y).zw;\n"
"R0.zw = (R0 * K0.z).zw;\n"
"R0.z = floor(R0).z;\n"
"R0.w = R0.x;\n"
"R0 = R0 * K0.y;\n"
"R0.w = (R0 * K1.x).w;\n"
"R0.w = floor(R0).w;\n"
"R0.w = (R0 * K1.y).w;\n"
"R1.x = dot(R0, " I_COLORS"[%d]);\n"
"R1.y = dot(R0, " I_COLORS"[%d]);\n"
"R1.z = dot(R0, " I_COLORS"[%d]);\n"
"R1.w = dot(R0, " I_COLORS"[%d]);\n"
"gl_FragData[0] = R1 * " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
s_nMaxPixelInstructions = 4096;
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
#if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
s_nMaxPixelInstructions = 4096;
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
s_DepthMatrixProgram.Destroy();
}
#endif
int maxinst, maxattribs;
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&maxinst);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, (GLint *)&maxattribs);
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
if (g_ActiveConfig.bUseGLSL)
{
char pmatrixprog[2048];
sprintf(pmatrixprog, "#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[7];\n"
"%s\n"
"void main(){\n"
"vec4 Temp0, Temp1;\n"
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
"Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
"Temp0 = Temp0 * " I_COLORS"[%d];\n"
"Temp0 = Temp0 + K0;\n"
"Temp0 = floor(Temp0);\n"
"Temp0 = Temp0 * " I_COLORS"[%d];\n"
"Temp1.x = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.y = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.z = dot(Temp0, " I_COLORS"[%d]);\n"
"Temp1.w = dot(Temp0, " I_COLORS"[%d]);\n"
"gl_FragData[0] = Temp1 + " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
sprintf(pmatrixprog, "#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[5];\n"
"%s\n"
"void main(){\n"
"vec4 R0, R1, R2;\n"
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
"vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
"R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
"R0.x = R2.x * K0.x;\n"
"R0.x = floor(R0).x;\n"
"R0.yzw = (R0 - R0.x).yzw;\n"
"R0.yzw = (R0 * K0.z).yzw;\n"
"R0.y = floor(R0).y;\n"
"R0.zw = (R0 - R0.y).zw;\n"
"R0.zw = (R0 * K0.z).zw;\n"
"R0.z = floor(R0).z;\n"
"R0.w = R0.x;\n"
"R0 = R0 * K0.y;\n"
"R0.w = (R0 * K1.x).w;\n"
"R0.w = floor(R0).w;\n"
"R0.w = (R0 * K1.y).w;\n"
"R1.x = dot(R0, " I_COLORS"[%d]);\n"
"R1.y = dot(R0, " I_COLORS"[%d]);\n"
"R1.z = dot(R0, " I_COLORS"[%d]);\n"
"R1.w = dot(R0, " I_COLORS"[%d]);\n"
"gl_FragData[0] = R1 * " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
s_DepthMatrixProgram.Destroy();
}
}
else
{
char pmatrixprog[2048];
sprintf(pmatrixprog, "!!ARBfp1.0"
"TEMP R0;\n"
"TEMP R1;\n"
"PARAM K0 = { 0.5, 0.5, 0.5, 0.5};\n"
"TEX R0, fragment.texcoord[0], texture[0], RECT;\n"
"MUL R0, R0, program.env[%d];\n"
"ADD R0, R0, K0;\n"
"FLR R0, R0;\n"
"MUL R0, R0, program.env[%d];\n"
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n",C_COLORS+5,C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
glGenProgramsARB(1, &s_ColorMatrixProgram.glprogid);
SetCurrentShader(s_ColorMatrixProgram.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
sprintf(pmatrixprog, "!!ARBfp1.0\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
//16777215/16777216*256, 1/255, 256, 0
"PARAM K0 = { 255.99998474121, 0.003921568627451, 256.0, 0.0};\n"
"PARAM K1 = { 15.0, 0.066666666666, 0.0, 0.0};\n"
//sample the depth value
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
//scale from [0*16777216..1*16777216] to
//[0*16777215..1*16777215], multiply by 256
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
//It is easy to get bad results due to low precision
//here, for example converting like this:
//MUL R0,R0,{ 65536, 256, 1, 16777216 }
//FRC R0,R0
//gives {?, 128/255, 254/255, ?} for depth value 254/255
//on some gpus
"FLR R0.x,R0;\n" //bits 31..24
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
"MUL R0.yzw,R0,K0.z;\n" // *256
"FLR R0.y,R0;\n" //bits 23..16
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
"MUL R0.zw,R0,K0.z;\n" // *256
"FLR R0.z,R0;\n" //bits 15..8
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
"MUL R0,R0,K0.y;\n" // /255
"MUL R0.w,R0,K1.x;\n" // *15
"FLR R0.w,R0;\n" //bits 31..28
"MUL R0.w,R0,K1.y;\n" // /15
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
glGenProgramsARB(1, &s_DepthMatrixProgram.glprogid);
SetCurrentShader(s_DepthMatrixProgram.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
s_DepthMatrixProgram.Destroy();
}
}
}
void PixelShaderCache::Shutdown()
@ -318,7 +194,7 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
// Make an entry in the table
PSCacheEntry& newentry = PixelShaders[uid];
last_entry = &newentry;
const char *code = GeneratePixelShaderCode(dstAlphaMode, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL, components);
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_GLSL, components);
if (g_ActiveConfig.bEnableShaderDebugging && code)
{
@ -348,38 +224,6 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
}
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{
return pCompilePixelShader(ps, pstrprogram);
}
// Disable Fragment programs and reset the selected Program
void PixelShaderCache::DisableShader()
{
if (ShaderEnabled)
{
glDisable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = false;
}
}
// bind a program if is different from the binded oone
void PixelShaderCache::SetCurrentShader(GLuint Shader)
{
if (!ShaderEnabled)
{
glEnable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = true;
}
if (CurrentShader != Shader)
{
if (Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
}
}
// GLSL Specific
bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{
GLuint result = glCreateShader(GL_FRAGMENT_SHADER);
@ -415,7 +259,6 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
(void)GL_REPORT_ERROR();
ps.glprogid = result;
ps.bGLSL = true;
return true;
}
@ -437,7 +280,8 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
}
}
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
// Renderer functions
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float const f[4] = {f1, f2, f3, f4};
@ -457,7 +301,7 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
}
}
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
@ -475,7 +319,7 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
}
}
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
@ -492,120 +336,4 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
}
}
}
// CG Specific
bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
}
#if defined HAVE_CG && HAVE_CG
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", NULL);
// handle errors
if (!cgIsProgram(tempprog))
{
cgDestroyProgram(tempprog);
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
return false;
}
// handle warnings
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL)
{
const char *penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local");
}
glGenProgramsARB(1, &ps.glprogid);
ps.bGLSL = false;
PixelShaderCache::SetCurrentShader(ps.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
GLint error_pos, native_limit;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
// Error occur
if (error_pos != -1) {
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
char line[256];
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
line[255] = 0;
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
} else if (native_limit != -1) {
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
// TODO
}
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
#endif
return true;
}
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float f[4] = { f1, f2, f3, f4 };
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
}
void SetCGPSConstant4fv(unsigned int const_number, const float *f)
{
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
}
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
}
// Renderer functions
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
pSetPSConstant4f(const_number, f1, f2, f3, f4);
}
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
{
pSetPSConstant4fv(const_number, f);
}
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
pSetMultiPSConstant4fv(const_number, count, f);
}
} // namespace OGL

View File

@ -29,21 +29,17 @@ namespace OGL
struct FRAGMENTSHADER
{
FRAGMENTSHADER() : glprogid(0), bGLSL(0) { }
FRAGMENTSHADER() : glprogid(0) { }
void Destroy()
{
if (glprogid)
{
if (bGLSL)
glDeleteShader(glprogid);
else
glDeleteProgramsARB(1, &glprogid);
glDeleteShader(glprogid);
glprogid = 0;
}
}
GLuint glprogid; // opengl program id
bool bGLSL;
std::string strprog;
};
@ -85,22 +81,7 @@ public:
static GLuint GetColorMatrixProgram();
static GLuint GetDepthMatrixProgram();
static void SetCurrentShader(GLuint Shader);
static void DisableShader();
};
// GLSL Specific
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f);
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
//CG Specific
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
void SetCGPSConstant4fv(unsigned int const_number, const float *f);
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
} // namespace OGL
#endif // _PIXELSHADERCACHE_H_

View File

@ -75,14 +75,14 @@ bool ApplyShader()
}
}
// TODO: Convert PP shaders to GLSL
if (s_shader.glprogid != 0)
{
PixelShaderCache::SetCurrentShader(s_shader.glprogid);
// SetBothShaders(s_shader, 0);
return true;
}
else
{
PixelShaderCache::DisableShader();
return false;
}
}

View File

@ -94,11 +94,6 @@ typedef struct
} ScrStrct;
#endif
#if defined HAVE_CG && HAVE_CG
CGcontext g_cgcontext;
CGprofile g_cgvProf;
CGprofile g_cgfProf;
#endif
int OSDInternalW, OSDInternalH;
@ -185,16 +180,6 @@ static const GLenum glLogicOpCodes[16] = {
GL_SET
};
#if defined HAVE_CG && HAVE_CG
void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
{
DEBUG_LOG(VIDEO, "Cg error: %s", cgGetErrorString(err));
const char* listing = cgGetLastListing(g_cgcontext);
if (listing != NULL)
DEBUG_LOG(VIDEO, " last listing: %s", listing);
}
#endif
int GetNumMSAASamples(int MSAAMode)
{
// required for MSAA
@ -255,12 +240,6 @@ Renderer::Renderer()
InitFPSCounter();
#if defined HAVE_CG && HAVE_CG
g_cgcontext = cgCreateContext();
cgGetError();
cgSetErrorHandler(HandleCgError, NULL);
#endif
// Look for required extensions.
const char *ptoken = (const char*)glGetString(GL_EXTENSIONS);
if (!ptoken)
@ -314,26 +293,23 @@ Renderer::Renderer()
s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL;
s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL;
if(g_ActiveConfig.bUseGLSL)
{
// TODO: Switch over to using glew once 1.6/1.7 becomes more mainstream, seems most people are stuck in 1.5
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL)
g_Config.backend_info.bSupportsGLSLBinding = true;
if (glewIsSupported("GL_ARB_blend_func_extended"))
g_Config.backend_info.bSupportsGLSLBlend = true;
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL)
g_Config.backend_info.bSupportsGLSLUBO = true;
if ((g_Config.backend_info.bSupportsGLSLBinding || g_Config.backend_info.bSupportsGLSLUBO) && strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_explicit_attrib_location") != NULL)
g_Config.backend_info.bSupportsGLSLATTRBind = true;
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_get_program_binary") != NULL)
g_Config.backend_info.bSupportsGLSLCache = true;
if (glewIsSupported("GL_ARB_shading_language_420pack"))
g_Config.backend_info.bSupportsGLSLBinding = true;
if (glewIsSupported("GL_ARB_blend_func_extended"))
g_Config.backend_info.bSupportsGLSLBlend = true;
if (glewIsSupported("GL_ARB_uniform_buffer_object"))
g_Config.backend_info.bSupportsGLSLUBO = true;
if ((g_Config.backend_info.bSupportsGLSLBinding || g_Config.backend_info.bSupportsGLSLUBO) && glewIsSupported("GL_ARB_explicit_attrib_location"))
g_Config.backend_info.bSupportsGLSLATTRBind = true;
if (glewIsSupported("GL_ARB_get_program_binary"))
g_Config.backend_info.bSupportsGLSLCache = true;
UpdateActiveConfig();
OSD::AddMessage(StringFromFormat("Using GLSL. Supports Binding: %s UBOs: %s Cache: %s",
OSD::AddMessage(StringFromFormat("Supports Binding: %s UBOs: %s Cache: %s",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "True" : "False",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "True" : "False",
g_ActiveConfig.backend_info.bSupportsGLSLCache ? "True" : "False").c_str(), 5000);
}
s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode;
s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode);
@ -411,74 +387,7 @@ Renderer::Renderer()
bSuccess = false;
s_pfont = new RasterFont();
#if defined HAVE_CG && HAVE_CG
// load the effect, find the best profiles (if any)
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE)
{
ERROR_LOG(VIDEO, "arbvp1 not supported");
return; // TODO: fail
}
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE)
{
ERROR_LOG(VIDEO, "arbfp1 not supported");
return; // TODO: fail
}
g_cgvProf = cgGLGetLatestProfile(CG_GL_VERTEX);
g_cgfProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") == NULL)
{
#if CG_VERSION_NUM == 2100
// A bug was introduced in Cg2.1's handling of very large profile option values
// so this will not work on ATI. ATI returns MAXINT = 2147483647 (0x7fffffff)
// which is correct in OpenGL but Cg fails to handle it properly. As a result
// -1 is used by Cg resulting (signedness incorrect) and compilation fails.
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") == NULL)
#endif
{
cgGLSetOptimalOptions(g_cgvProf);
cgGLSetOptimalOptions(g_cgfProf);
}
}
#else
// If we don't have Nvidia CG, we HAVE to use GLSL
g_Config.bUseGLSL = true;
UpdateActiveConfig();
INFO_LOG(VIDEO, "CG not found, switching to GLSL");
#endif // HAVE_CG
int nenvvertparams, nenvfragparams, naddrregisters[2];
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,
(GLint *)&nenvvertparams);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,
(GLint *)&nenvfragparams);
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
(GLint *)&naddrregisters[0]);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
(GLint *)&naddrregisters[1]);
DEBUG_LOG(VIDEO, "Max program env parameters: vert=%d, frag=%d",
nenvvertparams, nenvfragparams);
DEBUG_LOG(VIDEO, "Max program address register parameters: vert=%d, frag=%d",
naddrregisters[0], naddrregisters[1]);
if (nenvvertparams < 238)
ERROR_LOG(VIDEO, "Not enough vertex shader environment constants!!");
#if defined HAVE_CG && HAVE_CG
INFO_LOG(VIDEO, "Max buffer sizes: %d %d",
cgGetProgramBufferMaxSize(g_cgvProf),
cgGetProgramBufferMaxSize(g_cgfProf));
#ifndef _DEBUG
cgGLSetDebugMode(GL_FALSE);
#endif
#endif
glStencilFunc(GL_ALWAYS, 0, 0);
glBlendFunc(GL_ONE, GL_ONE);
@ -528,14 +437,6 @@ Renderer::~Renderer()
delete s_pfont;
s_pfont = 0;
#if defined HAVE_CG && HAVE_CG
if (g_cgcontext)
{
cgDestroyContext(g_cgcontext);
g_cgcontext = 0;
}
#endif
#if defined(HAVE_WX) && HAVE_WX
if (scrshotThread.joinable())
scrshotThread.join();
@ -962,7 +863,7 @@ void Renderer::SetBlendMode(bool forceUpdate)
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
bool useDualSource = useDstAlpha && g_ActiveConfig.bUseGLSL && g_ActiveConfig.backend_info.bSupportsGLSLBlend;
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsGLSLBlend;
if (changes & 1)
// blend enable change
@ -1139,7 +1040,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// It takes care of disabling it in that case. It returns false in
// case of no post processing.
if (applyShader)
PixelShaderCache::DisableShader();
ProgramShaderCache::SetBothShaders(0, 0);
}
}
else
@ -1168,7 +1069,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
glMultiTexCoord2fARB(GL_TEXTURE1, 1, 0);
glVertex2f( 1, -1);
glEnd();
PixelShaderCache::DisableShader();
ProgramShaderCache::SetBothShaders(0, 0);
}
else
{
@ -1432,13 +1333,8 @@ void Renderer::ResetAPIState()
{
// Gets us to a reasonably sane state where it's possible to do things like
// image copies with textured quads, etc.
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(0, 0);
else
{
VertexShaderCache::DisableShader();
PixelShaderCache::DisableShader();
}
ProgramShaderCache::SetBothShaders(0, 0);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
@ -1460,13 +1356,7 @@ void Renderer::RestoreAPIState()
glPolygonMode(GL_FRONT_AND_BACK, g_ActiveConfig.bWireFrame ? GL_LINE : GL_FILL);
if(g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(0, 0);
else
{
VertexShaderCache::SetCurrentShader(0);
PixelShaderCache::SetCurrentShader(0);
}
ProgramShaderCache::SetBothShaders(0, 0);
}
void Renderer::SetGenerationMode()

View File

@ -300,10 +300,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glViewport(0, 0, virtual_width, virtual_height);
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
else
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
PixelShaderManager::SetColorMatrix(colmat); // set transformation
GL_REPORT_ERRORD();

View File

@ -61,69 +61,45 @@ static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
void CreateRgbToYuyvProgram()
{
// Output is BGRA because that is slightly faster than RGBA.
if (g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
const char *FProgram =
"#version 330 compatibility\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
else
{
const char *FProgram =
"#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
const char *FProgram =
"#version 330 compatibility\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
else
{
const char *FProgram =
"uniform samplerRECT samp0 : register(s0);\n"
"void main(\n"
" out float4 ocol0 : COLOR0,\n"
" in float2 uv0 : TEXCOORD0)\n"
"#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" float2 uv1 = float2(uv0.x + 1.0f, uv0.y);\n"
" float3 c0 = texRECT(samp0, uv0).rgb;\n"
" float3 c1 = texRECT(samp0, uv1).rgb;\n"
" float3 y_const = float3(0.257f,0.504f,0.098f);\n"
" float3 u_const = float3(-0.148f,-0.291f,0.439f);\n"
" float3 v_const = float3(0.439f,-0.368f,-0.071f);\n"
" float4 const3 = float4(0.0625f,0.5f,0.0625f,0.5f);\n"
" float3 c01 = (c0 + c1) * 0.5f;\n"
" ocol0 = float4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
@ -132,82 +108,54 @@ void CreateRgbToYuyvProgram()
void CreateYuyvToRgbProgram()
{
if (g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
const char *FProgram =
"#version 330 compatibility\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
const char *FProgram =
"#version 330 compatibility\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
else
{
const char *FProgram =
"#version 120\n"
"#ifdef GL_ARB_texture_rectangle\n"
"#extension GL_ARB_texture_rectangle : require\n"
"#endif\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
else
{
const char *FProgram =
"uniform samplerRECT samp0 : register(s0);\n"
"void main(\n"
" out float4 ocol0 : COLOR0,\n"
" in float2 uv0 : TEXCOORD0)\n"
"{\n"
" float4 c0 = texRECT(samp0, uv0).rgba;\n"
"#version 120\n"
"#ifdef GL_ARB_texture_rectangle\n"
"#extension GL_ARB_texture_rectangle : require\n"
"#endif\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
" float f = step(0.5, frac(uv0.x));\n"
" float y = lerp(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" ocol0 = float4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
@ -223,7 +171,7 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)
if (s_encodingPrograms[format].glprogid == 0)
{
const char* shader = TextureConversionShader::GenerateEncodingShader(format, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
const char* shader = TextureConversionShader::GenerateEncodingShader(format, API_GLSL);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && shader)
@ -390,10 +338,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
s32 expandedWidth = (width + blkW) & (~blkW);
s32 expandedHeight = (height + blkH) & (~blkH);
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(texconv_shader.glprogid);
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
float sampleStride = bScaleByHalf ? 2.f : 1.f;
TextureConversionShader::SetShaderParameters((float)expandedWidth,
@ -425,10 +370,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
{
g_renderer->ResetAPIState();
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(s_rgbToYuyvProgram.glprogid);
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0);
EncodeToRamUsingShader(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, false);
FramebufferManager::SetFramebuffer(0);
@ -486,10 +428,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
}
glViewport(0, 0, srcWidth, srcHeight);
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
GL_REPORT_ERRORD();

View File

@ -170,7 +170,7 @@ void VertexManager::vFlush()
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
// Makes sure we can actually do Dual source blending
bool dualSourcePossible = g_ActiveConfig.bUseGLSL && g_ActiveConfig.backend_info.bSupportsGLSLBlend;
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsGLSLBlend;
// finally bind
FRAGMENTSHADER* ps;
@ -195,13 +195,7 @@ void VertexManager::vFlush()
}
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
else
{
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
}
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
// set global constants
VertexShaderManager::SetConstants();
@ -218,17 +212,12 @@ void VertexManager::vFlush()
if (useDstAlpha && !dualSourcePossible)
{
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
if (g_ActiveConfig.bUseGLSL)
{
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();
}
else
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();
// only update alpha
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

View File

@ -45,45 +45,11 @@ bool VertexShaderCache::ShaderEnabled;
VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry = NULL;
VERTEXSHADERUID VertexShaderCache::last_uid;
static int s_nMaxVertexInstructions;
void (*pSetVSConstant4f)(unsigned int, float, float, float, float);
void (*pSetVSConstant4fv)(unsigned int, const float*);
void (*pSetMultiVSConstant4fv)(unsigned int, unsigned int, const float*);
void (*pSetMultiVSConstant3fv)(unsigned int, unsigned int, const float*);
bool (*pCompileVertexShader)(VERTEXSHADER&, const char*);
void VertexShaderCache::Init()
{
ShaderEnabled = true;
CurrentShader = 0;
last_entry = NULL;
if (g_ActiveConfig.bUseGLSL)
{
pSetVSConstant4f = SetGLSLVSConstant4f;
pSetVSConstant4fv = SetGLSLVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
pCompileVertexShader = CompileGLSLVertexShader;
}
else
{
pSetVSConstant4f = SetCGVSConstant4f;
pSetVSConstant4fv = SetCGVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
pCompileVertexShader = CompileCGVertexShader;
glEnable(GL_VERTEX_PROGRAM_ARB);
}
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
#if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{
s_nMaxVertexInstructions = 4096;
}
#endif
}
void VertexShaderCache::Shutdown()
@ -123,7 +89,7 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
// Make an entry in the table
VSCacheEntry& entry = vshaders[uid];
last_entry = &entry;
const char *code = GenerateVertexShaderCode(components, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
const char *code = GenerateVertexShaderCode(components, API_GLSL);
GetSafeVertexShaderId(&entry.safe_uid, components);
#if defined(_DEBUG) || defined(DEBUGFAST)
@ -148,36 +114,6 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
}
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
return pCompileVertexShader(vs, pstrprogram);
}
void VertexShaderCache::DisableShader()
{
if (ShaderEnabled)
{
glDisable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = false;
}
}
void VertexShaderCache::SetCurrentShader(GLuint Shader)
{
if (!ShaderEnabled)
{
glEnable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled= true;
}
if (CurrentShader != Shader)
{
if (Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
}
}
// GLSL Specific
bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
GLuint result = glCreateShader(GL_VERTEX_SHADER);
@ -212,7 +148,6 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
}
(void)GL_REPORT_ERROR();
vs.glprogid = result;
vs.bGLSL = true;
return true;
}
@ -234,7 +169,7 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
}
}
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float const buf[4] = {f1, f2, f3, f4};
@ -254,7 +189,7 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
}
}
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
@ -272,7 +207,7 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
}
}
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
@ -290,7 +225,7 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
}
}
void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
@ -316,141 +251,4 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
}
}
// CG Specific
bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
}
#if defined HAVE_CG && HAVE_CG
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
if (!cgIsProgram(tempprog)) {
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
cgDestroyProgram(tempprog);
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, "%s", pstrprogram);
return false;
}
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char* penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local");
}
glGenProgramsARB(1, &vs.glprogid);
vs.bGLSL = false;
VertexShaderCache::SetCurrentShader(vs.glprogid);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
#endif
if (g_ActiveConfig.bEnableShaderDebugging)
vs.strprog = pstrprogram;
return true;
}
void SetCGVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
}
void SetCGVSConstant4fv(unsigned int const_number, const float *f)
{
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
}
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
if (GLEW_EXT_gpu_program_parameters)
{
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
}
else
{
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
}
}
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
if (GLEW_EXT_gpu_program_parameters)
{
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
{
buf[4*i ] = *f++;
buf[4*i+1] = *f++;
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
}
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
}
else
{
for (unsigned int i = 0; i < count; i++)
{
float buf[4];
buf[0] = *f++;
buf[1] = *f++;
buf[2] = *f++;
buf[3] = 0.f;
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
}
}
}
// Renderer Functions
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
pSetVSConstant4f(const_number, f1, f2, f3, f4);
}
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
{
pSetVSConstant4fv(const_number, f);
}
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
pSetMultiVSConstant4fv(const_number, count, f);
}
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
pSetMultiVSConstant3fv(const_number, count, f);
}
} // namespace OGL

View File

@ -29,18 +29,14 @@ namespace OGL
struct VERTEXSHADER
{
VERTEXSHADER() : glprogid(0), bGLSL(0) {}
VERTEXSHADER() : glprogid(0) {}
void Destroy()
{
if (bGLSL)
glDeleteShader(glprogid);
else
glDeleteProgramsARB(1, &glprogid);
glDeleteShader(glprogid);
glprogid = 0;
}
GLuint glprogid; // opengl program id
bool bGLSL;
std::string strprog;
};
@ -73,23 +69,7 @@ public:
static VERTEXSHADER* SetShader(u32 components);
static bool CompileVertexShader(VERTEXSHADER& ps, const char* pstrprogram);
static void SetCurrentShader(GLuint Shader);
static void DisableShader();
};
// GLSL Specific
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f);
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram);
// CG Specific
void SetCGVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
void SetCGVSConstant4fv(unsigned int const_number, const float *f);
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram);
} // namespace OGL
#endif // _VERTEXSHADERCACHE_H_