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
zpipe.h
ZZoglCRTC.h
ZZoglShaders.h
ZZGl.h
ZZLog.h)

View File

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

View File

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

View File

@ -46,12 +46,6 @@ inline void* wglGetProcAddress(const char* x)
#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;
// Defines
@ -82,47 +76,10 @@ extern u32 s_stencilfunc, s_stencilref, s_stencilmask;
// global alpha blending settings
extern GLenum g_internalFloatFmt;
extern GLenum g_internalRGBAFloatFmt;
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];
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; } }
// inline for an extremely often used sequence
@ -138,7 +95,6 @@ inline void DisableAllgl()
glColorMask(1, 1, 1, 1);
}
//--------------------- Dummies
#ifdef _WIN32
@ -152,105 +108,8 @@ extern void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
// ------------------------ 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
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
// GL prototypes

View File

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

View File

@ -25,7 +25,7 @@
#include "zerogs.h"
#include "GLWin.h"
#include "ZeroGSShaders/zerogsshaders.h"
#include "ZZoglShaders.h"
#include "targets.h"
// This include for windows resource file with Shaders
#ifdef _WIN32
@ -86,7 +86,6 @@ extern void KickDummy();
extern bool LoadEffects();
extern bool LoadExtraEffects();
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;
vector<GLuint> g_vboBuffers; // VBOs for all drawing commands
@ -159,8 +158,6 @@ int GPU_TEXWIDTH = 512;
float g_fiGPU_TEXWIDTH = 1/512.0f;
int g_MaxTexWidth = 4096, g_MaxTexHeight = 4096;
u32 s_uFramebuffer = 0;
CGprofile cgvProf, cgfProf;
int g_nPixelShaderVer = 0; // default
RasterFont* font_p = NULL;
float g_fBlockMult = 1;
@ -219,20 +216,9 @@ inline bool ZeroGS::CreateImportantCheck()
ZZLog::Error_Log("*********\nZZogl: OGL WARNING: Need GL_EXT_secondary_color\nZZogl: *********");
bSuccess = false;
}
// load the effect & find the best profiles (if any)
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;
}
bSuccess &= ZZcgCheckProfilesSupport();
return bSuccess;
}
@ -440,9 +426,6 @@ inline bool CreateFillExtensionsMap()
return true;
}
const static char* g_pShaders[] = { "full", "reduced", "accurate", "accurate-reduced" };
void LoadglFunctions()
{
GL_LOADFN(glIsRenderbufferEXT);
@ -464,6 +447,20 @@ void LoadglFunctions()
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)
{
GLenum err = GL_NO_ERROR;
@ -473,7 +470,6 @@ bool ZeroGS::Create(int _width, int _height)
Destroy(1);
GSStateReset();
cgSetErrorHandler(HandleCgError, NULL);
g_RenderFormatType = RFT_float16;
if (!Create_Window(_width, _height)) return false;
@ -614,43 +610,32 @@ bool ZeroGS::Create(int _width, int _height)
glGenTextures(1, &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.
g_internalRGBAFloatFmt = GL_RGBA32F;
g_internalRGBAFloat16Fmt = GL_RGBA16F;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_FLOAT, &vBlockData[0]);
if (glGetError() != GL_NO_ERROR)
{
// 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 (TryBlockFormat(GL_RGBA32F, &vBlockData[0]))
ZZLog::Error_Log("Use GL_RGBA32F for blockdata.");
else if (TryBlockFormat(GL_ALPHA_FLOAT32_ATI, &vBlockData[0]))
ZZLog::Error_Log("Use ATI_texture_float for blockdata.");
else if (TryBlockFormat(GL_ALPHA32F_ARB, &vBlockData[0]))
ZZLog::Error_Log("Use ARB_texture_float for blockdata.");
else
{ // This case is bad. But for really old cards it could be nice.
g_fBlockMult = 65535.0f*(float)g_fiGPU_TEXWIDTH;
BLOCK::FillBlocks(vBlockData, vBilinearData, 0);
g_internalFloatFmt = GL_ALPHA16;
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 ;
BLOCK::FillBlocks(vBlockData, vBilinearData, 0);
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.
glTexImage2D(GL_TEXTURE_2D, 0, g_internalFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_ALPHA, GL_UNSIGNED_SHORT, &vBlockData[0]);
if (glGetError() != GL_NO_ERROR)
{
ZZLog::Error_Log("Could not fill blocks.");
return false;
}
do_not_use_billinear = true;
ZZLog::Debug_Log("Using non-bilinear fill, quallity is outdated!");
}
else
ZZLog::Debug_Log("Use ATI_texture_float for blockdata.");
// 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]);
if( glGetError() != GL_NO_ERROR ) {
ZZLog::Error_Log("ZZogl ERROR: could not fill blocks");
return false;
}
do_not_use_billinear = true;
conf.bilinear = 0;
ZZLog::Error_Log("Using non-bilinear fill, quallity is outdated!");
}
else
ZZLog::Debug_Log("Use GL_RGBA32F for blockdata.");
setTex2DFilters(GL_NEAREST);
setTex2DWrap(GL_REPEAT);
@ -660,33 +645,15 @@ bool ZeroGS::Create(int _width, int _height)
// fill in the bilinear blocks (main variant).
glGenTextures(1, &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)
{
g_internalRGBAFloatFmt = GL_RGBA_FLOAT32_ATI;
g_internalRGBAFloat16Fmt = GL_RGBA_FLOAT16_ATI;
glTexImage2D(GL_TEXTURE_2D, 0, g_internalRGBAFloatFmt, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, GL_RGBA, GL_FLOAT, &vBilinearData[0]);
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
ZZLog::Debug_Log("Fill bilinear blocks with NVidia_float.");
}
else
ZZLog::Debug_Log("Fill bilinear blocks with ATI_texture_float.");
}
else
ZZLog::Debug_Log("Fill bilinear blocks OK.!");
if (TryBlinearFormat(GL_RGBA32F, GL_RGBA16F, &vBilinearData[0]))
ZZLog::Error_Log("Fill bilinear blocks OK.!");
else if (TryBlinearFormat(GL_RGBA_FLOAT32_ATI, GL_RGBA_FLOAT16_ATI, &vBilinearData[0]))
ZZLog::Error_Log("Fill bilinear blocks with ATI_texture_float.");
else if (TryBlinearFormat(GL_FLOAT_RGBA32_NV, GL_FLOAT_RGBA16_NV, &vBilinearData[0]))
ZZLog::Error_Log("ZZogl Fill bilinear blocks with NVidia_float.");
else
ZZLog::Error_Log("Fill bilinear blocks failed.");
setTex2DFilters(GL_NEAREST);
setTex2DWrap(GL_REPEAT);
@ -800,67 +767,7 @@ bool ZeroGS::Create(int _width, int _height)
if (err != GL_NO_ERROR) bSuccess = false;
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::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]);
if (!ZZcgStartUsingShaders()) bSuccess = false;
GL_REPORT_ERROR();

View File

@ -26,6 +26,7 @@
#include "zerogs.h"
#include "targets.h"
#include "ZZoglFlushHack.h"
#include "ZZoglShaders.h"
using namespace ZeroGS;
@ -969,10 +970,7 @@ inline FRAGMENTSHADER* FlushUseExistRenderTarget(VB& curvb, CRenderTarget* ptext
Vector vTexDims = FlushTextureDims(pfragment, shadertype, curvb, ptextarg);
if (pfragment->sCLUT != NULL && ptexclut != 0)
{
cgGLSetTextureParameter(pfragment->sCLUT, ptexclut);
cgGLEnableTextureParameter(pfragment->sCLUT);
}
ZZcgGLSetTextureParameter(pfragment->sCLUT, ptexclut, "CLUT");
FlushApplyResizeFilter(curvb, dwFilterOpts, ptextarg, context);
@ -1016,35 +1014,25 @@ inline void FlushSetTexture(VB& curvb, FRAGMENTSHADER* pfragment, CRenderTarget*
SetTexVariables(context, pfragment);
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 )
ZZcgGLSetTextureParameter(pfragment->sBitwiseANDX, curvb.ptexClamp[0], "Clamp 0");
if( curvb.ptexClamp[1] != 0 )
ZZcgGLSetTextureParameter(pfragment->sBitwiseANDY, curvb.ptexClamp[1], "Clamp 1");
if( pfragment->sMemory != NULL && s_ptexCurSet[context] != 0)
ZZcgGLSetTextureParameter(pfragment->sMemory, s_ptexCurSet[context], "Clamp memory");
if (curvb.ptexClamp[0] != 0)
{
cgGLSetTextureParameter(pfragment->sBitwiseANDX, curvb.ptexClamp[0]);
cgGLEnableTextureParameter(pfragment->sBitwiseANDX);
}
if (curvb.ptexClamp[1] != 0)
{
cgGLSetTextureParameter(pfragment->sBitwiseANDY, curvb.ptexClamp[1]);
cgGLEnableTextureParameter(pfragment->sBitwiseANDY);
}
if (pfragment->sMemory != NULL && s_ptexCurSet[context] != 0)
{
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)
{
vb[context].bTexConstsSync = 0;
vb[context].bVarsTexSync = 0;
cgGLBindProgram(pfragment->prog);
g_psprog = pfragment->prog;
ZZcgSetPixelShader(pfragment->prog);
}
inline FRAGMENTSHADER* FlushRendererStage(VB& curvb, u32& dwFilterOpts, CRenderTarget* ptextarg, int exactcolor, int context)
@ -1077,8 +1065,8 @@ inline FRAGMENTSHADER* FlushRendererStage(VB& curvb, u32& dwFilterOpts, CRenderT
GL_REPORT_ERRORD();
// set the shaders
SetShaderCaller("FlushRendererStage") ;
SETVERTEXSHADER(pvs[2 * ((curvb.curprim._val >> 1) & 3) + 8 * s_bWriteDepth + context]);
SetShaderCaller("FlushRendererStage");
ZZcgSetVertexShader(pvs[2 * ((curvb.curprim._val >> 1) & 3) + 8 * s_bWriteDepth + context]);
FlushBindProgramm(pfragment, context);
GL_REPORT_ERRORD();
@ -1501,7 +1489,7 @@ inline void AlphaColorClamping(VB& curvb, const pixTest curtest)
SetShaderCaller("AlphaColorClamping");
SETPIXELSHADER(ppsOne.prog);
ZZcgSetPixelShader(ppsOne.prog);
GL_BLEND_RGB(GL_ONE, GL_ONE);
float f;
@ -1764,7 +1752,7 @@ inline void ZeroGS::ProcessStencil(const VB& curvb)
SetShaderCaller("ProcessStencil");
SETPIXELSHADER(ppsOne.prog);
ZZcgSetPixelShader(ppsOne.prog);
Draw(curvb);
// process when alpha >= 0xff
@ -1825,7 +1813,7 @@ __forceinline void ZeroGS::ProcessFBA(const VB& curvb, CGparameter sOneColor)
float f = 1;
ZZcgSetParameter4fv(sOneColor, &f, "g_fOneColor");
SETPIXELSHADER(ppsOne.prog);
ZZcgSetPixelShader(ppsOne.prog);
Draw(curvb);
glDisable(GL_ALPHA_TEST);
@ -1981,13 +1969,13 @@ void ZeroGS::SetTexInt(int context, FRAGMENTSHADER* pfragment, int settexint)
{
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;
}
}
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;
INC_TEXVARS();
@ -2278,17 +2266,20 @@ 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
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)
{
ZZLog::Error_Log("SetTexVariablesInt error.");
return;
}
if (CheckVB && vb[context].pmemtarg == pmemtarg) return;
SetShaderCaller("SetTexVariablesInt");
@ -2307,7 +2298,7 @@ void ZeroGS::SetTexVariablesInt(int context, int bilinear, const tex0Info& tex0,
if (pfragment->fRealTexDims)
ZZcgSetParameter4fv(pfragment->fRealTexDims, v, "g_fRealTexDims");
else
ZZcgSetParameter4fv(cgGetNamedParameter(pfragment->prog, "g_fRealTexDims"), v, "g_fRealTexDims");
ZZcgSetParameter4fv(cgGetNamedParameter(pfragment->prog,"g_fRealTexDims"),v, "g_fRealTexDims");
}
if (m_Blocks[tex0.psm].bpp == 0)

View File

@ -21,7 +21,7 @@
//------------------- Includes
#include "zerogs.h"
#include "ZeroGSShaders/zerogsshaders.h"
#include "ZZoglShaders.h"
#include "zpipe.h"
// ----------------- Defines
@ -35,6 +35,7 @@ namespace ZeroGS
{
FRAGMENTSHADER ppsBitBlt[2], ppsBitBltDepth, ppsOne;
FRAGMENTSHADER ppsBaseTexture, ppsConvert16to32, ppsConvert32to16;
VERTEXSHADER pvsBitBlt;
}
// Debug variable, store name of the function that call the shader.
@ -48,9 +49,24 @@ bool g_bCRTCBilinear = true;
u8* s_lpShaderResources = NULL;
map<int, SHADERHEADER*> mapShaderResources;
CGcontext g_cgcontext;
CGprofile cgvProf, cgfProf;
int g_nPixelShaderVer = 0; // default
//------------------ 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.
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);
}
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.
// The name could be any string. We must use it on compilation time, because the erronious handler does not
// return it.
@ -68,6 +148,34 @@ void ZZcgSetParameter4fv(CGparameter param, const float* v, const char* name)
ShaderHandleName = name;
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)
{

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

View File

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

View File

@ -32,6 +32,7 @@
#include "zpipe.h"
#include "targets.h"
#include "GLWin.h"
#include "ZZoglShaders.h"
//----------------------- 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
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;
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)
{
FUNCLOG
cgGLDisableProfile(cgvProf);
cgGLDisableProfile(cgfProf);
ZZcgGLDisableProfile();
Vector v;
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);
font_p->printString(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, 0);
cgGLEnableProfile(cgvProf);
cgGLEnableProfile(cgfProf);
ZZcgGLEnableProfile();
}
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);
// inside vhDCb[0]'s target area, so render that region only
cgGLSetTextureParameter(ppsBaseTexture.sFinal, ptexLogo);
cgGLEnableTextureParameter(ppsBaseTexture.sFinal);
ZZcgGLSetTextureParameter(ppsBaseTexture.sFinal, ptexLogo, "Logo");
glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM();
SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsBaseTexture.prog);
ZZcgSetVertexShader(pvsBitBlt.prog);
ZZcgSetPixelShader(ppsBaseTexture.prog);
DrawTriangleArray();
// restore

View File

@ -34,7 +34,7 @@
#include "GS.h"
#include "CRC.h"
#include "rasterfont.h" // simple font
#include "ZeroGSShaders/zerogsshaders.h"
//#include "ZeroGSShaders/zerogsshaders.h"
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 GLuint vboRect;
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;
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 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 StartCapture();