Skip to content

Commit

Permalink
Add PGXP visual debug mode
Browse files Browse the repository at this point in the history
Toggles using F11
Red = low precision
Blue = high precision
Yellow = Sprite
  • Loading branch information
iCatButler committed May 10, 2016
1 parent 1a30cfb commit b5a7387
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/SyncToy_b769e033-01a5-40b2-9c12-6b3a0fbe40a4.dat
3 changes: 3 additions & 0 deletions libpcsxcore/plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GPUdmaChain GPU_dmaChain;
GPUkeypressed GPU_keypressed;
GPUdisplayText GPU_displayText;
GPUmakeSnapshot GPU_makeSnapshot;
GPUtoggleDebug GPU_toggleDebug;
GPUfreeze GPU_freeze;
GPUgetScreenPic GPU_getScreenPic;
GPUshowScreenPic GPU_showScreenPic;
Expand Down Expand Up @@ -207,6 +208,7 @@ long CALLBACK GPU__configure(void) { return 0; }
long CALLBACK GPU__test(void) { return 0; }
void CALLBACK GPU__about(void) {}
void CALLBACK GPU__makeSnapshot(void) {}
void CALLBACK GPU__toggleDebug(void) {}
void CALLBACK GPU__keypressed(int key) {}
long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; }
long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; }
Expand Down Expand Up @@ -254,6 +256,7 @@ static int LoadGPUplugin(const char *GPUdll) {
LoadGpuSym0(keypressed, "GPUkeypressed");
LoadGpuSym0(displayText, "GPUdisplayText");
LoadGpuSym0(makeSnapshot, "GPUmakeSnapshot");
LoadGpuSym0(toggleDebug, "GPUtoggleDebug");
LoadGpuSym1(freeze, "GPUfreeze");
LoadGpuSym0(getScreenPic, "GPUgetScreenPic");
LoadGpuSym0(showScreenPic, "GPUshowScreenPic");
Expand Down
2 changes: 2 additions & 0 deletions libpcsxcore/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef long (CALLBACK* GPUconfigure)(void);
typedef long (CALLBACK* GPUtest)(void);
typedef void (CALLBACK* GPUabout)(void);
typedef void (CALLBACK* GPUmakeSnapshot)(void);
typedef void (CALLBACK* GPUtoggleDebug)(void);
typedef void (CALLBACK* GPUkeypressed)(int);
typedef void (CALLBACK* GPUdisplayText)(char *);
typedef struct {
Expand Down Expand Up @@ -118,6 +119,7 @@ extern GPUdmaChain GPU_dmaChain;
extern GPUkeypressed GPU_keypressed;
extern GPUdisplayText GPU_displayText;
extern GPUmakeSnapshot GPU_makeSnapshot;
extern GPUtoggleDebug GPU_toggleDebug;
extern GPUfreeze GPU_freeze;
extern GPUgetScreenPic GPU_getScreenPic;
extern GPUshowScreenPic GPU_showScreenPic;
Expand Down
2 changes: 2 additions & 0 deletions plugins/peopsxgl/externals.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ typedef struct OGLVertexTag
unsigned char col[4];
unsigned int lcol;
} c;

unsigned int PGXP_flag;
} OGLVertex;

typedef union EXShortTag
Expand Down
1 change: 1 addition & 0 deletions plugins/peopsxgl/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,7 @@ void CALLBACK GPUwriteDataMem(uint32_t *pMem, int iSize)
vertex[i].x = vertex[i].y = 0.f;
vertex[i].z = 0.95f;
vertex[i].w = 1.f;
vertex[i].PGXP_flag = 0;
}
primFunc[gpuCommand]((unsigned char *)gpuDataM);

Expand Down
184 changes: 174 additions & 10 deletions plugins/peopsxgl/pgxp_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,25 @@ void PGXP_SetMatrix(float left, float right, float bottom, float top, float zNea
void PGXP_glVertexfv(GLfloat* pV)
{
// If there are PGXP vertices expected
//if (vertexIdx < numVertices)
//{
if (1)//(vertexIdx < numVertices)
{
float temp[4];
memcpy(temp, pV, sizeof(float) * 4);

// pre-multiply each element by w (to negate perspective divide)
//pre-multiply each element by w (to negate perspective divide)
for (unsigned int i = 0; i < 3; i++)
temp[i] *= temp[3];

// pass complete vertex to OpenGL
//pass complete vertex to OpenGL
glVertex4fv(temp);
vertexIdx++;

// pV[3] = 1.f;
//}
//else
//{
// glVertex3fv(pV);
//}
//pV[3] = 1.f;
}
else
{
glVertex3fv(pV);
}
}

// Get parallel vertex values
Expand Down Expand Up @@ -170,9 +170,173 @@ int PGXP_GetVertices(unsigned int* addr, void* pOutput, int xOffs, int yOffs)
pVertex[i].y = (primStart[stride * i].y + yOffs);
pVertex[i].z = 0.95f;
pVertex[i].w = w;
pVertex[i].PGXP_flag = 1;
}
else
pVertex[i].PGXP_flag = 2;
}

return 1;
}

/////////////////////////////////
//// Visual Debugging Functions
/////////////////////////////////
unsigned int PGXP_vDebug = 0;

const char blue[4] = { 0, 0, 255, 255 };
const char red[4] = { 255, 0, 0, 255 };
const char black[4] = { 0, 0, 0, 255 };
const char yellow[4] = { 255, 255, 0, 255 };

void CALLBACK GPUtoggleDebug(void)
{
if (PGXP_vDebug)
PGXP_vDebug = 0;
else
PGXP_vDebug = 1;
}

const char* PGXP_colour(unsigned int flag)
{
switch (flag)
{
case 0:
return yellow;
case 1:
return blue;
case 2:
return red;
default:
return black;
}
}

void PGXP_DrawDebugTriQuad(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3, OGLVertex* vertex4)
{
GLboolean bTexture = glIsEnabled(GL_TEXTURE_2D);
GLfloat fColour[4];
glGetFloatv(GL_CURRENT_COLOR, fColour);
glDisable(GL_TEXTURE_2D);

glBegin(GL_TRIANGLE_STRIP);

glColor4ubv(PGXP_colour(vertex1->PGXP_flag));
PGXP_glVertexfv(&vertex1->x);

glColor4ubv(PGXP_colour(vertex2->PGXP_flag));
PGXP_glVertexfv(&vertex2->x);

glColor4ubv(PGXP_colour(vertex3->PGXP_flag));
PGXP_glVertexfv(&vertex3->x);

glColor4ubv(PGXP_colour(vertex4->PGXP_flag));
PGXP_glVertexfv(&vertex4->x);

glEnd();

glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);

glBegin(GL_TRIANGLE_STRIP);

glColor4ubv(black);
PGXP_glVertexfv(&vertex1->x);
PGXP_glVertexfv(&vertex2->x);
PGXP_glVertexfv(&vertex3->x);
PGXP_glVertexfv(&vertex4->x);

glColor4fv(fColour);

glEnd();

glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);

if(bTexture == GL_TRUE)
glEnable(GL_TEXTURE_2D);
}

void PGXP_DrawDebugTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3)
{
GLboolean bTexture = glIsEnabled(GL_TEXTURE_2D);
GLfloat fColour[4];
glGetFloatv(GL_CURRENT_COLOR, fColour);
glDisable(GL_TEXTURE_2D);

glBegin(GL_TRIANGLES);

glColor4ubv(PGXP_colour(vertex1->PGXP_flag));
PGXP_glVertexfv(&vertex1->x);

glColor4ubv(PGXP_colour(vertex2->PGXP_flag));
PGXP_glVertexfv(&vertex2->x);

glColor4ubv(PGXP_colour(vertex3->PGXP_flag));
PGXP_glVertexfv(&vertex3->x);

glEnd();

glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);

glBegin(GL_TRIANGLE_STRIP);

glColor4ubv(black);
PGXP_glVertexfv(&vertex1->x);
PGXP_glVertexfv(&vertex2->x);
PGXP_glVertexfv(&vertex3->x);

glColor4fv(fColour);

glEnd();

glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);

if (bTexture == GL_TRUE)
glEnable(GL_TEXTURE_2D);
}

void PGXP_DrawDebugQuad(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3, OGLVertex* vertex4)
{
GLboolean bTexture = glIsEnabled(GL_TEXTURE_2D);
GLfloat fColour[4];
glGetFloatv(GL_CURRENT_COLOR, fColour);
glDisable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
glColor4ubv(PGXP_colour(vertex1->PGXP_flag));
PGXP_glVertexfv(&vertex1->x);

glColor4ubv(PGXP_colour(vertex2->PGXP_flag));
PGXP_glVertexfv(&vertex2->x);

glColor4ubv(PGXP_colour(vertex3->PGXP_flag));
PGXP_glVertexfv(&vertex3->x);

glColor4ubv(PGXP_colour(vertex4->PGXP_flag));
PGXP_glVertexfv(&vertex4->x);
glEnd();

glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);

glBegin(GL_TRIANGLE_STRIP);

glColor4ubv(black);
PGXP_glVertexfv(&vertex1->x);
PGXP_glVertexfv(&vertex2->x);
PGXP_glVertexfv(&vertex3->x);
PGXP_glVertexfv(&vertex4->x);

glColor4fv(fColour);

glEnd();

glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);

if (bTexture == GL_TRUE)
glEnable(GL_TEXTURE_2D);
}
11 changes: 11 additions & 0 deletions plugins/peopsxgl/pgxp_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,20 @@

#include "stdafx.h"

//struct OGLVertex;

struct OGLVertexTag;
typedef struct OGLVertexTag OGLVertex;

void PGXP_SetMatrix(float left, float right, float bottom, float top, float zNear, float zFar);
void PGXP_SetAddress(unsigned int addr);
int PGXP_GetVertices(unsigned int* addr, void* pOutput, int xOffs, int yOffs);
void PGXP_glVertexfv(GLfloat* pVertex);

extern unsigned int PGXP_vDebug;
extern unsigned int PGXP_debugFlags[4];
void PGXP_DrawDebugTriQuad(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3, OGLVertex* vertex4);
void PGXP_DrawDebugTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3);
void PGXP_DrawDebugQuad(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3, OGLVertex* vertex4);

#endif // _PGXP_GPU_H_
Loading

0 comments on commit b5a7387

Please sign in to comment.