GregMiscellaneous: zzogl-pg: Continuing to work on zerogs.cpp and zerogs.h.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@3960 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-10-23 04:14:19 +00:00
parent 4171a67c4d
commit c544ec7ca6
11 changed files with 181 additions and 241 deletions

View File

@ -31,8 +31,6 @@ using namespace std;
extern float fFPS;
#define MEMORY_END 0x00400000
extern int g_LastCRC;
struct Vector_16F

View File

@ -20,6 +20,10 @@
#ifndef HOSTMEMORY_H_INCLUDED
#define HOSTMEMORY_H_INCLUDED
#include "GLWin.h"
#define MEMORY_END 0x00400000
extern int GPU_TEXWIDTH;
extern u8* g_pBasePS2Mem;
@ -47,6 +51,32 @@ class GSClut
u8* get_raw(u32 addr);
};
class ZeroGSInit
{
public:
ZeroGSInit()
{
const u32 mem_size = MEMORY_END + 0x10000; // leave some room for out of range accesses (saves on the checks)
// clear
g_pbyGSMemory = (u8*)_aligned_malloc(mem_size, 1024);
memset(g_pbyGSMemory, 0, mem_size);
g_pbyGSClut = (u8*)_aligned_malloc(256 * 8, 1024); // need 512 alignment!
memset(g_pbyGSClut, 0, 256*8);
memset(&GLWin, 0, sizeof(GLWin));
}
~ZeroGSInit()
{
_aligned_free(g_pbyGSMemory);
g_pbyGSMemory = NULL;
_aligned_free(g_pbyGSClut);
g_pbyGSClut = NULL;
}
};
// The size in bytes of x strings (of texture).
inline int MemorySize(int x)
{

View File

@ -78,8 +78,6 @@ extern u32 s_stencilfunc, s_stencilref, s_stencilmask;
// global alpha blending settings
extern GLenum g_internalRGBAFloat16Fmt;
extern const GLenum primtype[8];
#define SAFE_RELEASE_TEX(x) { if( (x) != 0 ) { glDeleteTextures(1, &(x)); x = 0; } }
// inline for an extremely often used sequence

View File

@ -23,6 +23,8 @@
const u32 g_primmult[8] = { 1, 2, 2, 3, 3, 3, 2, 0xff };
const u32 g_primsub[8] = { 1, 2, 1, 3, 1, 1, 2, 0 };
const GLenum primtype[8] = { GL_POINTS, GL_LINES, GL_LINES, GL_TRIANGLES, GL_TRIANGLES, GL_TRIANGLES, GL_TRIANGLES, 0xffffffff };
extern float fiTexWidth[2], fiTexHeight[2]; // current tex width and height
DrawFn drawfn[8] = { KickDummy, KickDummy, KickDummy, KickDummy,
@ -54,6 +56,20 @@ void clear_drawfn()
drawfn[7] = KickDummy;
}
// Still thinking about the best place to put this.
// called on a primitive switch
void Prim()
{
FUNCLOG
VB& curvb = vb[prim->ctxt];
if (curvb.CheckPrim()) Flush(prim->ctxt);
curvb.curprim._val = prim->_val;
curvb.curprim.prim = prim->prim;
}
__forceinline void MOVZ(VertexGPU *p, u32 gsz, const VB& curvb)
{
p->z = (curvb.zprimmask == 0xffff) ? min((u32)0xffff, gsz) : gsz;

View File

@ -222,7 +222,6 @@ void SetContextTarget(int context);
void SetWriteDepth();
bool IsWriteDepth();
void SetDestAlphaTest();
void ResetRenderTarget(int index);
//------------------ Code
@ -1087,6 +1086,8 @@ inline void AlphaSetStencil(bool DoIt)
else glDisable(GL_STENCIL_TEST);
}
//inline u32 FtoDW(float f) { return (*((u32*)&f)); }
inline void AlphaSetDepthTest(VB& curvb, const pixTest curtest, FRAGMENTSHADER* pfragment)
{
glDepthMask(!curvb.zbuf.zmsk && curtest.zte);

View File

@ -69,7 +69,10 @@ extern HINSTANCE hInst;
// Used in a logarithmic Z-test, as (1-o(1))/log(MAX_U32).
const float g_filog32 = 0.999f / (32.0f * logf(2.0f));
#ifdef _DEBUG
const static char* g_pTexTypes[] = { "32", "tex32", "clut32", "tex32to16", "tex16to8h" };
#endif
const char* g_pShaders[4] = { "full", "reduced", "accurate", "accurate-reduced" };
// ----------------- Global Variables

View File

@ -34,8 +34,6 @@
#include "GS.h"
// For output
const static char* g_pShaders[] = { "full", "reduced", "accurate", "accurate-reduced" };
#define NVIDIA_CG_API
// --------------------------- API abstraction level --------------------------------
@ -58,7 +56,7 @@ inline bool ZZshActiveParameter(ZZshParameter param) {return (param !=NULL); }
#endif // end NVIDIA cg-toolkit API
const static char* g_pPsTexWrap[] = { "-DREPEAT", "-DCLAMP", "-DREGION_REPEAT", NULL };
//const static char* g_pPsTexWrap[] = { "-DREPEAT", "-DCLAMP", "-DREGION_REPEAT", NULL };
enum ZZshShaderType {ZZ_SH_ZERO, ZZ_SH_REGULAR, ZZ_SH_REGULAR_FOG, ZZ_SH_TEXTURE, ZZ_SH_TEXTURE_FOG, ZZ_SH_CRTC};
// We have "compatible" shaders, as RegularFogVS and RegularFogPS. if don't need to wory about incompatible shaders

View File

@ -63,7 +63,6 @@ void _Resolve(const void* psrc, int fbp, int fbw, int fbh, int psm, u32 fbm, boo
void SetWriteDepth();
bool IsWriteDepth();
bool IsWriteDestAlphaTest();
void ResetRenderTarget(int index);
// ------------------------- Useful inlines ------------------------------------

View File

@ -226,6 +226,7 @@ class CMemoryTarget
int clutsize; // size of the clut array. 0 otherwise
};
extern const GLenum primtype[8];
struct VB
{
@ -522,6 +523,7 @@ class CRangeManager
extern CRenderTargetMngr s_RTs, s_DepthRTs;
extern CBitwiseTextureMngr s_BitwiseTextures;
extern CMemoryTargetMngr g_MemTargs;
extern CRangeManager s_RangeMngr; // manages overwritten memory
//extern u8 s_AAx, s_AAy;
extern Point AA;
@ -634,6 +636,11 @@ static __forceinline void FBTexture(int attach, int id = 0)
GL_REPORT_ERRORD();
}
static __forceinline void ResetRenderTarget(int index)
{
FBTexture(index);
}
static __forceinline void Texture2D(GLint iFormat, GLint width, GLint height, GLenum format, GLenum type, const GLvoid* pixels)
{
glTexImage2D(GL_TEXTURE_2D, 0, iFormat, width, height, 0, format, type, pixels);
@ -710,7 +717,6 @@ static __forceinline void setRectWrap2(GLint type)
// VB variables
extern VB vb[2];
//------------------------ Inlines -------------------------
// Calculate maximum height for target

View File

@ -18,65 +18,7 @@
*/
//-------------------------- Includes
#if defined(_WIN32)
# include <windows.h>
# include "resource.h"
#endif
#include <stdlib.h>
#include "GS.h"
#include "Mem.h"
#include "x86.h"
#include "zerogs.h"
#include "targets.h"
#include "GLWin.h"
#include "ZZoglShaders.h"
#include "ZZKick.h"
#include "ZZClut.h"
//----------------------- Defines
//-------------------------- Typedefs
typedef void (APIENTRYP _PFNSWAPINTERVAL)(int);
//-------------------------- Extern variables
extern u32 g_nGenVars, g_nTexVars, g_nAlphaVars, g_nResolve;
extern char *libraryName;
extern int g_nFrame, g_nRealFrame;
//extern int s_nFullscreen;
//-------------------------- Variables
primInfo *prim;
inline u32 FtoDW(float f) { return (*((u32*)&f)); }
int g_nDepthUpdateCount = 0;
// Consts
const GLenum primtype[8] = { GL_POINTS, GL_LINES, GL_LINES, GL_TRIANGLES, GL_TRIANGLES, GL_TRIANGLES, GL_TRIANGLES, 0xffffffff };
static const int PRIMMASK = 0x0e; // for now ignore 0x10 (AA)
PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT = NULL;
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT = NULL;
PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT = NULL;
PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT = NULL;
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT = NULL;
PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT = NULL;
PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT = NULL;
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT = NULL;
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL;
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT = NULL;
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT = NULL;
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT = NULL;
PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT = NULL;
PFNGLDRAWBUFFERSPROC glDrawBuffers = NULL;
/////////////////////
// graphics resources
@ -84,70 +26,17 @@ PFNGLDRAWBUFFERSPROC glDrawBuffers = NULL;
bool s_bTexFlush = false;
int s_nLastResolveReset = 0;
int s_nResolveCounts[30] = {0}; // resolve counts for last 30 frames
////////////////////
// State parameters
int nBackbufferWidth, nBackbufferHeight; // ZZ
// = float4( 255.0 /256.0f, 255.0/65536.0f, 255.0f/(65535.0f*256.0f), 1.0f/(65536.0f*65536.0f));
// float4 g_vdepth = float4( 65536.0f*65536.0f, 256.0f*65536.0f, 65536.0f, 256.0f);
extern CRangeManager s_RangeMngr; // manages overwritten memory
int s_nNewWidth = -1, s_nNewHeight = -1;
void ProcessMessages();
void RenderCustom(float fAlpha); // intro anim
bool ZZCreate(int width, int height);
///////////////////////
// Method Prototypes //
///////////////////////
void ResolveInRange(int start, int end);
void ExtWrite();
extern GLuint vboRect;
void ResetRenderTarget(int index)
{
FBTexture(index);
}
// does one time only initializing/destruction
class ZeroGSInit
{
public:
ZeroGSInit()
{
const u32 mem_size = MEMORY_END + 0x10000; // leave some room for out of range accesses (saves on the checks)
// clear
g_pbyGSMemory = (u8*)_aligned_malloc(mem_size, 1024);
memset(g_pbyGSMemory, 0, mem_size);
g_pbyGSClut = (u8*)_aligned_malloc(256 * 8, 1024); // need 512 alignment!
memset(g_pbyGSClut, 0, 256*8);
memset(&GLWin, 0, sizeof(GLWin));
}
~ZeroGSInit()
{
_aligned_free(g_pbyGSMemory);
g_pbyGSMemory = NULL;
_aligned_free(g_pbyGSClut);
g_pbyGSClut = NULL;
}
};
primInfo *prim;
////////////////////
// State parameters
int nBackbufferWidth, nBackbufferHeight;
int g_nDepthUpdateCount = 0;
static ZeroGSInit s_ZeroGSInit;
#ifndef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
#endif
// does one time only initializing/destruction
void HandleGLError()
{
@ -328,113 +217,97 @@ void SetAA(int mode)
glPointSize(f);
}
void Prim()
{
FUNCLOG
VB& curvb = vb[prim->ctxt];
if (curvb.CheckPrim()) Flush(prim->ctxt);
curvb.curprim._val = prim->_val;
curvb.curprim.prim = prim->prim;
}
extern u32 ptexLogo;
extern int nLogoWidth, nLogoHeight;
void RenderCustom(float fAlpha)
{
FUNCLOG
GL_REPORT_ERROR();
fAlpha = 1;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer
DisableAllgl() ;
SetShaderCaller("RenderCustom");
glViewport(0, 0, nBackbufferWidth, nBackbufferHeight);
// play custom animation
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// tex coords
float4 v = float4(1 / 32767.0f, 1 / 32767.0f, 0, 0);
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltPos, v, "g_fBitBltPos");
v.x = (float)nLogoWidth;
v.y = (float)nLogoHeight;
ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
v.x = v.y = v.z = v.w = fAlpha;
ZZshSetParameter4fv(ppsBaseTexture.prog, ppsBaseTexture.sOneColor, v, "g_fOneColor");
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// inside vhDCb[0]'s target area, so render that region only
ZZshGLSetTextureParameter(ppsBaseTexture.prog, ppsBaseTexture.sFinal, ptexLogo, "Logo");
glBindBuffer(GL_ARRAY_BUFFER, vboRect);
SET_STREAM();
ZZshSetVertexShader(pvsBitBlt.prog);
ZZshSetPixelShader(ppsBaseTexture.prog);
DrawTriangleArray();
// restore
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
ProcessMessages();
GLWin.SwapGLBuffers();
glEnable(GL_SCISSOR_TEST);
glEnable(GL_STENCIL_TEST);
vb[0].bSyncVars = 0;
vb[1].bSyncVars = 0;
GL_REPORT_ERROR();
}
//void RenderCustom(float fAlpha)
//{
// FUNCLOG
// GL_REPORT_ERROR();
//
// fAlpha = 1;
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer
//
// DisableAllgl() ;
// SetShaderCaller("RenderCustom");
//
// glViewport(0, 0, nBackbufferWidth, nBackbufferHeight);
//
// // play custom animation
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//
// // tex coords
// float4 v = float4(1 / 32767.0f, 1 / 32767.0f, 0, 0);
// ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltPos, v, "g_fBitBltPos");
// v.x = (float)nLogoWidth;
// v.y = (float)nLogoHeight;
// ZZshSetParameter4fv(pvsBitBlt.prog, pvsBitBlt.sBitBltTex, v, "g_fBitBltTex");
//
// v.x = v.y = v.z = v.w = fAlpha;
// ZZshSetParameter4fv(ppsBaseTexture.prog, ppsBaseTexture.sOneColor, v, "g_fOneColor");
//
// if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//
// // inside vhDCb[0]'s target area, so render that region only
// ZZshGLSetTextureParameter(ppsBaseTexture.prog, ppsBaseTexture.sFinal, ptexLogo, "Logo");
// glBindBuffer(GL_ARRAY_BUFFER, vboRect);
//
// SET_STREAM();
//
// ZZshSetVertexShader(pvsBitBlt.prog);
// ZZshSetPixelShader(ppsBaseTexture.prog);
// DrawTriangleArray();
//
// // restore
// if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//
// ProcessMessages();
//
// GLWin.SwapGLBuffers();
//
// glEnable(GL_SCISSOR_TEST);
// glEnable(GL_STENCIL_TEST);
//
// vb[0].bSyncVars = 0;
// vb[1].bSyncVars = 0;
//
// GL_REPORT_ERROR();
//}
//////////////////////////
// Internal Definitions //
//////////////////////////
int Values[100] = {0, };
void SetFogColor(u32 fog)
{
FUNCLOG
// Always set the fog color, even if it was already set.
// if (gs.fogcol != fog)
// {
gs.fogcol = fog;
FlushBoth();
SetShaderCaller("SetFogColor");
float4 v;
// set it immediately
v.SetColor(gs.fogcol);
ZZshSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
// }
}
void SetFogColor(GIFRegFOGCOL* fog)
__forceinline void SetFogColor(float4 v)
{
FUNCLOG
SetShaderCaller("SetFogColor");
ZZshSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
}
__forceinline void SetFogColor(u32 fog)
{
FUNCLOG
gs.fogcol = fog;
FlushBoth();
float4 v;
// set it immediately
v.SetColor(gs.fogcol);
SetFogColor(v);
}
__forceinline void SetFogColor(GIFRegFOGCOL* fog)
{
FUNCLOG
float4 v;
v.x = fog->FCR / 255.0f;
v.y = fog->FCG / 255.0f;
v.z = fog->FCB / 255.0f;
ZZshSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
SetFogColor(v);
}
void ExtWrite()

View File

@ -25,44 +25,62 @@
#endif
// ----------------------------- Includes
//#include <list>
//#include <vector>
//#include <map>
//#include <string>
//#include <math.h>
//#include "ZZGl.h"
//#include "CRC.h"
//#include "targets.h"
#include "PS2Edefs.h"
// ------------------------ Variables -------------------------
//////////////////////////
// State parameters
#ifdef ZEROGS_DEVBUILD
extern char* EFFECT_NAME;
extern char* EFFECT_DIR;
extern u32 g_nGenVars, g_nTexVars, g_nAlphaVars, g_nResolve;
extern bool g_bSaveTrans, g_bUpdateEffect, g_bSaveTex, g_bSaveResolved;
#if defined(_WIN32)
# include <windows.h>
# include "resource.h"
#endif
extern bool s_bWriteDepth;
#include <stdlib.h>
extern int nBackbufferWidth, nBackbufferHeight;
#include "GS.h"
#include "targets.h"
#include "GLWin.h"
#include "ZZoglShaders.h"
#include "ZZClut.h"
#include "HostMemory.h"
extern float fiTexWidth[2], fiTexHeight[2]; // current tex width and height
typedef void (APIENTRYP _PFNSWAPINTERVAL)(int);
// Methods //
PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT = NULL;
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT = NULL;
PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT = NULL;
PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT = NULL;
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT = NULL;
PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT = NULL;
PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT = NULL;
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT = NULL;
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL;
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT = NULL;
PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT = NULL;
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT = NULL;
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT = NULL;
PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT = NULL;
PFNGLDRAWBUFFERSPROC glDrawBuffers = NULL;
#ifndef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
#endif
bool ZZCreate(int width, int height);
void ZZGSStateReset();
// flush current vertices, call before setting new registers (the main render method)
void Flush(int context);
void FlushBoth();
// called on a primitive switch
void Prim();
//extern u32 ptexLogo;
//extern int nLogoWidth, nLogoHeight;
//extern GLuint vboRect;
//void ProcessMessages();
//void RenderCustom(float fAlpha); // intro anim
#endif