Fix some issues with clipping
This commit is contained in:
parent
a8f3d86705
commit
f8d1fa3439
@ -4,7 +4,7 @@
|
|||||||
#include "sh4.h"
|
#include "sh4.h"
|
||||||
|
|
||||||
|
|
||||||
#define CLIP_DEBUG 1
|
#define CLIP_DEBUG 0
|
||||||
|
|
||||||
#define PVR_VERTEX_BUF_SIZE 2560 * 256
|
#define PVR_VERTEX_BUF_SIZE 2560 * 256
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ void SceneListSubmit(Vertex* vertices, int n) {
|
|||||||
|
|
||||||
#if CLIP_DEBUG
|
#if CLIP_DEBUG
|
||||||
fprintf(stderr, "----\n");
|
fprintf(stderr, "----\n");
|
||||||
|
|
||||||
Vertex* vertex = (Vertex*) vertices;
|
Vertex* vertex = (Vertex*) vertices;
|
||||||
for(int i = 0; i < n; ++i) {
|
for(int i = 0; i < n; ++i) {
|
||||||
fprintf(stderr, "IN: {%f, %f, %f, %f}, // %x (%x)\n", vertex[i].xyz[0], vertex[i].xyz[1], vertex[i].xyz[2], vertex[i].w, vertex[i].flags, &vertex[i]);
|
fprintf(stderr, "IN: {%f, %f, %f, %f}, // %x (%x)\n", vertex[i].xyz[0], vertex[i].xyz[1], vertex[i].xyz[2], vertex[i].w, vertex[i].flags, &vertex[i]);
|
||||||
@ -230,6 +230,27 @@ void SceneListSubmit(Vertex* vertices, int n) {
|
|||||||
Vertex* v1 = v0 + 1;
|
Vertex* v1 = v0 + 1;
|
||||||
Vertex* v2 = v0 + 2;
|
Vertex* v2 = v0 + 2;
|
||||||
|
|
||||||
|
assert(!is_header(v1));
|
||||||
|
|
||||||
|
if(is_header(v2)) {
|
||||||
|
// OK so we've hit a new context header
|
||||||
|
// we need to finalize this strip and move on
|
||||||
|
SUBMIT_QUEUED_VERTEX(qv.flags);
|
||||||
|
|
||||||
|
_glPerspectiveDivideVertex(v0, h);
|
||||||
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
|
_glPerspectiveDivideVertex(v1, h);
|
||||||
|
_glPushHeaderOrVertex(v1);
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(!is_header(v2));
|
||||||
|
|
||||||
|
// FIXME: What if v1 or v2 are headers? Should we handle that or just
|
||||||
|
// assume the user has done something weird and all bets are off?
|
||||||
|
|
||||||
int visible_mask = (
|
int visible_mask = (
|
||||||
(v0->xyz[2] >= -v0->w) << 0 |
|
(v0->xyz[2] >= -v0->w) << 0 |
|
||||||
(v1->xyz[2] >= -v1->w) << 1 |
|
(v1->xyz[2] >= -v1->w) << 1 |
|
||||||
@ -244,9 +265,9 @@ void SceneListSubmit(Vertex* vertices, int n) {
|
|||||||
SUBMIT_QUEUED_VERTEX(qv.flags);
|
SUBMIT_QUEUED_VERTEX(qv.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CLIP_DEBUG
|
#if CLIP_DEBUG
|
||||||
fprintf(stderr, "0x%x 0x%x 0x%x -> %d\n", v0, v1, v2, visible_mask);
|
fprintf(stderr, "0x%x 0x%x 0x%x -> %d\n", v0, v1, v2, visible_mask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Vertex __attribute__((aligned(32))) scratch[4];
|
Vertex __attribute__((aligned(32))) scratch[4];
|
||||||
Vertex* a = &scratch[0], *b = &scratch[1], *c = &scratch[2], *d = &scratch[3];
|
Vertex* a = &scratch[0], *b = &scratch[1], *c = &scratch[2], *d = &scratch[3];
|
||||||
@ -277,7 +298,7 @@ void SceneListSubmit(Vertex* vertices, int n) {
|
|||||||
|
|
||||||
QUEUE_VERTEX(b);
|
QUEUE_VERTEX(b);
|
||||||
break;
|
break;
|
||||||
case SECOND_VISIBLE:
|
case SECOND_VISIBLE:
|
||||||
memcpy_vertex(c, v1);
|
memcpy_vertex(c, v1);
|
||||||
|
|
||||||
_glClipEdge(v0, v1, a);
|
_glClipEdge(v0, v1, a);
|
||||||
@ -385,18 +406,6 @@ void SceneListSubmit(Vertex* vertices, int n) {
|
|||||||
default:
|
default:
|
||||||
fprintf(stderr, "ERROR\n");
|
fprintf(stderr, "ERROR\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(v2->flags == GPU_CMD_VERTEX_EOL && visible_mask == ALL_VISIBLE) {
|
|
||||||
SUBMIT_QUEUED_VERTEX(qv.flags);
|
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v1, h);
|
|
||||||
_glPushHeaderOrVertex(v1);
|
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v2, h);
|
|
||||||
_glPushHeaderOrVertex(v2);
|
|
||||||
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBMIT_QUEUED_VERTEX(GPU_CMD_VERTEX_EOL);
|
SUBMIT_QUEUED_VERTEX(GPU_CMD_VERTEX_EOL);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
|
|||||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||||
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glEnable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity(); // Reset The Projection Matrix
|
glLoadIdentity(); // Reset The Projection Matrix
|
||||||
@ -64,30 +64,38 @@ int check_start() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLfloat movement = 0.0f;
|
||||||
|
static GLfloat rotation = 0.0f;
|
||||||
|
|
||||||
|
void update_movement() {
|
||||||
|
#ifdef __DREAMCAST__
|
||||||
|
maple_device_t *cont;
|
||||||
|
cont_state_t *state;
|
||||||
|
|
||||||
|
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
|
||||||
|
|
||||||
|
if(cont) {
|
||||||
|
state = (cont_state_t *)maple_dev_status(cont);
|
||||||
|
if(state) {
|
||||||
|
if(state->buttons & CONT_DPAD_UP) {
|
||||||
|
movement += 0.5f;
|
||||||
|
} else if(state->buttons & CONT_DPAD_DOWN) {
|
||||||
|
movement -= 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(state->buttons & CONT_DPAD_LEFT) {
|
||||||
|
rotation += 0.5f;
|
||||||
|
} else if(state->buttons & CONT_DPAD_RIGHT) {
|
||||||
|
rotation -= 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* The main drawing function. */
|
/* The main drawing function. */
|
||||||
void DrawGLScene()
|
void DrawGLScene()
|
||||||
{
|
{
|
||||||
static GLfloat movement = 0.0f;
|
|
||||||
static GLfloat rotation = 0.0f;
|
|
||||||
static GLboolean increasing = GL_TRUE;
|
|
||||||
|
|
||||||
if(movement > 10.0) {
|
|
||||||
increasing = GL_FALSE;
|
|
||||||
} else if(movement < -10.0f) {
|
|
||||||
increasing = GL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(increasing) {
|
|
||||||
movement += 0.05f;
|
|
||||||
} else {
|
|
||||||
movement -= 0.05f;
|
|
||||||
}
|
|
||||||
|
|
||||||
rotation += 0.1f;
|
|
||||||
if(rotation > 360.0f) {
|
|
||||||
rotation -= 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
||||||
glLoadIdentity(); // Reset The View
|
glLoadIdentity(); // Reset The View
|
||||||
|
|
||||||
@ -95,24 +103,58 @@ void DrawGLScene()
|
|||||||
glTranslatef(0.0f, -1.0f, movement);
|
glTranslatef(0.0f, -1.0f, movement);
|
||||||
glRotatef(rotation, 0.0f, 1.0, 0.0f);
|
glRotatef(rotation, 0.0f, 1.0, 0.0f);
|
||||||
|
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
/* We create a horseshoe shape tri-strip here because that allows for situations where a strip
|
||||||
glColor3f(1.0f, 1.0f, 0.0f);
|
leaves and re-enters the viewport */
|
||||||
glVertex3f(-2.5f, 0.0f, 5.0f);
|
|
||||||
|
|
||||||
glColor3f(1.0f, 0.0f, 0.0f);
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
glVertex3f(2.5f, 0.0f, 5.0f);
|
// Left side
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-2.0f, 0.0f, 5.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, 0.0f, 5.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-2.0f, 0.0f, 3.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, 0.0f, 3.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-2.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Curve
|
||||||
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
glColor3f(0.0f, 1.0f, 0.0f);
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
glVertex3f(-2.5f, 0.0f, -5.0f);
|
glVertex3f(1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
glColor3f(0.0f, 0.0f, 1.0f);
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
glVertex3f(2.5f, 0.0f, -5.0f);
|
glVertex3f(1.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
glColor3f(0.0f, 1.0f, 1.0f);
|
// Right side
|
||||||
glVertex3f(-2.5f, 0.0f, -10.0f);
|
// Degenerate to reverse ordering
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(2.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
glColor3f(1.0f, 0.0f, 1.0f);
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
glVertex3f(2.5f, 0.0f, -10.0f);
|
glVertex3f(1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(1.0f, 0.0f, 3.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(2.0f, 0.0f, 3.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(1.0f, 0.0f, 5.0f);
|
||||||
|
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(2.0f, 0.0f, 5.0f);
|
||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
@ -131,6 +173,8 @@ int main(int argc, char **argv)
|
|||||||
if(check_start())
|
if(check_start())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
update_movement();
|
||||||
|
|
||||||
DrawGLScene();
|
DrawGLScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user