zzogl-pg: A bit more refactoring. Rename DrawTriangle. Move some code around.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3237 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-06-19 12:59:51 +00:00
parent dac3126808
commit a04e71cf9d
8 changed files with 205 additions and 163 deletions

View File

@ -304,6 +304,77 @@ static bool SPAM_PASS;
//#define DEVBUILD //#define DEVBUILD
#endif #endif
// sends a message to output window if assert fails
#define BMSG(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); } }
#define BMSG_RETURN(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return; } }
#define BMSG_RETURNX(x, str, rtype) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return (##rtype); } }
#define B(x) { if( !(x) ) { ZZLog::Log(_#x"\n"); ZZLog::Log(#x"\n"); } }
#define B_RETURN(x) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return; } }
#define B_RETURNX(x, rtype) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return (##rtype); } }
#define B_G(x, action) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); action; } }
#define GL_REPORT_ERROR() \
{ \
GLenum err = glGetError(); \
if( err != GL_NO_ERROR ) \
{ \
ZZLog::Error_Log("%s:%d: gl error %s(0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \
ZeroGS::HandleGLError(); \
} \
}
#ifdef _DEBUG
# define GL_REPORT_ERRORD() \
{ \
GLenum err = glGetError(); \
if( err != GL_NO_ERROR ) \
{ \
ZZLog::Error_Log("%s:%d: gl error %s (0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \
ZeroGS::HandleGLError(); \
} \
}
#else
# define GL_REPORT_ERRORD()
#endif
inline const char *error_name(int err)
{
switch (err)
{
case GL_NO_ERROR:
return "GL_NO_ERROR";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
case GL_TABLE_TOO_LARGE:
return "GL_TABLE_TOO_LARGE";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
default:
return "Unknown GL error";
}
}
extern void __LogToConsole(const char *fmt, ...); extern void __LogToConsole(const char *fmt, ...);
namespace ZZLog namespace ZZLog

View File

@ -114,8 +114,7 @@ inline u32 CreateInterlaceTex(int width)
glGenTextures(1, &s_ptexInterlace); glGenTextures(1, &s_ptexInterlace);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, s_ptexInterlace); glBindTexture(GL_TEXTURE_RECTANGLE_NV, s_ptexInterlace);
TextureRect(4, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); TextureRect(4, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setRectFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
return s_ptexInterlace; return s_ptexInterlace;
@ -442,7 +441,7 @@ inline void RenderCRTC24helper(u32 bInterlace, int interlace, int psm)
RenderGetForClip(bInterlace, interlace, psm, &ppsCRTC24[bInterlace]); RenderGetForClip(bInterlace, interlace, psm, &ppsCRTC24[bInterlace]);
SETPIXELSHADER(ppsCRTC24[bInterlace].prog); SETPIXELSHADER(ppsCRTC24[bInterlace].prog);
DrawTriangle(); DrawTriangleArray();
} }
// Maybe I do this function global-defined. Calculate bits per pixel for // Maybe I do this function global-defined. Calculate bits per pixel for
@ -636,7 +635,7 @@ inline bool RenderCheckForTargets(tex0Info& texframe, list<CRenderTarget*>& list
SETPIXELSHADER(ppsCRTCTarg[bInterlace].prog); SETPIXELSHADER(ppsCRTCTarg[bInterlace].prog);
DrawTriangle(); DrawTriangleArray();
if (abs(dh - (int)texframe.th) <= 1) return true; if (abs(dh - (int)texframe.th) <= 1) return true;
@ -708,7 +707,7 @@ inline void RenderCheckForMemory(tex0Info& texframe, list<CRenderTarget*>& listT
SETPIXELSHADER(ppsCRTC[bInterlace].prog); SETPIXELSHADER(ppsCRTC[bInterlace].prog);
DrawTriangle(); DrawTriangleArray();
} }
// Put FPS counter on screen (not in window title) // Put FPS counter on screen (not in window title)

View File

@ -587,16 +587,13 @@ bool ZeroGS::Create(int _width, int _height)
PBITMAPINFO pinfo = (PBITMAPINFO)LockResource(hBitmapGlob); PBITMAPINFO pinfo = (PBITMAPINFO)LockResource(hBitmapGlob);
if (pinfo->bmiHeader.biBitCount == 32) GLEnum tempFmt = (pinfo->bmiHeader.biBitCount == 32) ? GL_RGBA : GL_RGB;
TextureRect(4, pinfo->bmiHeader.biWidth, pinfo->bmiHeader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, (u8*)pinfo + pinfo->bmiHeader.biSize); TextureRect(4, pinfo->bmiHeader.biWidth, pinfo->bmiHeader.biHeight, tempFmt, GL_UNSIGNED_BYTE, (u8*)pinfo + pinfo->bmiHeader.biSize);
else
TextureRect(4, pinfo->bmiHeader.biWidth, pinfo->bmiHeader.biHeight, GL_RGB, GL_UNSIGNED_BYTE, (u8*)pinfo + pinfo->bmiHeader.biSize);
nLogoWidth = pinfo->bmiHeader.biWidth; nLogoWidth = pinfo->bmiHeader.biWidth;
nLogoHeight = pinfo->bmiHeader.biHeight; nLogoHeight = pinfo->bmiHeader.biHeight;
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); setRectFilters(GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
#else #else
#endif #endif
@ -639,11 +636,8 @@ bool ZeroGS::Create(int _width, int _height)
g_internalFloatFmt = GL_FLOAT_R32_NV; g_internalFloatFmt = GL_FLOAT_R32_NV;
Texture2D(g_internalFloatFmt, GL_RED, GL_FLOAT, &vBlockData[0]); Texture2D(g_internalFloatFmt, GL_RED, GL_FLOAT, &vBlockData[0]);
} }
setTex2DFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setTex2DWrap(GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (glGetError() != GL_NO_ERROR) if (glGetError() != GL_NO_ERROR)
{ {
@ -682,10 +676,8 @@ bool ZeroGS::Create(int _width, int _height)
//ZZLog::Error_Log("Fill bilinear blocks failed!"); //ZZLog::Error_Log("Fill bilinear blocks failed!");
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setTex2DFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); setTex2DWrap(GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} }
float fpri = 1; float fpri = 1;
@ -760,13 +752,10 @@ bool ZeroGS::Create(int _width, int _height)
conv16to32data[i] = (tempcol & 0xff00ff00) | ((tempcol & 0xff) << 16) | ((tempcol & 0xff0000) >> 16); conv16to32data[i] = (tempcol & 0xff00ff00) | ((tempcol & 0xff) << 16) | ((tempcol & 0xff0000) >> 16);
} }
glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, &conv16to32data[0]); Texture2D(4, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, &conv16to32data[0]);
nullTex = false;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setTex2DFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); setTex2DWrap(GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
GL_REPORT_ERROR(); GL_REPORT_ERROR();
@ -792,12 +781,9 @@ bool ZeroGS::Create(int _width, int _height)
} }
} }
glTexImage3D(GL_TEXTURE_3D, 0, 4, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, &conv32to16data[0]); Texture3D(4, 32, 32, 32, GL_RGBA, GL_UNSIGNED_BYTE, &conv32to16data[0]);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setTex3DFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); setTex3DWrap(GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
GL_REPORT_ERROR(); GL_REPORT_ERROR();
if (err != GL_NO_ERROR) bSuccess = false; if (err != GL_NO_ERROR) bSuccess = false;

View File

@ -767,16 +767,15 @@ inline void FlushDecodeClut(VB& curvb, GLuint& ptexclut)
} }
} }
glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 1, 0, GL_RGBA, PSMT_ISHALF_STORAGE(curvb.tex0) ? GL_UNSIGNED_SHORT_5_5_5_1 : GL_UNSIGNED_BYTE, &data[0]); GLenum tempType = PSMT_ISHALF_STORAGE(curvb.tex0) ? GL_UNSIGNED_SHORT_5_5_5_1 : GL_UNSIGNED_BYTE;
Texture2D(4, 256, 1, GL_RGBA, tempType, &data[0]);
s_vecTempTextures.push_back(ptexclut); s_vecTempTextures.push_back(ptexclut);
if (g_bSaveTex) SaveTexture("clut.tga", GL_TEXTURE_2D, ptexclut, 256, 1); if (g_bSaveTex) SaveTexture("clut.tga", GL_TEXTURE_2D, ptexclut, 256, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); setTex2DWrap(GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); setTex2DFilters(GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} }
} }

View File

@ -69,24 +69,27 @@ extern u32 ptexBilinearBlocks;
extern u32 ptexConv32to16; extern u32 ptexConv32to16;
bool g_bSaveZUpdate = 0; bool g_bSaveZUpdate = 0;
// ------------------------- Usefull inlines ------------------------------------ int VALIDATE_THRESH = 8;
u32 TEXDESTROY_THRESH = 16;
// memory size for one row of texture. It's depends of windth of texture and number of bytes // ------------------------- Useful inlines ------------------------------------
// memory size for one row of texture. It depends on width of texture and number of bytes
// per pixel // per pixel
inline u32 Pitch(int fbw) { return (RW(fbw) * (GetRenderFormat() == RFT_float16 ? 8 : 4)) ; } inline u32 Pitch(int fbw) { return (RW(fbw) * (GetRenderFormat() == RFT_float16 ? 8 : 4)) ; }
// memory size of whole texture. It is number of rows multiplied by memory size of row // memory size of whole texture. It is number of rows multiplied by memory size of row
inline u32 Tex_Memory_Size(int fbw, int fbh) { return (RH(fbh) * Pitch(fbw)); } inline u32 Tex_Memory_Size(int fbw, int fbh) { return (RH(fbh) * Pitch(fbw)); }
// Oftenly called for several reasons // Often called for several reasons
// Call flush if renderer or depther target is equal to ptr // Call flush if renderer or depth target is equal to ptr
inline void FlushIfNecesary(void* ptr) inline void FlushIfNecesary(void* ptr)
{ {
if (vb[0].prndr == ptr || vb[0].pdepth == ptr) Flush(0); if (vb[0].prndr == ptr || vb[0].pdepth == ptr) Flush(0);
if (vb[1].prndr == ptr || vb[1].pdepth == ptr) Flush(1); if (vb[1].prndr == ptr || vb[1].pdepth == ptr) Flush(1);
} }
// This block was repreaded several times, so I inlined it. // This block was repeated several times, so I inlined it.
inline void DestroyAllTargetsHelper(void* ptr) inline void DestroyAllTargetsHelper(void* ptr)
{ {
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
@ -97,24 +100,20 @@ inline void DestroyAllTargetsHelper(void* ptr)
} }
// Made an empty texture and bind it to $ptr_p // Made an empty texture and bind it to $ptr_p
// return false if creating texture was unsuccessfull // returns false if creating texture was unsuccessful
// fbh and fdb should be properly shifted before calling this!. // fbh and fdb should be properly shifted before calling this!
// We should ignore framebuffer trouble here, we put textures of different sizes to it. // We should ignore framebuffer trouble here, as we put textures of different sizes to it.
inline bool ZeroGS::CRenderTarget::InitialiseDefaultTexture(u32 *ptr_p, int fbw, int fbh) inline bool ZeroGS::CRenderTarget::InitialiseDefaultTexture(u32 *ptr_p, int fbw, int fbh)
{ {
glGenTextures(1, ptr_p); glGenTextures(1, ptr_p);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, *ptr_p); glBindTexture(GL_TEXTURE_RECTANGLE_NV, *ptr_p);
// initialize to default // initialize to default
if (GetRenderFormat() == RFT_float16) GLenum texType = (GetRenderFormat() == RFT_float16) ? GL_FLOAT : GL_UNSIGNED_BYTE;
TextureRect(GetRenderTargetFormat(), fbw, fbh, GL_RGBA, GL_FLOAT, NULL); TextureRect(GetRenderTargetFormat(), fbw, fbh, GL_RGBA, texType, NULL);
else
TextureRect(GetRenderTargetFormat(), fbw, fbh, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); setRectWrap(GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); setRectFilters(GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLenum Error = glGetError(); GLenum Error = glGetError();
return ((Error == GL_NO_ERROR) || (Error == GL_INVALID_FRAMEBUFFER_OPERATION_EXT)); return ((Error == GL_NO_ERROR) || (Error == GL_INVALID_FRAMEBUFFER_OPERATION_EXT));
@ -132,7 +131,7 @@ inline void FillOnlyStencilBuffer()
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xff); glStencilFunc(GL_ALWAYS, 1, 0xff);
DrawTriangle(); DrawTriangleArray();
glColorMask(1, 1, 1, 1); glColorMask(1, 1, 1, 1);
} }
} }
@ -161,8 +160,7 @@ inline Vector ZeroGS::CRenderTarget::DefaultBitBltTex()
inline void BindToSample(u32 *p_ptr) inline void BindToSample(u32 *p_ptr)
{ {
glBindTexture(GL_TEXTURE_RECTANGLE_NV, *p_ptr); glBindTexture(GL_TEXTURE_RECTANGLE_NV, *p_ptr);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); setRectFilters(GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
} }
//////////////////// ////////////////////
@ -518,7 +516,7 @@ void ZeroGS::CRenderTarget::Update(int context, ZeroGS::CRenderTarget* pdepth)
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
DrawTriangle(); DrawTriangleArray();
// fill stencil buf only // fill stencil buf only
FillOnlyStencilBuffer(); FillOnlyStencilBuffer();
@ -599,7 +597,7 @@ void ZeroGS::CRenderTarget::ConvertTo32()
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsConvert16to32.prog); SETPIXELSHADER(ppsConvert16to32.prog);
DrawTriangle(); DrawTriangleArray();
#ifdef _DEBUG #ifdef _DEBUG
if (g_bSaveZUpdate) if (g_bSaveZUpdate)
@ -706,7 +704,7 @@ void ZeroGS::CRenderTarget::ConvertTo16()
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsConvert32to16.prog); SETPIXELSHADER(ppsConvert32to16.prog);
DrawTriangle(); DrawTriangleArray();
#ifdef _DEBUG #ifdef _DEBUG
//g_bSaveZUpdate = 1; //g_bSaveZUpdate = 1;
@ -808,7 +806,7 @@ void ZeroGS::CRenderTarget::_CreateFeedback()
// render with an AA shader if possible (bilinearly interpolates data) // render with an AA shader if possible (bilinearly interpolates data)
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsBaseTexture.prog); SETPIXELSHADER(ppsBaseTexture.prog);
DrawTriangle(); DrawTriangleArray();
// restore // restore
swap(ptex, ptexFeedback); swap(ptex, ptexFeedback);
@ -1043,7 +1041,7 @@ void ZeroGS::CDepthTarget::Update(int context, ZeroGS::CRenderTarget* prndr)
//glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_HEIGHT_EXT, &h1); //glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_HEIGHT_EXT, &h1);
SetDepthStencilSurface(); SetDepthStencilSurface();
FBTexture(1, 0); FBTexture(1);
GLenum buffer = GL_COLOR_ATTACHMENT0_EXT; GLenum buffer = GL_COLOR_ATTACHMENT0_EXT;
@ -1060,7 +1058,7 @@ void ZeroGS::CDepthTarget::Update(int context, ZeroGS::CRenderTarget* prndr)
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsBitBltDepth.prog); SETPIXELSHADER(ppsBitBltDepth.prog);
DrawTriangle(); DrawTriangleArray();
status = TS_Resolved; status = TS_Resolved;
@ -1323,7 +1321,6 @@ CRenderTarget* ZeroGS::CRenderTargetMngr::GetTarg(const frameInfo& frame, u32 op
if (bfound) if (bfound)
{ {
// can be both 16bit and 32bit // can be both 16bit and 32bit
if (PSMT_ISHALF(frame.psm) != PSMT_ISHALF(it->second->psm)) if (PSMT_ISHALF(frame.psm) != PSMT_ISHALF(it->second->psm))
{ {
@ -1744,9 +1741,6 @@ bool ZeroGS::CMemoryTarget::ValidateClut(const tex0Info& tex0)
return true; return true;
} }
int VALIDATE_THRESH = 8;
u32 TEXDESTROY_THRESH = 16;
bool ZeroGS::CMemoryTarget::ValidateTex(const tex0Info& tex0, int starttex, int endtex, bool bDeleteBadTex) bool ZeroGS::CMemoryTarget::ValidateTex(const tex0Info& tex0, int starttex, int endtex, bool bDeleteBadTex)
{ {
FUNCLOG FUNCLOG
@ -2385,8 +2379,7 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
TextureRect(4, texW, texH, GL_RGBA, fmt, ptexdata); TextureRect(4, texW, texH, GL_RGBA, fmt, ptexdata);
} }
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); setRectWrap(GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP);
assert(tex0.psm != 0xd); assert(tex0.psm != 0xd);
@ -2582,8 +2575,7 @@ u32 ZeroGS::CBitwiseTextureMngr::GetTexInt(u32 bitvalue, u32 ptexDoNotDelete)
// Removing clamping, as it seems lead to numerous troubles at some drivers // Removing clamping, as it seems lead to numerous troubles at some drivers
// Need to observe, may be clamping is not really needed. // Need to observe, may be clamping is not really needed.
/*glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_REPEAT); /* setTexRectWrap(GL_REPEAT);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_REPEAT);
GLint Error = glGetError(); GLint Error = glGetError();
if( Error != GL_NO_ERROR ) { if( Error != GL_NO_ERROR ) {

View File

@ -309,12 +309,12 @@ inline u32 GetFrameKeyDummy(CRenderTarget* frame)
// And messes up Kingdom Hearts opening. I need to read up more on OpenGL. :( // And messes up Kingdom Hearts opening. I need to read up more on OpenGL. :(
//#define NO_NULL_TEXTURES //#define NO_NULL_TEXTURES
static __forceinline void DrawTriangle() static __forceinline void DrawTriangleArray()
{ {
#ifdef NO_NULL_TEXTURES #ifdef NO_NULL_TEXTURES
if (nullTex) if (nullTex)
{ {
ZZLog::Debug_Log("Drawing arrays without a texture!"); ZZLog::Debug_Log("Drawing triangle arrays without a texture!");
} }
else else
#endif #endif
@ -330,7 +330,7 @@ static __forceinline void DrawBuffers(GLenum *buffer)
{ {
#ifdef NO_NULL_TEXTURES #ifdef NO_NULL_TEXTURES
if (nullTex) if (nullTex)
ZZLog::Debug_Log("Update2: Drawing buffers without a texture!"); ZZLog::Debug_Log("Drawing buffers without a texture!");
else else
#endif #endif
glDrawBuffers(1, buffer); glDrawBuffers(1, buffer);
@ -339,27 +339,76 @@ static __forceinline void DrawBuffers(GLenum *buffer)
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
static __forceinline void FBTexture(int attach, int id) static __forceinline void FBTexture(int attach, int id = 0)
{ {
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + attach, GL_TEXTURE_RECTANGLE_NV, id, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + attach, GL_TEXTURE_RECTANGLE_NV, id, 0);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
static void Texture2D(GLint iFormat, GLenum format, GLenum type, const GLvoid* pixels) 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);
nullTex = (pixels == NULL);
}
static __forceinline void Texture2D(GLint iFormat, GLenum format, GLenum type, const GLvoid* pixels)
{ {
glTexImage2D(GL_TEXTURE_2D, 0, iFormat, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, format, type, pixels); glTexImage2D(GL_TEXTURE_2D, 0, iFormat, BLOCK_TEXWIDTH, BLOCK_TEXHEIGHT, 0, format, type, pixels);
nullTex = (pixels == NULL); nullTex = (pixels == NULL);
} }
static void TextureRect(GLint iFormat, GLint width, GLint height, GLenum format, GLenum type, const GLvoid* pixels) static __forceinline void Texture3D(GLint iFormat, GLint width, GLint height, GLint depth, GLenum format, GLenum type, const GLvoid* pixels)
{
glTexImage3D(GL_TEXTURE_2D, 0, iFormat, width, height, depth, 0, format, type, pixels);
nullTex = (pixels == NULL);
}
static __forceinline void TextureRect(GLint iFormat, GLint width, GLint height, GLenum format, GLenum type, const GLvoid* pixels)
{ {
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, iFormat, width, height, 0, format, type, pixels); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, iFormat, width, height, 0, format, type, pixels);
nullTex = (pixels == NULL); nullTex = (pixels == NULL);
} }
static void TextureRect(GLenum attach, GLuint id = 0) static __forceinline void TextureRect(GLenum attach, GLuint id = 0)
{ {
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attach, GL_RENDERBUFFER_EXT, id); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attach, GL_RENDERBUFFER_EXT, id);
} }
static __forceinline void setTex2DFilters(GLint type)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, type);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, type);
}
static __forceinline void setTex2DWrap(GLint type)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, type);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, type);
}
static __forceinline void setTex3DFilters(GLint type)
{
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, type);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, type);
}
static __forceinline void setTex3DWrap(GLint type)
{
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, type);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, type);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, type);
}
static __forceinline void setRectFilters(GLint type)
{
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, type);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, type);
}
static __forceinline void setRectWrap(GLint type)
{
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, type);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, type);
}
#endif #endif

View File

@ -158,7 +158,7 @@ void ExtWrite();
void ResetRenderTarget(int index) void ResetRenderTarget(int index)
{ {
FBTexture(index, 0); FBTexture(index);
} }
DrawFn drawfn[8] = { KickDummy, KickDummy, KickDummy, KickDummy, DrawFn drawfn[8] = { KickDummy, KickDummy, KickDummy, KickDummy,
@ -545,7 +545,7 @@ void ZeroGS::RenderCustom(float fAlpha)
SETVERTEXSHADER(pvsBitBlt.prog); SETVERTEXSHADER(pvsBitBlt.prog);
SETPIXELSHADER(ppsBaseTexture.prog); SETPIXELSHADER(ppsBaseTexture.prog);
DrawTriangle(); DrawTriangleArray();
// restore // restore
if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@ -1210,22 +1210,37 @@ void ZeroGS::texClutWrite(int ctx)
} }
else else
{ {
switch (tex0.cpsm) u32* src = (u32*)(g_pbyGSMemory + 256 * tex0.cbp);
if (entries == 16)
{ {
case PSMCT24: switch (tex0.cpsm)
case PSMCT32: {
if (entries == 16) case PSMCT24:
WriteCLUT_T32_I4_CSM1((u32*)(g_pbyGSMemory + tex0.cbp*256), (u32*)(g_pbyGSClut + 64*tex0.csa)); case PSMCT32:
else WriteCLUT_T32_I4_CSM1(src, (u32*)(g_pbyGSClut + 64 * tex0.csa));
WriteCLUT_T32_I8_CSM1((u32*)(g_pbyGSMemory + tex0.cbp*256), (u32*)(g_pbyGSClut + 64*tex0.csa)); break;
break;
default:
WriteCLUT_T16_I4_CSM1(src, (u32*)(g_pbyGSClut + 32*(tex0.csa & 15) + (tex0.csa >= 16 ? 2 : 0)));
break;
}
}
else
{
switch (tex0.cpsm)
{
case PSMCT24:
case PSMCT32:
WriteCLUT_T32_I8_CSM1(src, (u32*)(g_pbyGSClut + 64 * tex0.csa));
break;
default:
// sse2 for 256 is more complicated, so use regular
WriteCLUT_T16_I8_CSM1_c(src, (u32*)(g_pbyGSClut + 32*(tex0.csa & 15) + (tex0.csa >= 16 ? 2 : 0)));
break;
}
default:
if (entries == 16)
WriteCLUT_T16_I4_CSM1((u32*)(g_pbyGSMemory + 256 * tex0.cbp), (u32*)(g_pbyGSClut + 32*(tex0.csa&15) + (tex0.csa >= 16 ? 2 : 0)));
else // sse2 for 256 is more complicated, so use regular
WriteCLUT_T16_I8_CSM1_c((u32*)(g_pbyGSMemory + 256 * tex0.cbp), (u32*)(g_pbyGSClut + 32*(tex0.csa&15) + (tex0.csa >= 16 ? 2 : 0)));
break;
} }
} }
} }

View File

@ -99,39 +99,6 @@ using namespace std;
#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it)) #define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it))
// sends a message to output window if assert fails
#define BMSG(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); } }
#define BMSG_RETURN(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return; } }
#define BMSG_RETURNX(x, str, rtype) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return (##rtype); } }
#define B(x) { if( !(x) ) { ZZLog::Log(_#x"\n"); ZZLog::Log(#x"\n"); } }
#define B_RETURN(x) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return; } }
#define B_RETURNX(x, rtype) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return (##rtype); } }
#define B_G(x, action) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); action; } }
#define GL_REPORT_ERROR() \
{ \
GLenum err = glGetError(); \
if( err != GL_NO_ERROR ) \
{ \
ZZLog::Error_Log("%s:%d: gl error %s(0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \
ZeroGS::HandleGLError(); \
} \
}
#ifdef _DEBUG
# define GL_REPORT_ERRORD() \
{ \
GLenum err = glGetError(); \
if( err != GL_NO_ERROR ) \
{ \
ZZLog::Error_Log("%s:%d: gl error %s (0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \
ZeroGS::HandleGLError(); \
} \
}
#else
# define GL_REPORT_ERRORD()
#endif
// sets the data stream // sets the data stream
#define SET_STREAM() { \ #define SET_STREAM() { \
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8); \ glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8); \
@ -182,42 +149,6 @@ const float g_filog32 = 0.999f / (32.0f * logf(2.0f));
//------------------------ Inlines ------------------------- //------------------------ Inlines -------------------------
inline const char *error_name(int err)
{
switch (err)
{
case GL_NO_ERROR:
return "GL_NO_ERROR";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
case GL_TABLE_TOO_LARGE:
return "GL_TABLE_TOO_LARGE";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
default:
return "Unknown GL error";
}
}
// inline for an extremely often used sequence // inline for an extremely often used sequence
// This is turning off all gl functions. Safe to do updates. // This is turning off all gl functions. Safe to do updates.
inline void DisableAllgl() inline void DisableAllgl()