ZZogl-pg: Commit some of the work Zeydlitz did in r226 with separating out shader code.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3754 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-09-12 01:05:11 +00:00
parent 338589f900
commit 2f004397f6
13 changed files with 467 additions and 423 deletions

View File

@ -94,6 +94,7 @@ set(zzoglHeaders
zerogsmath.h zerogsmath.h
zpipe.h zpipe.h
ZZoglCRTC.h ZZoglCRTC.h
ZZoglShaders.h
ZZGl.h ZZGl.h
ZZLog.h) ZZLog.h)

View File

@ -36,7 +36,7 @@ using namespace std;
#include "zerogs.h" #include "zerogs.h"
#include "targets.h" #include "targets.h"
#include "ZeroGSShaders/zerogsshaders.h" #include "ZZoglShaders.h"
#include "ZZoglFlushHack.h" #include "ZZoglFlushHack.h"
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -497,6 +497,10 @@
RelativePath="..\ZZoglFlushHack.h" RelativePath="..\ZZoglFlushHack.h"
> >
</File> </File>
<File
RelativePath="..\ZZoglShaders.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"

View File

@ -46,12 +46,6 @@ inline void* wglGetProcAddress(const char* x)
#endif #endif
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <cstring>
#include "zerogsmath.h"
#include "ZeroGSShaders/zerogsshaders.h"
extern u32 s_stencilfunc, s_stencilref, s_stencilmask; extern u32 s_stencilfunc, s_stencilref, s_stencilmask;
// Defines // Defines
@ -82,47 +76,10 @@ extern u32 s_stencilfunc, s_stencilref, s_stencilmask;
// global alpha blending settings // global alpha blending settings
extern GLenum g_internalFloatFmt;
extern GLenum g_internalRGBAFloatFmt;
extern GLenum g_internalRGBAFloat16Fmt; extern GLenum g_internalRGBAFloat16Fmt;
extern CGprogram g_vsprog, g_psprog;
extern CGparameter g_vparamPosXY[2], g_fparamFogColor;
extern const char* ShaderCallerName;
extern const char* ShaderHandleName;
extern const GLenum primtype[8]; extern const GLenum primtype[8];
inline void SetShaderCaller(const char* Name)
{
ShaderCallerName = Name;
}
inline void SetHandleName(const char* Name)
{
ShaderHandleName = Name;
}
extern void HandleCgError(CGcontext ctx, CGerror err, void* appdata);
extern void ZZcgSetParameter4fv(CGparameter param, const float* v, const char* name);
#define SETVERTEXSHADER(prog) { \
if( (prog) != g_vsprog ) { \
cgGLBindProgram(prog); \
g_vsprog = prog; \
} \
} \
#define SETPIXELSHADER(prog) { \
if( (prog) != g_psprog ) { \
cgGLBindProgram(prog); \
g_psprog = prog; \
} \
} \
#define SAFE_RELEASE_PROG(x) { if( (x) != NULL ) { cgDestroyProgram(x); x = NULL; } }
#define SAFE_RELEASE_TEX(x) { if( (x) != 0 ) { glDeleteTextures(1, &(x)); x = 0; } } #define SAFE_RELEASE_TEX(x) { if( (x) != 0 ) { glDeleteTextures(1, &(x)); x = 0; } }
// inline for an extremely often used sequence // inline for an extremely often used sequence
@ -138,7 +95,6 @@ inline void DisableAllgl()
glColorMask(1, 1, 1, 1); glColorMask(1, 1, 1, 1);
} }
//--------------------- Dummies //--------------------- Dummies
#ifdef _WIN32 #ifdef _WIN32
@ -152,105 +108,8 @@ extern void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
// ------------------------ Types ------------------------- // ------------------------ Types -------------------------
struct FRAGMENTSHADER
{
FRAGMENTSHADER() : prog(0), sMemory(0), sFinal(0), sBitwiseANDX(0), sBitwiseANDY(0), sInterlace(0), sCLUT(0), sOneColor(0), sBitBltZ(0),
fTexAlpha2(0), fTexOffset(0), fTexDims(0), fTexBlock(0), fClampExts(0), fTexWrapMode(0),
fRealTexDims(0), fTestBlack(0), fPageOffset(0), fTexAlpha(0) {}
CGprogram prog;
CGparameter sMemory, sFinal, sBitwiseANDX, sBitwiseANDY, sInterlace, sCLUT;
CGparameter sOneColor, sBitBltZ, sInvTexDims;
CGparameter fTexAlpha2, fTexOffset, fTexDims, fTexBlock, fClampExts, fTexWrapMode, fRealTexDims, fTestBlack, fPageOffset, fTexAlpha;
void set_uniform_param(CGparameter &var, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE) var = p;
}
bool set_texture(GLuint texobj, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgGLSetTextureParameter(p, texobj);
cgGLEnableTextureParameter(p);
return true;
}
return false;
}
bool connect(CGparameter &tex, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgConnectParameter(tex, p);
return true;
}
return false;
}
bool set_texture(CGparameter &tex, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
//cgGLEnableTextureParameter(p);
tex = p;
return true;
}
return false;
}
bool set_shader_const(Vector v, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgGLSetParameter4fv(p, v);
return true;
}
return false;
}
};
///////////////////// /////////////////////
// graphics resources // graphics resources
extern map<string, GLbyte> mapGLExtensions;
//extern map<int, SHADERHEADER*> mapShaderResources;
struct VERTEXSHADER
{
VERTEXSHADER() : prog(0), sBitBltPos(0), sBitBltTex(0) {}
CGprogram prog;
CGparameter sBitBltPos, sBitBltTex, fBitBltTrans; // vertex shader constants
};
extern CGprofile cgvProf, cgfProf;
extern CGprogram pvs[16];
extern FRAGMENTSHADER ppsRegular[4], ppsTexture[NUM_SHADERS];
extern FRAGMENTSHADER ppsCRTC[2], ppsCRTC24[2], ppsCRTCTarg[2];
extern GLenum s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha; // set by zgsBlendFuncSeparateEXT extern GLenum s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha; // set by zgsBlendFuncSeparateEXT
// GL prototypes // GL prototypes

View File

@ -23,6 +23,7 @@
//------------------ Includes //------------------ Includes
#include "ZZoglCRTC.h" #include "ZZoglCRTC.h"
#include "GLWin.h" #include "GLWin.h"
#include "ZZoglShaders.h"
using namespace ZeroGS; using namespace ZeroGS;
@ -221,7 +222,7 @@ inline void RenderStartHelper(u32 bInterlace)
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
} }
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
glBindBuffer(GL_ARRAY_BUFFER, vboRect); glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM(); SET_STREAM();
@ -294,8 +295,7 @@ inline void RenderCreateInterlaceTex(u32 bInterlace, int th, FRAGMENTSHADER* pro
int interlacetex = CreateInterlaceTex(2 * th); int interlacetex = CreateInterlaceTex(2 * th);
cgGLSetTextureParameter(prog->sInterlace, interlacetex); ZZcgGLSetTextureParameter(prog->sInterlace, interlacetex, "Interlace");
cgGLEnableTextureParameter(prog->sInterlace);
} }
// Well, do blending setup prior to second pass of half-frame drawing // Well, do blending setup prior to second pass of half-frame drawing
@ -359,7 +359,7 @@ inline void RenderCRTC24helper(u32 bInterlace, int interlace, int psm)
SetShaderCaller("RenderCRTC24helper"); SetShaderCaller("RenderCRTC24helper");
// assume that data is already in ptexMem (do Resolve?) // assume that data is already in ptexMem (do Resolve?)
RenderGetForClip(bInterlace, interlace, psm, &ppsCRTC24[bInterlace]); RenderGetForClip(bInterlace, interlace, psm, &ppsCRTC24[bInterlace]);
SETPIXELSHADER(ppsCRTC24[bInterlace].prog); ZZcgSetPixelShader(ppsCRTC24[bInterlace].prog);
DrawTriangleArray(); DrawTriangleArray();
} }
@ -554,11 +554,10 @@ inline void RenderCheckForTargets(tex0Info& texframe, list<CRenderTarget*>& list
Vector valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTCTarg[bInterlace]); Vector valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTCTarg[bInterlace]);
// inside vb[0]'s target area, so render that region only // inside vb[0]'s target area, so render that region only
cgGLSetTextureParameter(ppsCRTCTarg[bInterlace].sFinal, ptarg->ptex); ZZcgGLSetTextureParameter(ppsCRTCTarg[bInterlace].sFinal, ptarg->ptex, "CRTC target");
cgGLEnableTextureParameter(ppsCRTCTarg[bInterlace].sFinal);
RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTCTarg[bInterlace]); RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTCTarg[bInterlace]);
SETPIXELSHADER(ppsCRTCTarg[bInterlace].prog); ZZcgSetPixelShader(ppsCRTCTarg[bInterlace].prog);
DrawTriangleArray(); DrawTriangleArray();
@ -591,10 +590,7 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
} }
// context has to be 0 // context has to be 0
CMemoryTarget* pmemtarg = g_MemTargs.GetMemoryTarget(texframe, 1); if (bInterlace >= 2) ZZLog::Error_Log("CRCR Check for memory shader fault.");
if ((pmemtarg == NULL) || (bInterlace >= 2))
ZZLog::Error_Log("CRCR Check for memory shader fault.");
//if (!(*bUsingStencil)) RenderUpdateStencil(i, bUsingStencil); //if (!(*bUsingStencil)) RenderUpdateStencil(i, bUsingStencil);
@ -607,7 +603,7 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
h1 = texframe.th; h1 = texframe.th;
w2 = -0.5f; w2 = -0.5f;
h2 = -0.5f; h2 = -0.5f;
SetTexVariablesInt(0, 2, texframe, pmemtarg, &ppsCRTC[bInterlace], 1); SetTexVariablesInt(0, 2, texframe, false, &ppsCRTC[bInterlace], 1);
} }
else else
{ {
@ -615,7 +611,7 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
h1 = 1; h1 = 1;
w2 = -0.5f / (float)texframe.tw; w2 = -0.5f / (float)texframe.tw;
h2 = -0.5f / (float)texframe.th; h2 = -0.5f / (float)texframe.th;
SetTexVariablesInt(0, 0, texframe, pmemtarg, &ppsCRTC[bInterlace], 1); SetTexVariablesInt(0, 0, texframe, false, &ppsCRTC[bInterlace], 1);
} }
if (g_bSaveFinalFrame) SaveTex(&texframe, g_bSaveFinalFrame - 1 > 0); if (g_bSaveFinalFrame) SaveTex(&texframe, g_bSaveFinalFrame - 1 > 0);
@ -630,12 +626,9 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
v = RenderSetTargetInvTex(bInterlace, texframe.tw, texframe.th, &ppsCRTC[bInterlace]); v = RenderSetTargetInvTex(bInterlace, texframe.tw, texframe.th, &ppsCRTC[bInterlace]);
Vector valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTC[bInterlace]); Vector valpha = RenderGetForClip(bInterlace, interlace, texframe.psm, &ppsCRTC[bInterlace]);
cgGLSetTextureParameter(ppsCRTC[bInterlace].sMemory, pmemtarg->ptex->tex); ZZcgGLSetTextureParameter(ppsCRTC[bInterlace].sMemory, vb[0].pmemtarg->ptex->tex, "CRTC memory");
cgGLEnableTextureParameter(ppsCRTC[bInterlace].sMemory);
RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTC[bInterlace]); RenderCreateInterlaceTex(bInterlace, texframe.th, &ppsCRTC[bInterlace]);
ZZcgSetPixelShader(ppsCRTC[bInterlace].prog);
SETPIXELSHADER(ppsCRTC[bInterlace].prog);
DrawTriangleArray(); DrawTriangleArray();
} }

View File

@ -25,7 +25,7 @@
#include "zerogs.h" #include "zerogs.h"
#include "GLWin.h" #include "GLWin.h"
#include "ZeroGSShaders/zerogsshaders.h" #include "ZZoglShaders.h"
#include "targets.h" #include "targets.h"
// This include for windows resource file with Shaders // This include for windows resource file with Shaders
#ifdef _WIN32 #ifdef _WIN32
@ -86,7 +86,6 @@ extern void KickDummy();
extern bool LoadEffects(); extern bool LoadEffects();
extern bool LoadExtraEffects(); extern bool LoadExtraEffects();
extern FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed); extern FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed);
VERTEXSHADER pvsBitBlt;
GLuint vboRect = 0; GLuint vboRect = 0;
vector<GLuint> g_vboBuffers; // VBOs for all drawing commands vector<GLuint> g_vboBuffers; // VBOs for all drawing commands
@ -159,8 +158,6 @@ int GPU_TEXWIDTH = 512;
float g_fiGPU_TEXWIDTH = 1/512.0f; float g_fiGPU_TEXWIDTH = 1/512.0f;
int g_MaxTexWidth = 4096, g_MaxTexHeight = 4096; int g_MaxTexWidth = 4096, g_MaxTexHeight = 4096;
u32 s_uFramebuffer = 0; u32 s_uFramebuffer = 0;
CGprofile cgvProf, cgfProf;
int g_nPixelShaderVer = 0; // default
RasterFont* font_p = NULL; RasterFont* font_p = NULL;
float g_fBlockMult = 1; float g_fBlockMult = 1;
@ -220,18 +217,7 @@ inline bool ZeroGS::CreateImportantCheck()
bSuccess = false; bSuccess = false;
} }
// load the effect & find the best profiles (if any) bSuccess &= ZZcgCheckProfilesSupport();
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE)
{
ZZLog::Error_Log("arbvp1 not supported.");
bSuccess = false;
}
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE)
{
ZZLog::Error_Log("arbfp1 not supported.");
bSuccess = false;
}
return bSuccess; return bSuccess;
} }
@ -440,9 +426,6 @@ inline bool CreateFillExtensionsMap()
return true; return true;
} }
const static char* g_pShaders[] = { "full", "reduced", "accurate", "accurate-reduced" };
void LoadglFunctions() void LoadglFunctions()
{ {
GL_LOADFN(glIsRenderbufferEXT); GL_LOADFN(glIsRenderbufferEXT);
@ -464,6 +447,20 @@ void LoadglFunctions()
GL_LOADFN(glGenerateMipmapEXT); GL_LOADFN(glGenerateMipmapEXT);
} }
inline bool TryBlockFormat(GLint fmt, const GLvoid* vBlockData) {
g_internalFloatFmt = fmt;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_FLOAT, vBlockData);
return (glGetError() == GL_NO_ERROR);
}
inline bool TryBlinearFormat(GLint fmt32, GLint fmt16, const GLvoid* vBilinearData) {
g_internalRGBAFloatFmt = fmt32;
g_internalRGBAFloat16Fmt = fmt16;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalRGBAFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_RGBA, GL_FLOAT, vBilinearData);
return (glGetError() == GL_NO_ERROR);
}
bool ZeroGS::Create(int _width, int _height) bool ZeroGS::Create(int _width, int _height)
{ {
GLenum err = GL_NO_ERROR; GLenum err = GL_NO_ERROR;
@ -473,7 +470,6 @@ bool ZeroGS::Create(int _width, int _height)
Destroy(1); Destroy(1);
GSStateReset(); GSStateReset();
cgSetErrorHandler(HandleCgError, NULL);
g_RenderFormatType = RFT_float16; g_RenderFormatType = RFT_float16;
if (!Create_Window(_width, _height)) return false; if (!Create_Window(_width, _height)) return false;
@ -615,42 +611,31 @@ bool ZeroGS::Create(int _width, int _height)
glGenTextures(1, &ptexBlocks); glGenTextures(1, &ptexBlocks);
glBindTexture(GL_TEXTURE_2D, ptexBlocks); glBindTexture(GL_TEXTURE_2D, ptexBlocks);
g_internalFloatFmt = GL_RGBA32F; // This is OpenGL 3.0 standard format, so it should be implemented in new cards. if (TryBlockFormat(GL_RGBA32F, &vBlockData[0]))
g_internalRGBAFloatFmt = GL_RGBA32F; ZZLog::Error_Log("Use GL_RGBA32F for blockdata.");
g_internalRGBAFloat16Fmt = GL_RGBA16F; else if (TryBlockFormat(GL_ALPHA_FLOAT32_ATI, &vBlockData[0]))
ZZLog::Error_Log("Use ATI_texture_float for blockdata.");
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_FLOAT, &vBlockData[0]); else if (TryBlockFormat(GL_ALPHA32F_ARB, &vBlockData[0]))
ZZLog::Error_Log("Use ARB_texture_float for blockdata.");
if (glGetError() != GL_NO_ERROR) else
{ { // This case is bad. But for really old cards it could be nice.
// try different internal format
g_internalFloatFmt = GL_ALPHA_FLOAT32_ATI;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_FLOAT, &vBlockData[0]);
if (glGetError() != GL_NO_ERROR)
{
// This case is bad. But for really old cards it could be nice.
g_fBlockMult = 65535.0f*(float)g_fiGPU_TEXWIDTH; g_fBlockMult = 65535.0f*(float)g_fiGPU_TEXWIDTH;
BLOCK::FillBlocks(vBlockData, vBilinearData, 0); BLOCK::FillBlocks(vBlockData, vBilinearData, 0);
g_internalFloatFmt = GL_ALPHA16; g_internalFloatFmt = GL_ALPHA16;
// We store block data on u16 rather float numbers. It's not as precise, but ALPHA16 is OpenGL 2.0 standard
// and uses only 16 bit. Old zerogs use red channel, but it does not work. // We store block data on u16 rather float numbers. It's not so preciese, but ALPHA16 is OpenGL 2.0 standart
// and use only 16 bit. Old zerogs use red channel, but it does not work.
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_UNSIGNED_SHORT, &vBlockData[0]); glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_UNSIGNED_SHORT, &vBlockData[0]);
if (glGetError() != GL_NO_ERROR) if( glGetError() != GL_NO_ERROR ) {
{ ZZLog::Error_Log("ZZogl ERROR: could not fill blocks");
ZZLog::Error_Log("Could not fill blocks.");
return false; return false;
} }
do_not_use_billinear = true; do_not_use_billinear = true;
ZZLog::Debug_Log("Using non-bilinear fill, quallity is outdated!"); conf.bilinear = 0;
ZZLog::Error_Log("Using non-bilinear fill, quallity is outdated!");
} }
else
ZZLog::Debug_Log("Use ATI_texture_float for blockdata.");
}
else
ZZLog::Debug_Log("Use GL_RGBA32F for blockdata.");
setTex2DFilters(GL_NEAREST); setTex2DFilters(GL_NEAREST);
setTex2DWrap(GL_REPEAT); setTex2DWrap(GL_REPEAT);
@ -660,33 +645,15 @@ bool ZeroGS::Create(int _width, int _height)
// fill in the bilinear blocks (main variant). // fill in the bilinear blocks (main variant).
glGenTextures(1, &ptexBilinearBlocks); glGenTextures(1, &ptexBilinearBlocks);
glBindTexture(GL_TEXTURE_2D, ptexBilinearBlocks); glBindTexture(GL_TEXTURE_2D, ptexBilinearBlocks);
glTexImage2D(GL_TEXTURE_2D, 0, g_internalRGBAFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_RGBA, GL_FLOAT, &vBilinearData[0]);
if (glGetError() != GL_NO_ERROR) if (TryBlinearFormat(GL_RGBA32F, GL_RGBA16F, &vBilinearData[0]))
{ ZZLog::Error_Log("Fill bilinear blocks OK.!");
g_internalRGBAFloatFmt = GL_RGBA_FLOAT32_ATI; else if (TryBlinearFormat(GL_RGBA_FLOAT32_ATI, GL_RGBA_FLOAT16_ATI, &vBilinearData[0]))
g_internalRGBAFloat16Fmt = GL_RGBA_FLOAT16_ATI; ZZLog::Error_Log("Fill bilinear blocks with ATI_texture_float.");
glTexImage2D(GL_TEXTURE_2D, 0, g_internalRGBAFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_RGBA, GL_FLOAT, &vBilinearData[0]); else if (TryBlinearFormat(GL_FLOAT_RGBA32_NV, GL_FLOAT_RGBA16_NV, &vBilinearData[0]))
ZZLog::Error_Log("ZZogl Fill bilinear blocks with NVidia_float.");
if (glGetError() != GL_NO_ERROR)
{
g_internalRGBAFloatFmt = GL_FLOAT_RGBA32_NV;
g_internalRGBAFloat16Fmt = GL_FLOAT_RGBA16_NV;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalRGBAFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_RGBA, GL_FLOAT, &vBilinearData[0]);
if (glGetError() != GL_NO_ERROR)
{
ZZLog::Error_Log("Fill bilinear blocks failed!");
return false;
}
else else
ZZLog::Debug_Log("Fill bilinear blocks with NVidia_float."); ZZLog::Error_Log("Fill bilinear blocks failed.");
}
else
ZZLog::Debug_Log("Fill bilinear blocks with ATI_texture_float.");
}
else
ZZLog::Debug_Log("Fill bilinear blocks OK.!");
setTex2DFilters(GL_NEAREST); setTex2DFilters(GL_NEAREST);
setTex2DWrap(GL_REPEAT); setTex2DWrap(GL_REPEAT);
@ -800,67 +767,7 @@ bool ZeroGS::Create(int _width, int _height)
if (err != GL_NO_ERROR) bSuccess = false; if (err != GL_NO_ERROR) bSuccess = false;
g_cgcontext = cgCreateContext(); if (!ZZcgStartUsingShaders()) bSuccess = false;
cgvProf = CG_PROFILE_ARBVP1;
cgfProf = CG_PROFILE_ARBFP1;
cgGLEnableProfile(cgvProf);
cgGLEnableProfile(cgfProf);
cgGLSetOptimalOptions(cgvProf);
cgGLSetOptimalOptions(cgfProf);
cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE);
//cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE);
g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4);
g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
ZZLog::GS_Log("Creating effects.");
B_G(LoadEffects(), return false);
// create a sample shader
clampInfo temp;
memset(&temp, 0, sizeof(temp));
temp.wms = 3;
temp.wmt = 3;
g_nPixelShaderVer = 0;//SHADER_ACCURATE;
// test
bool bFailed;
FRAGMENTSHADER* pfrag = LoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
if (bFailed || pfrag == NULL)
{
g_nPixelShaderVer = SHADER_ACCURATE | SHADER_REDUCED;
pfrag = LoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
if (pfrag != NULL)
cgGLLoadProgram(pfrag->prog);
if (bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR)
{
g_nPixelShaderVer = SHADER_REDUCED;
ZZLog::Error_Log("Basic shader test failed.");
}
}
if (g_nPixelShaderVer & SHADER_REDUCED) conf.bilinear = 0;
ZZLog::GS_Log("Creating extra effects.");
B_G(LoadExtraEffects(), return false);
ZZLog::GS_Log("Using %s shaders.", g_pShaders[g_nPixelShaderVer]);
GL_REPORT_ERROR(); GL_REPORT_ERROR();

View File

@ -26,6 +26,7 @@
#include "zerogs.h" #include "zerogs.h"
#include "targets.h" #include "targets.h"
#include "ZZoglFlushHack.h" #include "ZZoglFlushHack.h"
#include "ZZoglShaders.h"
using namespace ZeroGS; using namespace ZeroGS;
@ -969,10 +970,7 @@ inline FRAGMENTSHADER* FlushUseExistRenderTarget(VB& curvb, CRenderTarget* ptext
Vector vTexDims = FlushTextureDims(pfragment, shadertype, curvb, ptextarg); Vector vTexDims = FlushTextureDims(pfragment, shadertype, curvb, ptextarg);
if (pfragment->sCLUT != NULL && ptexclut != 0) if (pfragment->sCLUT != NULL && ptexclut != 0)
{ ZZcgGLSetTextureParameter(pfragment->sCLUT, ptexclut, "CLUT");
cgGLSetTextureParameter(pfragment->sCLUT, ptexclut);
cgGLEnableTextureParameter(pfragment->sCLUT);
}
FlushApplyResizeFilter(curvb, dwFilterOpts, ptextarg, context); FlushApplyResizeFilter(curvb, dwFilterOpts, ptextarg, context);
@ -1016,35 +1014,25 @@ inline void FlushSetTexture(VB& curvb, FRAGMENTSHADER* pfragment, CRenderTarget*
SetTexVariables(context, pfragment); SetTexVariables(context, pfragment);
SetTexInt(context, pfragment, ptextarg == NULL); SetTexInt(context, pfragment, ptextarg == NULL);
// have to enable the texture parameters(curtest.atst= // have to enable the texture parameters(curtest.atst)
if( curvb.ptexClamp[0] != 0 ) if( curvb.ptexClamp[0] != 0 )
{ ZZcgGLSetTextureParameter(pfragment->sBitwiseANDX, curvb.ptexClamp[0], "Clamp 0");
cgGLSetTextureParameter(pfragment->sBitwiseANDX, curvb.ptexClamp[0]);
cgGLEnableTextureParameter(pfragment->sBitwiseANDX);
}
if( curvb.ptexClamp[1] != 0 ) if( curvb.ptexClamp[1] != 0 )
{ ZZcgGLSetTextureParameter(pfragment->sBitwiseANDY, curvb.ptexClamp[1], "Clamp 1");
cgGLSetTextureParameter(pfragment->sBitwiseANDY, curvb.ptexClamp[1]);
cgGLEnableTextureParameter(pfragment->sBitwiseANDY);
}
if( pfragment->sMemory != NULL && s_ptexCurSet[context] != 0) if( pfragment->sMemory != NULL && s_ptexCurSet[context] != 0)
{ ZZcgGLSetTextureParameter(pfragment->sMemory, s_ptexCurSet[context], "Clamp memory");
cgGLSetTextureParameter(pfragment->sMemory, s_ptexCurSet[context]);
cgGLEnableTextureParameter(pfragment->sMemory);
}
} }
// Reset programm and texture variables; // Reset program and texture variables;
inline void FlushBindProgramm(FRAGMENTSHADER* pfragment, int context) inline void FlushBindProgramm(FRAGMENTSHADER* pfragment, int context)
{ {
vb[context].bTexConstsSync = 0; vb[context].bTexConstsSync = 0;
vb[context].bVarsTexSync = 0; vb[context].bVarsTexSync = 0;
cgGLBindProgram(pfragment->prog); ZZcgSetPixelShader(pfragment->prog);
g_psprog = pfragment->prog;
} }
inline FRAGMENTSHADER* FlushRendererStage(VB& curvb, u32& dwFilterOpts, CRenderTarget* ptextarg, int exactcolor, int context) inline FRAGMENTSHADER* FlushRendererStage(VB& curvb, u32& dwFilterOpts, CRenderTarget* ptextarg, int exactcolor, int context)
@ -1078,7 +1066,7 @@ inline FRAGMENTSHADER* FlushRendererStage(VB& curvb, u32& dwFilterOpts, CRenderT
// set the shaders // set the shaders
SetShaderCaller("FlushRendererStage"); SetShaderCaller("FlushRendererStage");
SETVERTEXSHADER(pvs[2 * ((curvb.curprim._val >> 1) & 3) + 8 * s_bWriteDepth + context]); ZZcgSetVertexShader(pvs[2 * ((curvb.curprim._val >> 1) & 3) + 8 * s_bWriteDepth + context]);
FlushBindProgramm(pfragment, context); FlushBindProgramm(pfragment, context);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
@ -1501,7 +1489,7 @@ inline void AlphaColorClamping(VB& curvb, const pixTest curtest)
SetShaderCaller("AlphaColorClamping"); SetShaderCaller("AlphaColorClamping");
SETPIXELSHADER(ppsOne.prog); ZZcgSetPixelShader(ppsOne.prog);
GL_BLEND_RGB(GL_ONE, GL_ONE); GL_BLEND_RGB(GL_ONE, GL_ONE);
float f; float f;
@ -1764,7 +1752,7 @@ inline void ZeroGS::ProcessStencil(const VB& curvb)
SetShaderCaller("ProcessStencil"); SetShaderCaller("ProcessStencil");
SETPIXELSHADER(ppsOne.prog); ZZcgSetPixelShader(ppsOne.prog);
Draw(curvb); Draw(curvb);
// process when alpha >= 0xff // process when alpha >= 0xff
@ -1825,7 +1813,7 @@ __forceinline void ZeroGS::ProcessFBA(const VB& curvb, CGparameter sOneColor)
float f = 1; float f = 1;
ZZcgSetParameter4fv(sOneColor, &f, "g_fOneColor"); ZZcgSetParameter4fv(sOneColor, &f, "g_fOneColor");
SETPIXELSHADER(ppsOne.prog); ZZcgSetPixelShader(ppsOne.prog);
Draw(curvb); Draw(curvb);
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
@ -1981,13 +1969,13 @@ void ZeroGS::SetTexInt(int context, FRAGMENTSHADER* pfragment, int settexint)
{ {
if (vb[context].pmemtarg != pmemtarg) if (vb[context].pmemtarg != pmemtarg)
{ {
SetTexVariablesInt(context, GetTexFilter(vb[context].tex1), tex0, pmemtarg, pfragment, s_bForceTexFlush); SetTexVariablesInt(context, GetTexFilter(vb[context].tex1), tex0, true, pfragment, s_bForceTexFlush);
vb[context].bVarsTexSync = true; vb[context].bVarsTexSync = true;
} }
} }
else else
{ {
SetTexVariablesInt(context, GetTexFilter(vb[context].tex1), tex0, pmemtarg, pfragment, s_bForceTexFlush); SetTexVariablesInt(context, GetTexFilter(vb[context].tex1), tex0, false, pfragment, s_bForceTexFlush);
vb[context].bVarsTexSync = true; vb[context].bVarsTexSync = true;
INC_TEXVARS(); INC_TEXVARS();
@ -2278,18 +2266,21 @@ void ZeroGS::SetTexVariables(int context, FRAGMENTSHADER* pfragment)
} }
} }
void ZeroGS::SetTexVariablesInt(int context, int bilinear, const tex0Info& tex0, CMemoryTarget* pmemtarg, FRAGMENTSHADER* pfragment, int force) void ZeroGS::SetTexVariablesInt(int context, int bilinear, const tex0Info& tex0, bool CheckVB, FRAGMENTSHADER* pfragment, int force)
{ {
FUNCLOG FUNCLOG
Vector v; Vector v;
assert(pmemtarg != NULL && pfragment != NULL && pmemtarg->ptex != NULL); CMemoryTarget* pmemtarg = g_MemTargs.GetMemoryTarget(tex0, 1);
assert( pmemtarg != NULL && pfragment != NULL && pmemtarg->ptex != NULL);
if (pmemtarg == NULL || pfragment == NULL || pmemtarg->ptex == NULL) if (pmemtarg == NULL || pfragment == NULL || pmemtarg->ptex == NULL)
{ {
ZZLog::Error_Log("SetTexVariablesInt error."); ZZLog::Error_Log("SetTexVariablesInt error.");
return; return;
} }
if (CheckVB && vb[context].pmemtarg == pmemtarg) return;
SetShaderCaller("SetTexVariablesInt"); SetShaderCaller("SetTexVariablesInt");
float fw = (float)tex0.tw; float fw = (float)tex0.tw;

View File

@ -21,7 +21,7 @@
//------------------- Includes //------------------- Includes
#include "zerogs.h" #include "zerogs.h"
#include "ZeroGSShaders/zerogsshaders.h" #include "ZZoglShaders.h"
#include "zpipe.h" #include "zpipe.h"
// ----------------- Defines // ----------------- Defines
@ -35,6 +35,7 @@ namespace ZeroGS
{ {
FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne; FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne;
FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16; FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16;
VERTEXSHADER pvsBitBlt;
} }
// Debug variable, store name of the function that call the shader. // Debug variable, store name of the function that call the shader.
@ -48,9 +49,24 @@ bool g_bCRTCBilinear = true;
u8* s_lpShaderResources = NULL; u8* s_lpShaderResources = NULL;
map<int, SHADERHEADER*> mapShaderResources; map<int, SHADERHEADER*> mapShaderResources;
CGcontext g_cgcontext; CGcontext g_cgcontext;
CGprofile cgvProf, cgfProf;
int g_nPixelShaderVer = 0; // default
//------------------ Code //------------------ Code
bool ZZcgCheckProfilesSupport() {
// load the effect, find the best profiles (if any)
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE) {
ZZLog::Error_Log("arbvp1 not supported.");
return false;
}
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE) {
ZZLog::Error_Log("arbfp1 not supported.");
return false;
}
return true;
}
// Error handler. Setup in ZZogl_Create once. // Error handler. Setup in ZZogl_Create once.
void HandleCgError(CGcontext ctx, CGerror err, void* appdata) void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
{ {
@ -60,6 +76,70 @@ void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
if (listing != NULL) ZZLog::Debug_Log(" Last listing: %s", listing); if (listing != NULL) ZZLog::Debug_Log(" Last listing: %s", listing);
} }
bool ZZcgStartUsingShaders() {
cgSetErrorHandler(HandleCgError, NULL);
g_cgcontext = cgCreateContext();
cgvProf = CG_PROFILE_ARBVP1;
cgfProf = CG_PROFILE_ARBFP1;
cgGLEnableProfile(cgvProf);
cgGLEnableProfile(cgfProf);
cgGLSetOptimalOptions(cgvProf);
cgGLSetOptimalOptions(cgfProf);
cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE);
//cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE);
g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4);
g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
ZZLog::Debug_Log("Creating effects.");
B_G(LoadEffects(), return false);
// create a sample shader
clampInfo temp;
memset(&temp, 0, sizeof(temp));
temp.wms = 3; temp.wmt = 3;
g_nPixelShaderVer = 0;//SHADER_ACCURATE;
// test
bool bFailed;
FRAGMENTSHADER* pfrag = LoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
if( bFailed || pfrag == NULL ) {
g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED;
pfrag = LoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
if( pfrag != NULL )
cgGLLoadProgram(pfrag->prog);
if( bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR ) {
g_nPixelShaderVer = SHADER_REDUCED;
ZZLog::Error_Log("Basic shader test failed.");
}
}
if (g_nPixelShaderVer & SHADER_REDUCED)
conf.bilinear = 0;
ZZLog::Debug_Log("Creating extra effects.");
B_G(LoadExtraEffects(), return false);
ZZLog::Debug_Log("using %s shaders.", g_pShaders[g_nPixelShaderVer]);
return true;
}
// Disable CG
void ZZcgGLDisableProfile() {
cgGLDisableProfile(cgvProf);
cgGLDisableProfile(cgfProf);
}
//Enable CG
void ZZcgGLEnableProfile() {
cgGLEnableProfile(cgvProf);
cgGLEnableProfile(cgfProf);
}
// This is a helper of cgGLSetParameter4fv, made for debugging purposes. // This is a helper of cgGLSetParameter4fv, made for debugging purposes.
// The name could be any string. We must use it on compilation time, because the erronious handler does not // The name could be any string. We must use it on compilation time, because the erronious handler does not
// return it. // return it.
@ -69,6 +149,34 @@ void ZZcgSetParameter4fv(CGparameter param, const float* v, const char* name)
cgGLSetParameter4fv(param, v); cgGLSetParameter4fv(param, v);
} }
// The same function for texture, also to cgGLEnable
void ZZcgGLSetTextureParameter(CGparameter param, GLuint texobj, const char* name) {
ShaderHandleName = name;
cgGLSetTextureParameter(param, texobj);
cgGLEnableTextureParameter(param);
}
// Used sometimes for color 1.
void ZZcgDefaultOneColor( FRAGMENTSHADER ptr ) {
ShaderHandleName = "Set Default One color";
Vector v = Vector ( 1, 1, 1, 1 );
ZZcgSetParameter4fv( ptr.sOneColor, v, "DefaultOne");
}
void ZZcgSetVertexShader(CGprogram prog) {
if ((prog) != g_vsprog) {
cgGLBindProgram(prog);
g_vsprog = prog;
}
}
void ZZcgSetPixelShader(CGprogram prog) {
if ((prog) != g_psprog) {
cgGLBindProgram(prog);
g_psprog = prog;
}
}
void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int type) void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int type)
{ {
// uniform parameters // uniform parameters

View File

@ -0,0 +1,228 @@
/* ZZ Open GL graphics plugin
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __ZEROGS_SHADERS_H__
#define __ZEROGS_SHADERS_H__
// I'll need to figure out a way to get rid of this dependency... --arcum42
#include "GS.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#define NUM_FILTERS 2 // texture filtering
#define NUM_TYPES 5 // types of texture read modes
#define NUM_TEXWRAPS 4 // texture wrapping
#define SHADER_REDUCED 1 // equivalent to ps2.0
#define SHADER_ACCURATE 2 // for older cards with less accurate math (ps2.x+)
#define NUM_SHADERS (NUM_FILTERS*NUM_TYPES*NUM_TEXWRAPS*32) // # shaders for a given ps
const static char* g_pShaders[] = { "full", "reduced", "accurate", "accurate-reduced" };
const static char* g_pPsTexWrap[] = { "-DREPEAT", "-DCLAMP", "-DREGION_REPEAT", NULL };
const static char* g_pTexTypes[] = { "32", "tex32", "clut32", "tex32to16", "tex16to8h" };
#define TEXWRAP_REPEAT 0
#define TEXWRAP_CLAMP 1
#define TEXWRAP_REGION_REPEAT 2
#define TEXWRAP_REPEAT_CLAMP 3
inline int GET_SHADER_INDEX(int type, int texfilter, int texwrap, int fog, int writedepth, int testaem, int exactcolor, int context, int ps)
{
return type + texfilter*NUM_TYPES + NUM_FILTERS*NUM_TYPES*texwrap + NUM_TEXWRAPS*NUM_FILTERS*NUM_TYPES*(fog+2*writedepth+4*testaem+8*exactcolor+16*context+32*ps);
}
struct SHADERHEADER
{
unsigned int index, offset, size; // if highest bit of index is set, pixel shader
};
#define SH_WRITEDEPTH 0x2000 // depth is written
#define SH_CONTEXT1 0x1000 // context1 is used
#define SH_REGULARVS 0x8000
#define SH_TEXTUREVS 0x8001
#define SH_REGULARFOGVS 0x8002
#define SH_TEXTUREFOGVS 0x8003
#define SH_REGULARPS 0x8004
#define SH_REGULARFOGPS 0x8005
#define SH_BITBLTVS 0x8006
#define SH_BITBLTPS 0x8007
#define SH_BITBLTDEPTHPS 0x8009
#define SH_CRTCTARGPS 0x800a
#define SH_CRTCPS 0x800b
#define SH_CRTC24PS 0x800c
#define SH_ZEROPS 0x800e
#define SH_BASETEXTUREPS 0x800f
#define SH_BITBLTAAPS 0x8010
#define SH_CRTCTARGINTERPS 0x8012
#define SH_CRTCINTERPS 0x8013
#define SH_CRTC24INTERPS 0x8014
#define SH_BITBLTDEPTHMRTPS 0x8016
#define SH_CONVERT16TO32PS 0x8020
#define SH_CONVERT32TO16PS 0x8021
#define SH_CRTC_NEARESTPS 0x8022
#define SH_CRTCINTER_NEARESTPS 0x8023
struct FRAGMENTSHADER
{
FRAGMENTSHADER() : prog(0), sMemory(0), sFinal(0), sBitwiseANDX(0), sBitwiseANDY(0), sInterlace(0), sCLUT(0), sOneColor(0), sBitBltZ(0),
fTexAlpha2(0), fTexOffset(0), fTexDims(0), fTexBlock(0), fClampExts(0), fTexWrapMode(0),
fRealTexDims(0), fTestBlack(0), fPageOffset(0), fTexAlpha(0) {}
CGprogram prog;
CGparameter sMemory, sFinal, sBitwiseANDX, sBitwiseANDY, sInterlace, sCLUT;
CGparameter sOneColor, sBitBltZ, sInvTexDims;
CGparameter fTexAlpha2, fTexOffset, fTexDims, fTexBlock, fClampExts, fTexWrapMode, fRealTexDims, fTestBlack, fPageOffset, fTexAlpha;
#ifdef _DEBUG
string filename;
#endif
void set_uniform_param(CGparameter &var, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE) var = p;
}
bool set_texture(GLuint texobj, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgGLSetTextureParameter(p, texobj);
cgGLEnableTextureParameter(p);
return true;
}
return false;
}
bool connect(CGparameter &tex, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgConnectParameter(tex, p);
return true;
}
return false;
}
bool set_texture(CGparameter &tex, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
//cgGLEnableTextureParameter(p);
tex = p;
return true;
}
return false;
}
bool set_shader_const(Vector v, const char *name)
{
CGparameter p;
p = cgGetNamedParameter(prog, name);
if (p != NULL && cgIsParameterUsed(p, prog) == CG_TRUE)
{
cgGLSetParameter4fv(p, v);
return true;
}
return false;
}
};
struct VERTEXSHADER
{
VERTEXSHADER() : prog(0), sBitBltPos(0), sBitBltTex(0) {}
CGprogram prog;
CGparameter sBitBltPos, sBitBltTex, fBitBltTrans; // vertex shader constants
};
// ------------------------- Variables -------------------------------
extern u8* s_lpShaderResources;
extern CGprofile cgvProf, cgfProf;
extern int g_nPixelShaderVer;
extern CGprogram pvs[16];
extern FRAGMENTSHADER ppsRegular[4], ppsTexture[NUM_SHADERS];
extern FRAGMENTSHADER ppsCRTC[2], ppsCRTC24[2], ppsCRTCTarg[2];
extern CGprogram g_vsprog, g_psprog;
extern CGparameter g_vparamPosXY[2], g_fparamFogColor;
// ------------------------- Functions -------------------------------
extern const char* ShaderCallerName;
extern const char* ShaderHandleName;
inline void SetShaderCaller(const char* Name) {
ShaderCallerName = Name;
}
inline void SetHandleName(const char* Name) {
ShaderHandleName = Name;
}
extern bool ZZcgCheckProfilesSupport();
extern bool ZZcgStartUsingShaders();
extern void ZZcgGLDisableProfile();
extern void ZZcgGLEnableProfile();
extern void ZZcgSetParameter4fv(CGparameter param, const float* v, const char* name);
extern void ZZcgGLSetTextureParameter(CGparameter param, GLuint texobj, const char* name);
extern void ZZcgDefaultOneColor( FRAGMENTSHADER ptr );
extern void ZZcgSetVertexShader(CGprogram prog);
extern void ZZcgSetPixelShader(CGprogram prog);
#define SAFE_RELEASE_PROG(x) { if( (x) != NULL ) { cgDestroyProgram(x); x = NULL; } }
namespace ZeroGS {
// Shaders variables
extern Vector g_vdepth;
extern Vector vlogz;
extern VERTEXSHADER pvsBitBlt;
extern FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne;
extern FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16;
bool LoadEffects();
bool LoadExtraEffects();
FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed);
// only sets a limited amount of state (for Update)
void SetTexClamping(int context, FRAGMENTSHADER* pfragment);
void SetTexVariablesInt(int context, int bilinear, const tex0Info& tex0, bool CheckVB, FRAGMENTSHADER* pfragment, int force);
}
#endif

View File

@ -18,8 +18,6 @@
*/ */
#include "GS.h" #include "GS.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <stdlib.h> #include <stdlib.h>
@ -27,6 +25,7 @@
#include "x86.h" #include "x86.h"
#include "zerogs.h" #include "zerogs.h"
#include "targets.h" #include "targets.h"
#include "ZZoglShaders.h"
#define RHA #define RHA
//#define RW //#define RW
@ -434,8 +433,7 @@ void ZeroGS::CRenderTarget::Update(int context, ZeroGS::CRenderTarget* pdepth)
if (nUpdateTarg) if (nUpdateTarg)
{ {
cgGLSetTextureParameter(ppsBaseTexture.sFinal, ittarg->second->ptex); ZZcgGLSetTextureParameter(ppsBaseTexture.sFinal, ittarg->second->ptex, "BaseTexture.final");
cgGLEnableTextureParameter(ppsBaseTexture.sFinal);
//assert( ittarg->second->fbw == fbw ); //assert( ittarg->second->fbw == fbw );
int offset = (fbp - ittarg->second->fbp) * 64 / fbw; int offset = (fbp - ittarg->second->fbp) * 64 / fbw;
@ -451,9 +449,9 @@ void ZeroGS::CRenderTarget::Update(int context, ZeroGS::CRenderTarget* pdepth)
ZZcgSetParameter4fv(pvsBitBlt.sBitBltTex, v, "g_fBitBltTex"); ZZcgSetParameter4fv(pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
// v = DefaultBitBltTex(); Maybe? // v = DefaultBitBltTex(); Maybe?
v = DefaultOneColor(ppsBaseTexture) ; ZZcgDefaultOneColor ( ppsBaseTexture );
SETPIXELSHADER(ppsBaseTexture.prog); ZZcgSetPixelShader(ppsBaseTexture.prog);
nUpdateTarg = 0; nUpdateTarg = 0;
} }
@ -469,15 +467,13 @@ void ZeroGS::CRenderTarget::Update(int context, ZeroGS::CRenderTarget* pdepth)
texframe.tw = fbw; texframe.tw = fbw;
texframe.th = fbh; texframe.th = fbh;
texframe.psm = psm; texframe.psm = psm;
CMemoryTarget* pmemtarg = g_MemTargs.GetMemoryTarget(texframe, 1);
// write color and zero out stencil buf, always 0 context! // write color and zero out stencil buf, always 0 context!
// force bilinear if using AA // force bilinear if using AA
// Fix in r133 -- FFX movies and Gust backgrounds! // Fix in r133 -- FFX movies and Gust backgrounds!
//SetTexVariablesInt(0, 0*(s_AAx || s_AAy) ? 2 : 0, texframe, pmemtarg, &ppsBitBlt[!!s_AAx], 1); //SetTexVariablesInt(0, 0*(s_AAx || s_AAy)?2:0, texframe, false, &ppsBitBlt[!!s_AAx], 1);
SetTexVariablesInt(0, 0, texframe, pmemtarg, &ppsBitBlt[bit_idx], 1); SetTexVariablesInt(0, 0, texframe, false, &ppsBitBlt[bit_idx], 1);
cgGLSetTextureParameter(ppsBitBlt[bit_idx].sMemory, pmemtarg->ptex->tex); ZZcgGLSetTextureParameter(ppsBitBlt[bit_idx].sMemory, vb[0].pmemtarg->ptex->tex, "BitBlt.memory");
cgGLEnableTextureParameter(ppsBitBlt[bit_idx].sMemory);
v = Vector(1, 1, 0.0f, 0.0f); v = Vector(1, 1, 0.0f, 0.0f);
ZZcgSetParameter4fv(pvsBitBlt.sBitBltTex, v, "g_fBitBltTex"); ZZcgSetParameter4fv(pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
@ -500,10 +496,10 @@ void ZeroGS::CRenderTarget::Update(int context, ZeroGS::CRenderTarget* pdepth)
// render with an AA shader if possible (bilinearly interpolates data) // render with an AA shader if possible (bilinearly interpolates data)
//cgGLLoadProgram(ppsBitBlt[bit_idx].prog); //cgGLLoadProgram(ppsBitBlt[bit_idx].prog);
SETPIXELSHADER(ppsBitBlt[bit_idx].prog); ZZcgSetPixelShader(ppsBitBlt[bit_idx].prog);
} }
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
DrawTriangleArray(); DrawTriangleArray();
@ -573,9 +569,7 @@ void ZeroGS::CRenderTarget::ConvertTo32()
ZeroGS::ResetRenderTarget(1); ZeroGS::ResetRenderTarget(1);
BindToSample(&ptex); BindToSample(&ptex);
ZZcgGLSetTextureParameter(ppsConvert16to32.sFinal, ptex, "Convert 16 to 32.Final");
cgGLSetTextureParameter(ppsConvert16to32.sFinal, ptex);
cgGLEnableTextureParameter(ppsBitBlt[!!s_AAx].sMemory);
fbh /= 2; // have 16 bit surfaces are usually 2x higher fbh /= 2; // have 16 bit surfaces are usually 2x higher
SetViewport(); SetViewport();
@ -583,9 +577,8 @@ void ZeroGS::CRenderTarget::ConvertTo32()
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// render with an AA shader if possible (bilinearly interpolates data) // render with an AA shader if possible (bilinearly interpolates data)
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
ZZcgSetPixelShader(ppsConvert16to32.prog);
SETPIXELSHADER(ppsConvert16to32.prog);
DrawTriangleArray(); DrawTriangleArray();
#ifdef _DEBUG #ifdef _DEBUG
@ -603,7 +596,6 @@ void ZeroGS::CRenderTarget::ConvertTo32()
// restore // restore
SAFE_RELEASE_TEX(ptex); SAFE_RELEASE_TEX(ptex);
SAFE_RELEASE_TEX(ptexFeedback); SAFE_RELEASE_TEX(ptexFeedback);
ptex = ptexConv; ptex = ptexConv;
@ -680,8 +672,7 @@ void ZeroGS::CRenderTarget::ConvertTo16()
BindToSample(&ptex); BindToSample(&ptex);
cgGLSetTextureParameter(ppsConvert32to16.sFinal, ptex); ZZcgGLSetTextureParameter(ppsConvert32to16.sFinal, ptex, "Convert 32 to 16");
cgGLEnableTextureParameter(ppsConvert32to16.sFinal);
// fbh *= 2; // have 16 bit surfaces are usually 2x higher // fbh *= 2; // have 16 bit surfaces are usually 2x higher
@ -690,9 +681,8 @@ void ZeroGS::CRenderTarget::ConvertTo16()
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// render with an AA shader if possible (bilinearly interpolates data) // render with an AA shader if possible (bilinearly interpolates data)
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
ZZcgSetPixelShader(ppsConvert32to16.prog);
SETPIXELSHADER(ppsConvert32to16.prog);
DrawTriangleArray(); DrawTriangleArray();
#ifdef _DEBUG #ifdef _DEBUG
@ -705,7 +695,6 @@ void ZeroGS::CRenderTarget::ConvertTo16()
#endif #endif
vposxy.y = -2.0f * (32767.0f / 8.0f) / (float)fbh; vposxy.y = -2.0f * (32767.0f / 8.0f) / (float)fbh;
vposxy.w = 1 + 0.5f / fbh; vposxy.w = 1 + 0.5f / fbh;
// restore // restore
@ -775,8 +764,8 @@ void ZeroGS::CRenderTarget::_CreateFeedback()
v.y = (float)(RH(fbh)); v.y = (float)(RH(fbh));
v.z = 0.0f; v.z = 0.0f;
v.w = 0.0f; v.w = 0.0f;
cgGLSetParameter4fv(pvsBitBlt.sBitBltTex, v); ZZcgSetParameter4fv(pvsBitBlt.sBitBltTex, v, "BitBlt.Feedback");
v = DefaultOneColor(ppsBaseTexture); ZZcgDefaultOneColor(ppsBaseTexture);
glBindBuffer(GL_ARRAY_BUFFER, vboRect); glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM(); SET_STREAM();
@ -785,16 +774,15 @@ void ZeroGS::CRenderTarget::_CreateFeedback()
glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptex); glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptex);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
cgGLSetTextureParameter(ppsBaseTexture.sFinal, ptex); ZZcgGLSetTextureParameter(ppsBaseTexture.sFinal, ptex, "BaseTexture.Feedback");
cgGLEnableTextureParameter(ppsBaseTexture.sFinal);
SetViewport(); SetViewport();
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// render with an AA shader if possible (bilinearly interpolates data) // render with an AA shader if possible (bilinearly interpolates data)
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
SETPIXELSHADER(ppsBaseTexture.prog); ZZcgSetPixelShader(ppsBaseTexture.prog);
DrawTriangleArray(); DrawTriangleArray();
// restore // restore
@ -970,7 +958,6 @@ void ZeroGS::CDepthTarget::Update(int context, ZeroGS::CRenderTarget* prndr)
texframe.tw = fbw; texframe.tw = fbw;
texframe.th = fbh; texframe.th = fbh;
texframe.psm = psm; texframe.psm = psm;
CMemoryTarget* pmemtarg = g_MemTargs.GetMemoryTarget(texframe, 1);
DisableAllgl(); DisableAllgl();
@ -989,10 +976,8 @@ void ZeroGS::CDepthTarget::Update(int context, ZeroGS::CRenderTarget* prndr)
glDepthFunc(g_dwZCmp[curvb.test.ztst]); glDepthFunc(g_dwZCmp[curvb.test.ztst]);
// write color and zero out stencil buf, always 0 context! // write color and zero out stencil buf, always 0 context!
SetTexVariablesInt(0, 0, texframe, pmemtarg, &ppsBitBltDepth, 1); SetTexVariablesInt(0, 0, texframe, false, &ppsBitBltDepth, 1);
ZZcgGLSetTextureParameter(ppsBitBltDepth.sMemory, vb[0].pmemtarg->ptex->tex, "BitBltDepth");
cgGLSetTextureParameter(ppsBitBltDepth.sMemory, pmemtarg->ptex->tex);
cgGLEnableTextureParameter(ppsBaseTexture.sFinal);
Vector v = DefaultBitBltPos(); Vector v = DefaultBitBltPos();
@ -1042,8 +1027,8 @@ void ZeroGS::CDepthTarget::Update(int context, ZeroGS::CRenderTarget* prndr)
glBindBuffer(GL_ARRAY_BUFFER, vboRect); glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM(); SET_STREAM();
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
SETPIXELSHADER(ppsBitBltDepth.prog); ZZcgSetPixelShader(ppsBitBltDepth.prog);
DrawTriangleArray(); DrawTriangleArray();

View File

@ -27,13 +27,6 @@
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV #define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
#endif #endif
inline Vector DefaultOneColor(FRAGMENTSHADER ptr)
{
Vector v = Vector(1, 1, 1, 1);
cgGLSetParameter4fv(ptr.sOneColor, v);
return v ;
}
namespace ZeroGS namespace ZeroGS
{ {
@ -242,10 +235,6 @@ inline list<ZeroGS::CRenderTarget*> CreateTargetsList(int start, int end)
extern Vector g_vdepth; extern Vector g_vdepth;
extern int icurctx; extern int icurctx;
extern VERTEXSHADER pvsBitBlt;
extern FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne;
extern FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16;
extern GLuint vboRect; extern GLuint vboRect;
// Unworking // Unworking

View File

@ -32,6 +32,7 @@
#include "zpipe.h" #include "zpipe.h"
#include "targets.h" #include "targets.h"
#include "GLWin.h" #include "GLWin.h"
#include "ZZoglShaders.h"
//----------------------- Defines //----------------------- Defines
@ -104,10 +105,6 @@ GLenum GetRenderTargetFormat() { return GetRenderFormat() == RFT_byte8 ? 4 : g_i
// returns the first and last addresses aligned to a page that cover // returns the first and last addresses aligned to a page that cover
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw); void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw);
// bool LoadEffects();
// bool LoadExtraEffects();
// FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed);
int s_nNewWidth = -1, s_nNewHeight = -1; int s_nNewWidth = -1, s_nNewHeight = -1;
void ChangeDeviceSize(int nNewWidth, int nNewHeight); void ChangeDeviceSize(int nNewWidth, int nNewHeight);
@ -343,8 +340,7 @@ extern RasterFont* font_p;
void ZeroGS::DrawText(const char* pstr, int left, int top, u32 color) void ZeroGS::DrawText(const char* pstr, int left, int top, u32 color)
{ {
FUNCLOG FUNCLOG
cgGLDisableProfile(cgvProf); ZZcgGLDisableProfile();
cgGLDisableProfile(cgfProf);
Vector v; Vector v;
v.SetColor(color); v.SetColor(color);
@ -352,8 +348,7 @@ void ZeroGS::DrawText(const char* pstr, int left, int top, u32 color)
//glColor3f(((color >> 16) & 0xff) / 255.0f, ((color >> 8) & 0xff)/ 255.0f, (color & 0xff) / 255.0f); //glColor3f(((color >> 16) & 0xff) / 255.0f, ((color >> 8) & 0xff)/ 255.0f, (color & 0xff) / 255.0f);
font_p->printString(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, 0); font_p->printString(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, 0);
cgGLEnableProfile(cgvProf); ZZcgGLEnableProfile();
cgGLEnableProfile(cgfProf);
} }
void ZeroGS::ChangeWindowSize(int nNewWidth, int nNewHeight) void ZeroGS::ChangeWindowSize(int nNewWidth, int nNewHeight)
@ -548,14 +543,13 @@ void ZeroGS::RenderCustom(float fAlpha)
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// inside vhDCb[0]'s target area, so render that region only // inside vhDCb[0]'s target area, so render that region only
cgGLSetTextureParameter(ppsBaseTexture.sFinal, ptexLogo); ZZcgGLSetTextureParameter(ppsBaseTexture.sFinal, ptexLogo, "Logo");
cgGLEnableTextureParameter(ppsBaseTexture.sFinal);
glBindBuffer(GL_ARRAY_BUFFER, vboRect); glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM(); SET_STREAM();
SETVERTEXSHADER(pvsBitBlt.prog); ZZcgSetVertexShader(pvsBitBlt.prog);
SETPIXELSHADER(ppsBaseTexture.prog); ZZcgSetPixelShader(ppsBaseTexture.prog);
DrawTriangleArray(); DrawTriangleArray();
// restore // restore

View File

@ -34,7 +34,7 @@
#include "GS.h" #include "GS.h"
#include "CRC.h" #include "CRC.h"
#include "rasterfont.h" // simple font #include "rasterfont.h" // simple font
#include "ZeroGSShaders/zerogsshaders.h" //#include "ZeroGSShaders/zerogsshaders.h"
using namespace std; using namespace std;
@ -413,17 +413,6 @@ extern float fiTexWidth[2], fiTexHeight[2]; // current tex width and height
extern vector<GLuint> g_vboBuffers; // VBOs for all drawing commands extern vector<GLuint> g_vboBuffers; // VBOs for all drawing commands
extern GLuint vboRect; extern GLuint vboRect;
extern int g_nCurVBOIndex; extern int g_nCurVBOIndex;
// Shaders variables
extern Vector g_vdepth;
extern Vector vlogz;
extern VERTEXSHADER pvsBitBlt;
extern FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne;
extern FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16;
bool LoadEffects();
bool LoadExtraEffects();
FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed);
extern RenderFormatType g_RenderFormatType; extern RenderFormatType g_RenderFormatType;
void AddMessage(const char* pstr, u32 ms = 5000); void AddMessage(const char* pstr, u32 ms = 5000);
@ -517,10 +506,6 @@ void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h
void SetContextTarget(int context) ; void SetContextTarget(int context) ;
void NeedFactor(int w); void NeedFactor(int w);
// only sets a limited amount of state (for Update)
void SetTexClamping(int context, FRAGMENTSHADER* pfragment);
void SetTexVariablesInt(int context, int bilinear, const tex0Info& tex0, ZeroGS::CMemoryTarget* pmemtarg, FRAGMENTSHADER* pfragment, int force);
void ResetAlphaVariables(); void ResetAlphaVariables();
void StartCapture(); void StartCapture();