ref: 03f5d05b72f0c07308b2eab32c0c904f63af5799
parent: 80ca2e40a207c0178f76eb7d7c35b325d87a484c
author: David <gek@katherine>
date: Sun Feb 21 08:31:12 EST 2021
Improvements to compliance and bug fixes
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -26,6 +26,7 @@
#include <SDL/SDL.h>
int noSDL = 0;
+#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
@@ -216,11 +217,12 @@
unsigned int frames = 0;
unsigned int tNow = SDL_GetTicks();
unsigned int tLastFps = tNow;
-
+ unsigned int frames_notreset = 0;
// main loop:
int isRunning = 1;
while (isRunning) {
++frames;
+ frames_notreset++;
tNow = SDL_GetTicks();
// do event handling:
SDL_Event evt;
@@ -246,7 +248,7 @@
draw();
glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x000000FF);
glPixelZoom(0.5,1);
- glRasterPos2f(-1,-1);
+ glRasterPos3f(-1,-1,fabs(sinf(frames_notreset/200.0)));
{
GLint xsize, ysize;
void* data = glGetTexturePixmap(tex, 0, &xsize, &ysize);
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -12,7 +12,6 @@
#define ZB_Z_BITS 16
#define ZB_POINT_Z_FRAC_BITS 14
-
//a "1" in bit FRAC_BITS+1 (starting at zero) = 1.
#define ZB_POINT_S_MIN ( (1<<ZB_POINT_S_FRAC_BITS) )
--- a/src/clip.c
+++ b/src/clip.c
@@ -69,9 +69,6 @@
for(int i = 0; i < 3; i++)
q->color.v[i] = p0->color.v[i] + (p1->color.v[i] - p0->color.v[i]) * t;
-// q->color.v[0] = p0->color.v[0] + (p1->color.v[0] - p0->color.v[0]) * t;
-// q->color.v[1] = p0->color.v[1] + (p1->color.v[1] - p0->color.v[1]) * t;
-// q->color.v[2] = p0->color.v[2] + (p1->color.v[2] - p0->color.v[2]) * t;
}
/*
--- a/src/init.c
+++ b/src/init.c
@@ -241,6 +241,12 @@
c->select_buffer = NULL;
c->name_stack_size = 0;
+ /* feedback */
+ c->feedback_buffer = NULL;
+ c->feedback_ptr = NULL;
+ c->feedback_size = 0;
+ c->feedback_hits = 0;
+ c->feedback_overflow = 0;
/* matrix */
c->matrix_mode = 0;
--- a/src/select.c
+++ b/src/select.c
@@ -18,6 +18,15 @@
c->select_ptr = c->select_buffer;
c->name_stack_size = 0;
break;
+ case GL_FEEDBACK:
+ if(c->feedback_overflow)
+ result = -c->feedback_hits;
+ else
+ result = c->feedback_hits;
+ c->feedback_overflow = 0;
+ c->feedback_hits = 0;
+ c->feedback_ptr = c->feedback_buffer;
+ break;
default:
assert(0);
}
@@ -33,6 +42,11 @@
c->select_overflow = 0;
c->select_hit = NULL;
break;
+ case GL_FEEDBACK:
+ c->render_mode = GL_FEEDBACK;
+ c->feedback_hits = 0;
+ c->feedback_ptr = c->feedback_buffer;
+ break;
default:
assert(0);
}
@@ -41,9 +55,13 @@
void glSelectBuffer(GLint size, GLuint* buf) {
GLContext* c = gl_get_context();
-
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if(c->render_mode == GL_SELECT)
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
assert(c->render_mode != GL_SELECT);
-
+#endif
c->select_buffer = buf;
c->select_size = size;
}
@@ -86,7 +104,7 @@
if (!c->select_overflow) {
if (c->select_hit == NULL) {
n = c->name_stack_size;
- if ((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) {
+ if ((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) { //Detect overflows
c->select_overflow = 1;
} else {
ptr = c->select_ptr;
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -231,6 +231,14 @@
GLint select_overflow;
GLint select_hits;
+ /* feedback */
+ //render_mode as seen above
+ GLfloat* feedback_buffer;
+ GLfloat* feedback_ptr;
+ GLuint feedback_size;
+ GLint feedback_hits;
+ GLubyte feedback_overflow;
+
/* names */
GLuint name_stack[MAX_NAME_STACK_DEPTH];
GLint name_stack_size;
@@ -290,6 +298,7 @@
/* raster position */
V3 rasterpos;
+ GLint rasterpos_zz;
GLubyte rasterposvalid;
GLfloat pzoomx, pzoomy;
--- a/src/zline.c
+++ b/src/zline.c
@@ -14,11 +14,12 @@
GLubyte zbdt = zb->depth_test;
GLfloat zbps = zb->pointsize;
TGL_BLEND_VARS
+ zz = p->z >> ZB_POINT_Z_FRAC_BITS;
// PIXEL col;
if(zbps == 1){
pz = zb->zbuf + (p->y * zb->xsize + p->x);
pp = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * p->y + p->x * PSZB);
- zz = p->z >> ZB_POINT_Z_FRAC_BITS;
+
if (ZCMP(zz, *pz)) {
if(!zb->enable_blend)
*pp = RGB_TO_PIXEL(p->r, p->g, p->b);
@@ -41,7 +42,7 @@
{
pz = zb->zbuf + (y * zb->xsize + x);
pp = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * y + x * PSZB);
- zz = p->z >> ZB_POINT_Z_FRAC_BITS;
+ //zz = p->z >> ZB_POINT_Z_FRAC_BITS;
if (ZCMP(zz, *pz)) {
if(!zb->enable_blend)
*pp = col;
--- a/src/zraster.c
+++ b/src/zraster.c
@@ -40,7 +40,7 @@
v.coord.Z = p[3].f;
v.coord.W = p[4].f;
gl_vertex_transform_raster(c, &v);
-// if (v.clip_code == 0)
+ if (v.clip_code == 0)
{
{
GLfloat winv = 1.0 / v.pc.W;
@@ -47,14 +47,16 @@
v.zp.x = (GLint)(v.pc.X * winv * c->viewport.scale.X + c->viewport.trans.X);
v.zp.y = (GLint)(v.pc.Y * winv * c->viewport.scale.Y + c->viewport.trans.Y);
v.zp.z = (GLint)(v.pc.Z * winv * c->viewport.scale.Z + c->viewport.trans.Z);
+
}
c->rasterpos.v[0] = v.zp.x;
c->rasterpos.v[1] = v.zp.y;
- c->rasterpos.v[2] = v.zp.z;
+ //c->rasterpos.v[2] = v.zp.z;
+ c->rasterpos_zz = v.zp.z >> ZB_POINT_Z_FRAC_BITS; //I believe this is it?
c->rasterposvalid = 1;
}
-// else
-// c->rasterposvalid = 0;
+ else
+ c->rasterposvalid = 0;
}
void glRasterPos2f(GLfloat x, GLfloat y){glRasterPos4f(x,y,0,1);}
@@ -95,6 +97,7 @@
p[3].p = data;
gl_add_op(p);
}
+#define ZCMP(z, zpix) (!(zbdt) || z >= (zpix))
#define CLIPTEST(_x,_y,_w,_h)((0<=_x) && (_w>_x) && (0<=_y) && (_h>_y))
void glopDrawPixels(GLContext* c, GLParam* p){
// p[3]
@@ -102,16 +105,30 @@
GLint w = p[1].i;
GLint h = p[2].i;
V3 rastpos = c->rasterpos;
+ ZBuffer* zb = c->zb;
PIXEL* d = p[3].p;
- PIXEL* pbuf = c->zb->pbuf;
- GLint tw = c->zb->xsize;
- GLint th = c->zb->ysize;
+ PIXEL* pbuf = zb->pbuf;
+ GLushort* zbuf = zb->zbuf;
+ GLushort* pz;
+ GLubyte zbdw = zb->depth_write;
+ GLubyte zbdt = zb->depth_test;
+ GLint tw = zb->xsize;
+ GLint th = zb->ysize;
GLfloat pzoomx = c->pzoomx;
GLfloat pzoomy = c->pzoomy;
V4 rastoffset;
rastoffset.v[0] = rastpos.v[0];
rastoffset.v[1] = rastpos.v[1];
+ GLint zz = c->rasterpos_zz;
+ TGL_BLEND_VARS
//Looping over the source pixels.
+ if(c->render_mode == GL_SELECT){
+ gl_add_select(c, 0, 0);
+ return;
+ } else if(c->render_mode == GL_FEEDBACK){
+ //TODO
+ return;
+ }
for(GLint sx = 0; sx < w; sx++)
for(GLint sy = 0; sy < h; sy++)
{
@@ -122,8 +139,21 @@
rastoffset.v[3] = rastoffset.v[1] - pzoomy;
for(GLint tx = rastoffset.v[0]; (GLfloat)tx < rastoffset.v[2];tx++)
for(GLint ty = rastoffset.v[1]; (GLfloat)ty > rastoffset.v[3];ty--)
- if(CLIPTEST(tx,ty,tw,th))
- pbuf[tx+ty*tw] = col;
+ if(CLIPTEST(tx,ty,tw,th)){
+ pz = zbuf + (ty * tw + tx);
+
+ if(ZCMP(zz,*pz)){
+#if TGL_FEATURE_BLEND == 1
+ if(!zb->enable_blend)
+ pbuf[tx+ty*tw] = col;
+ else
+ TGL_BLEND_FUNC(col, pbuf[tx+ty*tw])
+#else
+ pbuf[tx+ty*tw] = col;
+#endif
+ if(zbdw) *pz = zz;
+ }
+ }
}
/*GLint mult = textsize;
for (GLint i = 0; i < mult; i++)