-/* $Id: gears.c,v 1.2 1999/10/21 16:39:06 brianp Exp $ */
+/* $Id: gears.c,v 1.3 2000/03/28 16:59:39 rjfrank Exp $ */
/*
* 3-D gear wheels. This program is in the public domain.
/*
* $Log: gears.c,v $
+ * Revision 1.3 2000/03/28 16:59:39 rjfrank
+ * Implemented support for the HP occlusion test extension (osmesa and X)
+ *
* Revision 1.2 1999/10/21 16:39:06 brianp
* added -info command line option
*
}
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
-static GLint gear1, gear2, gear3;
+static GLint gear1, gear2, gear3, gear3box;
static GLfloat angle = 0.0;
static void
draw(void)
{
+ GLboolean bRet = GL_TRUE;
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glPushMatrix();
glTranslatef(-3.1, 4.2, 0.0);
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
- glCallList(gear3);
+
+#ifdef GL_HP_occlusion_test
+ glDepthMask(GL_FALSE);
+ glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
+ glEnable(GL_OCCLUSION_TEST_HP);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
+ glCallList(gear3box);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
+ glDepthMask(GL_TRUE);
+ glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
+ glDisable(GL_OCCLUSION_TEST_HP);
+#endif
+
+ if (bRet) glCallList(gear3);
glPopMatrix();
glPopMatrix();
{0.0, 0.8, 0.2, 1.0};
static GLfloat blue[4] =
{0.2, 0.2, 1.0, 1.0};
+ static float cube[8][3] = {
+ {-2.35,-2.35,-0.5},
+ { 2.35,-2.35,-0.5},
+ { 2.35, 2.35,-0.5},
+ {-2.35, 2.35,-0.5},
+ {-2.35,-2.35, 0.5},
+ { 2.35,-2.35, 0.5},
+ { 2.35, 2.35, 0.5},
+ {-2.35, 2.35, 0.5},
+ };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
gear(1.3, 2.0, 0.5, 10, 0.7);
glEndList();
+ gear3box = glGenLists(1);
+ glNewList(gear3box, GL_COMPILE);
+ glDisable(GL_LIGHTING);
+ glBegin(GL_QUADS);
+ glVertex3fv(cube[3]); glVertex3fv(cube[2]);
+ glVertex3fv(cube[1]); glVertex3fv(cube[0]);
+ glVertex3fv(cube[4]); glVertex3fv(cube[5]);
+ glVertex3fv(cube[6]); glVertex3fv(cube[7]);
+ glVertex3fv(cube[0]); glVertex3fv(cube[1]);
+ glVertex3fv(cube[5]); glVertex3fv(cube[4]);
+ glVertex3fv(cube[1]); glVertex3fv(cube[2]);
+ glVertex3fv(cube[6]); glVertex3fv(cube[5]);
+ glVertex3fv(cube[2]); glVertex3fv(cube[3]);
+ glVertex3fv(cube[7]); glVertex3fv(cube[6]);
+ glVertex3fv(cube[3]); glVertex3fv(cube[0]);
+ glVertex3fv(cube[4]); glVertex3fv(cube[7]);
+ glEnd();
+ glEnable(GL_LIGHTING);
+ glEndList();
+
glEnable(GL_NORMALIZE);
if (argc > 1 && strcmp(argv[1], "-info")==0) {
-/* $Id: osdemo.c,v 1.3 2000/03/06 23:56:21 brianp Exp $ */
+/* $Id: osdemo.c,v 1.4 2000/03/28 16:59:39 rjfrank Exp $ */
/*
* Demo of off-screen Mesa rendering
glutSolidCone(1.0, 2.0, 16, 1);
glPopMatrix();
-#ifdef OSMESA_OCCLUSION_TEST_RESULT_HP
+#ifdef GL_HP_occlusion_test
{
GLboolean bRet;
- OSMesaGetBooleanv(OSMESA_OCCLUSION_TEST_RESULT_HP,&bRet);
glDepthMask(GL_FALSE);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
+ glEnable(GL_OCCLUSION_TEST_HP);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
glPushMatrix();
- glTranslatef(0.75, 0.0, -1.0);
+ glTranslatef(0.75, 0.0, -1.0);
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
glutSolidSphere(1.0, 20, 20);
glPopMatrix();
- OSMesaGetBooleanv(OSMESA_OCCLUSION_TEST_RESULT_HP,&bRet);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
printf("Occlusion test 1 (result should be 1): %d\n",bRet);
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
+ glDisable(GL_OCCLUSION_TEST_HP);
}
#endif
glutSolidSphere(1.0, 20, 20);
glPopMatrix();
-#ifdef OSMESA_OCCLUSION_TEST_RESULT_HP
+#ifdef GL_HP_occlusion_test
{
GLboolean bRet;
- OSMesaGetBooleanv(OSMESA_OCCLUSION_TEST_RESULT_HP,&bRet);
glDepthMask(GL_FALSE);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
+ glEnable(GL_OCCLUSION_TEST_HP);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
/* draw a sphere inside the previous sphere */
glPushMatrix();
- glTranslatef(0.75, 0.0, -1.0);
+ glTranslatef(0.75, 0.0, -1.0);
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
glutSolidSphere(0.5, 20, 20);
glPopMatrix();
- OSMesaGetBooleanv(OSMESA_OCCLUSION_TEST_RESULT_HP,&bRet);
+ glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP,&bRet);
printf("Occlusion test 2 (result should be 0): %d\n",bRet);
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
+ glDisable(GL_OCCLUSION_TEST_HP);
}
#endif
-/* $Id: osmesa.c,v 1.11 2000/03/17 15:32:29 brianp Exp $ */
+/* $Id: osmesa.c,v 1.12 2000/03/28 16:59:39 rjfrank Exp $ */
/*
* Mesa 3-D graphics library
#include "matrix.h"
#include "types.h"
#include "vb.h"
+#include "extensions.h"
#endif
void *rowaddr[MAX_HEIGHT]; /* address of first pixel in each image row */
GLboolean yup; /* TRUE -> Y increases upward */
/* FALSE -> Y increases downward */
- GLboolean bVisible; /* TRUE if geometry is visible */
};
FREE(osmesa);
return NULL;
}
-
+ gl_extensions_enable(&(osmesa->gl_ctx),"GL_HP_occlusion_test");
osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual,
osmesa->gl_visual->DepthBits > 0,
osmesa->rind = rind;
osmesa->gind = gind;
osmesa->bind = bind;
- osmesa->bVisible = GL_FALSE;
}
return osmesa;
}
}
}
-void GLAPIENTRY OSMesaGetBooleanv( GLint pname, GLboolean *value )
-{
- OSMesaContext ctx = OSMesaGetCurrentContext();
-
- switch (pname) {
- case OSMESA_OCCLUSION_TEST_RESULT_HP:
- *value = ctx->bVisible;
- ctx->bVisible = GL_FALSE;
- return;
- default:
- gl_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetBooleanv(pname)" );
- return;
- }
-}
-
/*
* Return the depth buffer associated with an OSMesa context.
* Input: c - the OSMesa context
}
}
-
-
+/*
+ * Return the color buffer associated with an OSMesa context.
+ * Input: c - the OSMesa context
+ * Output: width, height - size of buffer in pixels
+ * format - the pixel format (OSMESA_FORMAT)
+ * buffer - pointer to color buffer values
+ * Return: GL_TRUE or GL_FALSE to indicate success or failure.
+ */
+GLboolean GLAPIENTRY OSMesaGetColorBuffer( OSMesaContext c, GLint *width,
+ GLint *height, GLint *format, void **buffer )
+{
+ if (!c->buffer) {
+ *width = 0;
+ *height = 0;
+ *format = 0;
+ *buffer = 0;
+ return GL_FALSE;
+ } else {
+ *width = c->width;
+ *height = c->height;
+ *format = c->format;
+ *buffer = c->buffer;
+ return GL_TRUE;
+ }
+}
/**********************************************************************/
/*** Device Driver Functions ***/
GLint gshift = osmesa->gshift;
GLint bshift = osmesa->bshift;
GLint ashift = osmesa->ashift;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr4++) {
if (mask[i]) {
GLuint *ptr4 = PIXELADDR4( x, y );
const GLuint *rgba4 = (const GLuint *) rgba;
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++) {
if (mask[i]) {
GLint gshift = osmesa->gshift;
GLint bshift = osmesa->bshift;
GLint ashift = osmesa->ashift;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr4++) {
if (mask[i]) {
OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4(x,y);
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++,ptr4++) {
if (mask[i]) {
*ptr4 = osmesa->pixel;
GLint gshift = osmesa->gshift;
GLint bshift = osmesa->bshift;
GLint ashift = osmesa->ashift;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLuint *ptr4 = PIXELADDR4(x[i],y[i]);
{
OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLuint *ptr4 = PIXELADDR4(x[i],y[i]);
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLint bind = osmesa->bind;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr3+=3) {
if (mask[i]) {
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLint bind = osmesa->bind;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr3+=3) {
if (mask[i]) {
GLubyte *ptr3 = PIXELADDR3( x, y);
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++,ptr3+=3) {
if (mask[i]) {
ptr3[rind] = rval;
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLint bind = osmesa->bind;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLubyte *ptr3 = PIXELADDR3(x[i],y[i]);
GLubyte rval = UNPACK_RED(osmesa->pixel);
GLubyte gval = UNPACK_GREEN(osmesa->pixel);
GLubyte bval = UNPACK_BLUE(osmesa->pixel);
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLubyte *ptr3 = PIXELADDR3(x[i],y[i]);
OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr1++) {
if (mask[i]) {
OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
if (mask) {
for (i=0;i<n;i++,ptr1++) {
if (mask[i]) {
OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++,ptr1++) {
if (mask[i]) {
*ptr1 = (GLubyte) osmesa->pixel;
{
OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLubyte *ptr1 = PIXELADDR1(x[i],y[i]);
{
OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
for (i=0;i<n;i++) {
if (mask[i]) {
GLubyte *ptr1 = PIXELADDR1(x[i],y[i]);
OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *color = ctx->VB->ColorPtr->data[pvert];
unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] );
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_XY 1
#define CLIP_HACK 1
OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *color = ctx->VB->ColorPtr->data[pvert];
unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] );
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_XY 1
#define INTERP_Z 1
GLint rvalue = VB->ColorPtr->data[pvert][0]*avalue;
GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_XY 1
#define CLIP_HACK 1
GLint rvalue = VB->ColorPtr->data[pvert][0]*avalue;
GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_XY 1
#define INTERP_Z 1
GLint rvalue = VB->ColorPtr->data[pvert][0]*avalue;
GLint gvalue = VB->ColorPtr->data[pvert][1]*avalue;
GLint bvalue = VB->ColorPtr->data[pvert][2]*avalue;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_XY 1
#define INTERP_Z 1
GLint bshift = osmesa->bshift;
GLint ashift = osmesa->ashift;
(void) pv;
- osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
+
#define INTERP_Z 1
#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define INTERP_RGB 1
/**********************************************************************/
#define OCC_STD_MASK_TEST \
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; \
- if (osmesa->bVisible) return; \
+ if (ctx->OcclusionResult) return; \
if (mask) { \
GLuint i; \
for (i=0;i<n;i++) if (mask[i]) { \
- osmesa->bVisible = GL_TRUE; \
+ ((GLcontext *)ctx)->OcclusionResult = GL_TRUE; \
return; \
} \
} else { \
- osmesa->bVisible = GL_TRUE; \
+ ((GLcontext *)ctx)->OcclusionResult = GL_TRUE; \
} \
return;
static void line_occ( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
- osmesa->bVisible = GL_TRUE;
+ ctx->OcclusionResult = GL_TRUE;
}
static void line_z_occ( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
- if (osmesa->bVisible) return;
+ if (ctx->OcclusionResult) return;
#define INTERP_XY 1
#define INTERP_Z 1
#define CLIP_HACK 1
#define PLOT(X,Y) \
if (Z < *zPtr) { \
- osmesa->bVisible = GL_TRUE; \
+ ctx->OcclusionResult = GL_TRUE; \
return; \
}
static void triangle_occ( GLcontext *ctx, GLuint v0, GLuint v1,
GLuint v2, GLuint pv )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
- osmesa->bVisible = GL_TRUE;
+ ctx->OcclusionResult = GL_TRUE;
}
static void triangle_z_occ( GLcontext *ctx, GLuint v0, GLuint v1,
GLuint v2, GLuint pv )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
- if (osmesa->bVisible) return;
+ if (ctx->OcclusionResult) return;
+
#define INTERP_Z 1
#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define INNER_LOOP( LEFT, RIGHT, Y ) \
for (i=0;i<len;i++) { \
GLdepth z = FixedToDepth(ffz); \
if (z < zRow[i]) { \
- osmesa->bVisible = GL_TRUE; \
+ ctx->OcclusionResult = GL_TRUE; \
return; \
} \
ffz += fdzdx; \
* extension use will just cause unnecessary rasterization
* to occur. The image will be correct in any case.
*/
- if ((ctx->Color.IndexMask == 0) &&
+ if ((ctx->Depth.OcclusionTest) &&
+ (((!ctx->Visual->RGBAflag) &&
+ (ctx->Color.IndexMask == 0)) ||
+ ((ctx->Visual->RGBAflag) &&
(ctx->Color.ColorMask[0] == 0) &&
(ctx->Color.ColorMask[1] == 0) &&
(ctx->Color.ColorMask[2] == 0) &&
- (ctx->Color.ColorMask[3] == 0) &&
+ (ctx->Color.ColorMask[3] == 0))) &&
+ (ctx->Depth.Func == GL_LESS) &&
(ctx->Stencil.Enabled == GL_FALSE)) {
- /* XXX depth.func == GL_LESS ? */
-
ctx->Driver.WriteCI32Span = write_index32_span_occ;
ctx->Driver.WriteCI8Span = write_index8_span_occ;
ctx->Driver.WriteMonoCISpan = write_monoindex_span_occ;
ctx->Driver.LineFunc = line_occ;
ctx->Driver.TriangleFunc = triangle_occ;
}
+ } else {
+ ctx->OcclusionResult = GL_TRUE;
}
}