zzogl-pg: Shuffle stuff out of zerogs.h to ZZGl.h and Util.h.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3377 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-07-03 06:34:27 +00:00
parent 4eb20d3f47
commit 841e326e0c
3 changed files with 199 additions and 209 deletions

View File

@ -248,6 +248,8 @@ typedef struct
} GSconf; } GSconf;
extern GSconf conf; extern GSconf conf;
// ----------------------- Defines
#define REG64(name) \ #define REG64(name) \
union name \ union name \
{ \ { \
@ -282,6 +284,22 @@ union name \
#define REG_SET_END }; #define REG_SET_END };
#ifndef SAFE_DELETE
# define SAFE_DELETE(x) if( (x) != NULL ) { delete (x); (x) = NULL; }
#endif
#ifndef SAFE_DELETE_ARRAY
# define SAFE_DELETE_ARRAY(x) if( (x) != NULL ) { delete[] (x); (x) = NULL; }
#endif
#ifndef SAFE_RELEASE
# define SAFE_RELEASE(x) if( (x) != NULL ) { (x)->Release(); (x) = NULL; }
#endif
#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it))
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
extern void LoadConfig(); extern void LoadConfig();
extern void SaveConfig(); extern void SaveConfig();

View File

@ -29,6 +29,186 @@ inline void* wglGetProcAddress(const char* x)
#include <Cg/cg.h> #include <Cg/cg.h>
#include <Cg/cgGL.h> #include <Cg/cgGL.h>
#include <cstring>
#include "zerogsmath.h"
// Defines
#ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils
# define GL_DEPTH_STENCIL_EXT 0x84F9
# define GL_UNSIGNED_INT_24_8_EXT 0x84FA
# define GL_DEPTH24_STENCIL8_EXT 0x88F0
# define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
#endif
#define GL_STENCILFUNC(func, ref, mask) { \
s_stencilfunc = func; \
s_stencilref = ref; \
s_stencilmask = mask; \
glStencilFunc(func, ref, mask); \
}
#define GL_STENCILFUNC_SET() glStencilFunc(s_stencilfunc, s_stencilref, s_stencilmask)
// sets the data stream
#define SET_STREAM() { \
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8); \
glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)12); \
glTexCoordPointer(3, GL_FLOAT, sizeof(VertexGPU), (void*)16); \
glVertexPointer(4, GL_SHORT, sizeof(VertexGPU), (void*)0); \
}
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 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
// This is turning off all gl functions. Safe to do updates.
inline void DisableAllgl()
{
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDepthMask(0);
glDisable(GL_STENCIL_TEST);
glColorMask(1, 1, 1, 1);
}
//--------------------- Dummies
#ifdef _WIN32
extern void (__stdcall *zgsBlendEquationSeparateEXT)(GLenum, GLenum);
extern void (__stdcall *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
#else
extern void (APIENTRY *zgsBlendEquationSeparateEXT)(GLenum, GLenum);
extern void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
#endif
// ------------------------ 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;
}
};
struct VERTEXSHADER
{
VERTEXSHADER() : prog(0), sBitBltPos(0), sBitBltTex(0) {}
CGprogram prog;
CGparameter sBitBltPos, sBitBltTex, fBitBltTrans; // vertex shader constants
};
// GL prototypes // GL prototypes
extern PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT; extern PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT;

View File

@ -37,100 +37,16 @@
using namespace std; using namespace std;
// ----------------------- Defines
#ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils
# define GL_DEPTH_STENCIL_EXT 0x84F9
# define GL_UNSIGNED_INT_24_8_EXT 0x84FA
# define GL_DEPTH24_STENCIL8_EXT 0x88F0
# define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
#endif
#define GL_STENCILFUNC(func, ref, mask) { \
s_stencilfunc = func; \
s_stencilref = ref; \
s_stencilmask = mask; \
glStencilFunc(func, ref, mask); \
}
#define GL_STENCILFUNC_SET() glStencilFunc(s_stencilfunc, s_stencilref, s_stencilmask)
#ifndef SAFE_DELETE
# define SAFE_DELETE(x) if( (x) != NULL ) { delete (x); (x) = NULL; }
#endif
#ifndef SAFE_DELETE_ARRAY
# define SAFE_DELETE_ARRAY(x) if( (x) != NULL ) { delete[] (x); (x) = NULL; }
#endif
#ifndef SAFE_RELEASE
# define SAFE_RELEASE(x) if( (x) != NULL ) { (x)->Release(); (x) = NULL; }
#endif
#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 FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it))
// sets the data stream
#define SET_STREAM() { \
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8); \
glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)12); \
glTexCoordPointer(3, GL_FLOAT, sizeof(VertexGPU), (void*)16); \
glVertexPointer(4, GL_SHORT, sizeof(VertexGPU), (void*)0); \
}
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 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; \
} \
} \
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
//------------------------ Constants ---------------------- //------------------------ Constants ----------------------
#define VB_BUFFERSIZE 0x400 #define VB_BUFFERSIZE 0x400
// Used in logaripmic Z-test, as (1-o(1))/log(MAX_U32). // Used in a logarithmic Z-test, as (1-o(1))/log(MAX_U32).
const float g_filog32 = 0.999f / (32.0f * logf(2.0f)); const float g_filog32 = 0.999f / (32.0f * logf(2.0f));
//------------------------ Inlines ------------------------- //------------------------ Inlines -------------------------
// inline for an extremely often used sequence
// This is turning off all gl functions. Safe to do updates.
inline void DisableAllgl()
{
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDepthMask(0);
glDisable(GL_STENCIL_TEST);
glColorMask(1, 1, 1, 1);
}
// Calculate maximum height for target // Calculate maximum height for target
inline int get_maxheight(int fbp, int fbw, int psm) inline int get_maxheight(int fbp, int fbw, int psm)
@ -160,110 +76,6 @@ inline u8 GetTexCPSM(const tex0Info& tex)
return tex.psm; return tex.psm;
} }
//--------------------- Dummies
#ifdef _WIN32
extern void (__stdcall *zgsBlendEquationSeparateEXT)(GLenum, GLenum);
extern void (__stdcall *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
#else
extern void (APIENTRY *zgsBlendEquationSeparateEXT)(GLenum, GLenum);
extern void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum);
#endif
// ------------------------ 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;
#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 ------------------------- // ------------------------ Variables -------------------------
// all textures have this width // all textures have this width
@ -810,24 +622,4 @@ inline void CluttingForFlushedTex(tex0Info* tex0, u32 Data, int ictx)
} }
}; };
//// GL prototypes
//extern PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT;
//extern PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT;
//extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT;
//extern PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT;
//extern PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT;
//extern PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT;
//extern PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT;
//extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT;
//extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
//extern PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT;
//extern PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT;
//extern PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT;
//extern PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT;
//extern PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT;
//extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT;
//extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT;
//extern PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT;
//extern PFNGLDRAWBUFFERSPROC glDrawBuffers;
#endif #endif