/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/zerogs.cpp
ViewVC logotype

Diff of /trunk/plugins/zzogl-pg/opengl/zerogs.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/plugins/zzogl-pg/opengl/zerogs.cpp	2010/09/07 03:24:11	31
+++ trunk/plugins/zzogl-pg/opengl/zerogs.cpp	2010/09/07 11:08:22	62
@@ -1,5 +1,6 @@
-/*  ZeroGS KOSMOS
- *  Copyright (C) 2005-2006 zerofrog@gmail.com
+/*  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
@@ -13,31 +14,24 @@
  *
  *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
 //-------------------------- Includes
 #if defined(_WIN32)
 #	include <windows.h>
-//#	include <aviUtil.h>
 #	include "resource.h"
 #endif
 
-#include <stdio.h>
-
-#include <malloc.h>
-#include <assert.h>
 #include <stdlib.h>
-#include <string.h>
 
 #include "GS.h"
 #include "Mem.h"
 #include "x86.h"
 #include "zerogs.h"
 #include "zpipe.h"
-
-#include "ZeroGSShaders/zerogsshaders.h"
 #include "targets.h"
+#include "GLWin.h"
 
 //----------------------- Defines
 
@@ -52,21 +46,11 @@
 extern char *libraryName;
 extern int g_nFrame, g_nRealFrame;
 
+//extern int s_nFullscreen;
 //-------------------------- Variables
 
-#ifdef _WIN32
-HDC			hDC = NULL;	 // Private GDI Device Context
-HGLRC		hRC = NULL;	 // Permanent Rendering Context
-#endif
-
-bool g_bIsLost = 0;									// ZZ
-
-bool g_bMakeSnapshot = 0;
-string strSnapshot;
-
+primInfo *prim;
 CGprogram g_vsprog = 0, g_psprog = 0;							// 2 -- ZZ
-// AVI Capture
-int s_avicapturing = 0;
 
 inline u32 FtoDW(float f) { return (*((u32*)&f)); }
 
@@ -99,20 +83,13 @@
 // graphics resources
 CGparameter g_vparamPosXY[2] = {0}, g_fparamFogColor = 0;
 
-map<int, SHADERHEADER*> mapShaderResources;
-
 bool s_bTexFlush = false;
 int s_nLastResolveReset = 0;
-int s_nWireframeCount = 0;
 int s_nResolveCounts[30] = {0}; // resolve counts for last 30 frames
 
 ////////////////////
 // State parameters
-CGcontext g_cgcontext;
-int nBackbufferWidth, nBackbufferHeight;
-
-u8* g_pbyGSMemory = NULL;   // 4Mb GS system mem
-u8* g_pbyGSClut = NULL;													// ZZ
+int nBackbufferWidth, nBackbufferHeight;									// ZZ
 
 namespace ZeroGS
 {
@@ -166,7 +143,7 @@
 
 void ResetRenderTarget(int index)
 {
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + index, GL_TEXTURE_RECTANGLE_NV, 0, 0);
+	FBTexture(index);
 }
 
 DrawFn drawfn[8] = { KickDummy, KickDummy, KickDummy, KickDummy,
@@ -183,7 +160,7 @@
 	public:
 		ZeroGSInit()
 		{
-			const u32 mem_size = 0x00400000 + 0x10000; // leave some room for out of range accesses (saves on the checks)
+			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);
@@ -219,7 +196,8 @@
 
 	if (error != 0)
 	{
-		int w, h;
+		int w = 0;
+		int h = 0;
 		GLint fmt;
 		glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_INTERNAL_FORMAT_EXT, &fmt);
 		glGetRenderbufferParameterivEXT(GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_WIDTH_EXT, &w);
@@ -263,13 +241,12 @@
 				break;
 
 			default:
-				ZZLog::Error_Log("*UNKNOWN ERROR* reported from glCheckFramebufferStatusEXT() for %s!");
+				ZZLog::Error_Log("*UNKNOWN ERROR* reported from glCheckFramebufferStatusEXT(0x%x)!", error);
 				break;
 		}
 	}
 }
 
-
 void ZeroGS::GSStateReset()
 {
 	FUNCLOG
@@ -299,6 +276,62 @@
 	vb[1].ictx = 1;
 }
 
+void ZeroGS::Reset()
+{
+	FUNCLOG
+	s_RTs.ResolveAll();
+	s_DepthRTs.ResolveAll();
+
+	vb[0].nCount = 0;
+	vb[1].nCount = 0;
+
+	memset(s_nResolveCounts, 0, sizeof(s_nResolveCounts));
+	s_nLastResolveReset = 0;
+
+	icurctx = -1;
+	g_vsprog = g_psprog = 0;
+
+	GSStateReset();
+	Destroy(0);
+
+	drawfn[0] = KickDummy;
+	drawfn[1] = KickDummy;
+	drawfn[2] = KickDummy;
+	drawfn[3] = KickDummy;
+	drawfn[4] = KickDummy;
+	drawfn[5] = KickDummy;
+	drawfn[6] = KickDummy;
+	drawfn[7] = KickDummy;
+}
+
+void ZeroGS::GSReset()
+{
+	FUNCLOG
+
+	memset(&gs, 0, sizeof(gs));
+
+	ZeroGS::GSStateReset();
+
+	gs.prac = 1;
+	prim = &gs._prim[0];
+	gs.nTriFanVert = -1;
+	gs.imageTransfer = -1;
+	gs.q = 1;
+}
+
+void ZeroGS::GSSoftReset(u32 mask)
+{
+	FUNCLOG
+
+	if (mask & 1) memset(&gs.path[0], 0, sizeof(gs.path[0]));
+	if (mask & 2) memset(&gs.path[1], 0, sizeof(gs.path[1]));
+	if (mask & 4) memset(&gs.path[2], 0, sizeof(gs.path[2]));
+
+	gs.imageTransfer = -1;
+	gs.q = 1;
+	gs.nTriFanVert = -1;
+}
+
 void ZeroGS::AddMessage(const char* pstr, u32 ms)
 {
 	FUNCLOG
@@ -306,6 +339,7 @@
 	ZZLog::Log("%s\n", pstr);
 }
 
+extern RasterFont* font_p;
 void ZeroGS::DrawText(const char* pstr, int left, int top, u32 color)
 {
 	FUNCLOG
@@ -328,11 +362,10 @@
 	nBackbufferWidth = max(nNewWidth, 16);
 	nBackbufferHeight = max(nNewHeight, 16);
 
-	if (!(conf.options & GSOPTION_FULLSCREEN))
+	if (!(conf.fullscreen()))
 	{
 		conf.width = nNewWidth;
 		conf.height = nNewHeight;
-		//SaveConfig();
 	}
 }
 
@@ -342,42 +375,13 @@
 	s_nNewWidth = nNewWidth;
 	s_nNewHeight = nNewHeight;
 
-	if (!(conf.options & GSOPTION_FULLSCREEN))
+	if (!(conf.fullscreen()))
 	{
 		conf.width = nNewWidth;
 		conf.height = nNewHeight;
-		//SaveConfig();
 	}
 }
 
-void ZeroGS::Reset()
-{
-	FUNCLOG
-	s_RTs.ResolveAll();
-	s_DepthRTs.ResolveAll();
-
-	vb[0].nCount = 0;
-	vb[1].nCount = 0;
-
-	memset(s_nResolveCounts, 0, sizeof(s_nResolveCounts));
-	s_nLastResolveReset = 0;
-
-	icurctx = -1;
-	g_vsprog = g_psprog = 0;
-
-	GSStateReset();
-	Destroy(0);
-
-	drawfn[0] = KickDummy;
-	drawfn[1] = KickDummy;
-	drawfn[2] = KickDummy;
-	drawfn[3] = KickDummy;
-	drawfn[4] = KickDummy;
-	drawfn[5] = KickDummy;
-	drawfn[6] = KickDummy;
-	drawfn[7] = KickDummy;
-}
-
 void ZeroGS::ChangeDeviceSize(int nNewWidth, int nNewHeight)
 {
 	FUNCLOG
@@ -477,8 +481,6 @@
 {
 	FUNCLOG
 
-	if (g_bIsLost) return;
-
 	VB& curvb = vb[prim->ctxt];
 
 	if (curvb.CheckPrim()) Flush(prim->ctxt);
@@ -543,7 +545,7 @@
 	v.x = v.y = v.z = v.w = fAlpha;
 	ZZcgSetParameter4fv(ppsBaseTexture.sOneColor, v, "g_fOneColor");
 
-	if (conf.options & GSOPTION_WIREFRAME) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+	if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
 	// inside vhDCb[0]'s target area, so render that region only
 	cgGLSetTextureParameter(ppsBaseTexture.sFinal, ptexLogo);
@@ -554,11 +556,10 @@
 
 	SETVERTEXSHADER(pvsBitBlt.prog);
 	SETPIXELSHADER(ppsBaseTexture.prog);
-
-	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
+	DrawTriangleArray();
+	
 	// restore
-	if (conf.options & GSOPTION_WIREFRAME) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	if (conf.wireframe()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
 	ProcessMessages();
 
@@ -571,25 +572,6 @@
 	vb[1].bSyncVars = 0;
 
 	GL_REPORT_ERROR();
-
-	GLint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-
-	assert(status == GL_FRAMEBUFFER_COMPLETE_EXT || status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT);
-}
-
-void ZeroGS::Restore()
-{
-	FUNCLOG
-
-	if (!g_bIsLost) return;
-
-	//if( SUCCEEDED(pd3dDevice->Reset(&d3dpp)) ) {
-	g_bIsLost = 0;
-
-	// handle lost states
-	ZeroGS::ChangeDeviceSize(nBackbufferWidth, nBackbufferHeight);
-
-	//}
 }
 
 //////////////////////////
@@ -609,21 +591,12 @@
 
 
 int Values[100] = {0, };
-__forceinline void SET_VERTEX(VertexGPU *p, int Index, const VB& curvb)
+
+void SET_VERTEX(VertexGPU *p, int Index, const VB& curvb)
 {
 	int index = Index;
 	p->x = ((((int)gs.gsvertex[index].x - curvb.offset.x) >> 1) & 0xffff);
 	p->y = ((((int)gs.gsvertex[index].y - curvb.offset.y) >> 1) & 0xffff);
-
-#ifdef LSD_MODE
-	int diffX = (int)gs.gsvertex[index].x - curvb.offset.x;
-	int diffY = (int)gs.gsvertex[index].y - curvb.offset.y;
-
-	if (diffX < 0) { p->x = - p->x; }
-	if (diffY < 0) { p->y = - p->y; }
-#endif
-
-
 	p->f = ((s16)gs.gsvertex[index].f << 7) | 0x7f;
 
 	MOVZ(p, gs.gsvertex[index].z, curvb);
@@ -634,7 +607,7 @@
 //	if ((gs.texa.aem) && ((p->rgba & 0xffffff ) == 0))
 //		p->rgba = 0;
 
-	if (g_GameSettings & GAME_TEXAHACK)
+	if (conf.settings().texa)
 	{
 		u32 B = ((p->rgba & 0xfe000000) >> 1) +
 				(0x01000000 * curvb.fba.fba) ;
@@ -674,7 +647,7 @@
 
 	VB& curvb = vb[prim->ctxt];
 
-	if (curvb.bNeedTexCheck) curvb.FlushTexData();
+	curvb.FlushTexData();
 
 	if ((vb[!prim->ctxt].nCount > 0) && (vb[prim->ctxt].gsfb.fbp == vb[!prim->ctxt].gsfb.fbp))
 	{
@@ -699,7 +672,7 @@
 	assert(gs.primC >= 2);
 	VB& curvb = vb[prim->ctxt];
 
-	if (curvb.bNeedTexCheck) curvb.FlushTexData();
+	curvb.FlushTexData();
 
 	if ((vb[!prim->ctxt].nCount > 0) && (vb[prim->ctxt].gsfb.fbp == vb[!prim->ctxt].gsfb.fbp))
 	{
@@ -728,7 +701,7 @@
 	assert(gs.primC >= 3);
 	VB& curvb = vb[prim->ctxt];
 
-	if (curvb.bNeedTexCheck) curvb.FlushTexData();
+	curvb.FlushTexData();
 
 	if ((vb[!prim->ctxt].nCount > 0) && (vb[prim->ctxt].gsfb.fbp == vb[!prim->ctxt].gsfb.fbp))
 	{
@@ -756,7 +729,7 @@
 	assert(gs.primC >= 3);
 	VB& curvb = vb[prim->ctxt];
 
-	if (curvb.bNeedTexCheck) curvb.FlushTexData();
+	curvb.FlushTexData();
 
 	if ((vb[!prim->ctxt].nCount > 0) && (vb[prim->ctxt].gsfb.fbp == vb[!prim->ctxt].gsfb.fbp))
 	{
@@ -782,7 +755,7 @@
 	OUTPUT_VERT(p[2], 2);
 }
 
-__forceinline void SetKickVertex(VertexGPU *p, Vertex v, int next, const VB& curvb)
+void SetKickVertex(VertexGPU *p, Vertex v, int next, const VB& curvb)
 {
 	SET_VERTEX(p, next, curvb);
 	MOVZ(p, v.z, curvb);
@@ -795,7 +768,7 @@
 	assert(gs.primC >= 2);
 	VB& curvb = vb[prim->ctxt];
 
-	if (curvb.bNeedTexCheck) curvb.FlushTexData();
+	curvb.FlushTexData();
 
 	if ((vb[!prim->ctxt].nCount > 0) && (vb[prim->ctxt].gsfb.fbp == vb[!prim->ctxt].gsfb.fbp))
 	{
@@ -807,15 +780,10 @@
 
 	int next = (gs.primIndex + 1) % ARRAY_SIZE(gs.gsvertex);
 	int last = (gs.primIndex + 2) % ARRAY_SIZE(gs.gsvertex);
-
-	// sprite is too small and AA shows lines (tek4)
-
-	if (s_AAx)
-	{
-		gs.gsvertex[last].x += 4;
-
-		if (s_AAy) gs.gsvertex[last].y += 4;
-	}
+	
+	// sprite is too small and AA shows lines (tek4, Mana Khemia)
+	gs.gsvertex[last].x += (4*s_AAx);
+	gs.gsvertex[last].y += (4*s_AAy);
 
 	// might be bad sprite (KH dialog text)
 	//if( gs.gsvertex[next].x == gs.gsvertex[last].x || gs.gsvertex[next].y == gs.gsvertex[last].y )
@@ -858,25 +826,34 @@
 //	{
 	gs.fogcol = fog;
 
-	ZeroGS::Flush(0);
-	ZeroGS::Flush(1);
+	ZeroGS::FlushBoth();
 
-	if (!g_bIsLost)
-	{
-		SetShaderCaller("SetFogColor");
-		Vector v;
+	SetShaderCaller("SetFogColor");
+	Vector v;
 
-		// set it immediately
-//			v.x = (gs.fogcol & 0xff) / 255.0f;
-//			v.y = ((gs.fogcol >> 8) & 0xff) / 255.0f;
-//			v.z = ((gs.fogcol >> 16) & 0xff) / 255.0f;
-		v.SetColor(gs.fogcol);
-		ZZcgSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
-	}
+	// set it immediately
+//	v.x = (gs.fogcol & 0xff) / 255.0f;
+//	v.y = ((gs.fogcol >> 8) & 0xff) / 255.0f;
+//	v.z = ((gs.fogcol >> 16) & 0xff) / 255.0f;
+	v.SetColor(gs.fogcol);
+	ZZcgSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
 
 //	}
 }
 
+void ZeroGS::SetFogColor(GIFRegFOGCOL* fog)
+{
+	FUNCLOG
+	
+	SetShaderCaller("SetFogColor");
+	Vector v;
+	
+	v.x = fog->FCR / 255.0f;
+	v.y = fog->FCG / 255.0f;
+	v.z = fog->FCB / 255.0f;
+	ZZcgSetParameter4fv(g_fparamFogColor, v, "g_fParamFogColor");
+}
+
 void ZeroGS::ExtWrite()
 {
 	FUNCLOG
@@ -1114,9 +1091,7 @@
 void ZeroGS::texClutWrite(int ctx)
 {
 	FUNCLOG
-	s_bTexFlush = 0;
-
-	if (g_bIsLost) return;
+	s_bTexFlush = false;
 
 	tex0Info& tex0 = vb[ctx].tex0;
 
@@ -1226,22 +1201,37 @@
 	}
 	else
 	{
-		switch (tex0.cpsm)
+		u32* src = (u32*)(g_pbyGSMemory + 256 * tex0.cbp);
+		
+		if (entries == 16)
 		{
-			case PSMCT24:
-			case PSMCT32:
-				if (entries == 16)
-					WriteCLUT_T32_I4_CSM1((u32*)(g_pbyGSMemory + tex0.cbp*256), (u32*)(g_pbyGSClut + 64*tex0.csa));
-				else
-					WriteCLUT_T32_I8_CSM1((u32*)(g_pbyGSMemory + tex0.cbp*256), (u32*)(g_pbyGSClut + 64*tex0.csa));
-				break;
+			switch (tex0.cpsm)
+			{
+				case PSMCT24:
+				case PSMCT32:
+					WriteCLUT_T32_I4_CSM1(src, (u32*)(g_pbyGSClut + 64 * tex0.csa));
+					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;
 		}
 	}
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22