-/* $Id: osmesa.c,v 1.7 2000/01/06 09:28:38 brianp Exp $ */
+/* $Id: osmesa.c,v 1.8 2000/01/14 04:55:44 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#endif
+/*
+ * This is the OS/Mesa context struct.
+ * Notice how it includes a GLcontext. By doing this we're mimicking
+ * C++ inheritance/derivation.
+ * Later, we can cast a GLcontext pointer into an OSMesaContext pointer
+ * or vice versa.
+ */
struct osmesa_context {
- GLcontext *gl_ctx; /* The core GL/Mesa context */
+ GLcontext gl_ctx; /* The core GL/Mesa context */
GLvisual *gl_visual; /* Describes the buffers */
GLframebuffer *gl_buffer; /* Depth, stencil, accum, etc buffers */
GLenum format; /* either GL_RGBA or GL_COLOR_INDEX */
return NULL;
}
- osmesa->gl_ctx = gl_create_context( osmesa->gl_visual,
- sharelist ? sharelist->gl_ctx : (GLcontext *) NULL,
- (void *) osmesa, GL_TRUE );
- if (!osmesa->gl_ctx) {
+ if (!gl_initialize_context_data(&osmesa->gl_ctx,
+ osmesa->gl_visual,
+ sharelist ? &sharelist->gl_ctx
+ : (GLcontext *) NULL,
+ (void *) osmesa, GL_TRUE )) {
gl_destroy_visual( osmesa->gl_visual );
FREE(osmesa);
return NULL;
}
+
+
osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual,
osmesa->gl_visual->DepthBits > 0,
osmesa->gl_visual->StencilBits > 0,
if (!osmesa->gl_buffer) {
gl_destroy_visual( osmesa->gl_visual );
- gl_destroy_context( osmesa->gl_ctx );
+ gl_free_context_data( &osmesa->gl_ctx );
FREE(osmesa);
return NULL;
}
if (ctx) {
gl_destroy_visual( ctx->gl_visual );
gl_destroy_framebuffer( ctx->gl_buffer );
- gl_destroy_context( ctx->gl_ctx );
+ gl_free_context_data( &ctx->gl_ctx );
FREE( ctx );
}
}
return GL_FALSE;
}
- osmesa_update_state( ctx->gl_ctx );
- gl_make_current( ctx->gl_ctx, ctx->gl_buffer );
+ osmesa_update_state( &ctx->gl_ctx );
+ gl_make_current( &ctx->gl_ctx, ctx->gl_buffer );
ctx->buffer = buffer;
ctx->width = width;
compute_row_addresses( ctx );
/* init viewport */
- if (ctx->gl_ctx->Viewport.Width==0) {
+ if (ctx->gl_ctx.Viewport.Width==0) {
/* initialize viewport and scissor box to buffer size */
_mesa_Viewport( 0, 0, width, height );
- ctx->gl_ctx->Scissor.Width = width;
- ctx->gl_ctx->Scissor.Height = height;
+ ctx->gl_ctx.Scissor.Width = width;
+ ctx->gl_ctx.Scissor.Height = height;
}
return GL_TRUE;
{
GLcontext *ctx = gl_get_current_context();
if (ctx)
- return (OSMesaContext) ctx->DriverCtx;
+ return (OSMesaContext) ctx;
else
return NULL;
}
switch (pname) {
case OSMESA_ROW_LENGTH:
if (value<0) {
- gl_error( ctx->gl_ctx, GL_INVALID_VALUE,
+ gl_error( &ctx->gl_ctx, GL_INVALID_VALUE,
"OSMesaPixelStore(value)" );
return;
}
ctx->yup = value ? GL_TRUE : GL_FALSE;
break;
default:
- gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" );
+ gl_error( &ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaPixelStore(pname)" );
return;
}
*value = ctx->yup;
return;
default:
- gl_error( ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)" );
+ gl_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)");
return;
}
}
static void clear_index( GLcontext *ctx, GLuint index )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
osmesa->clearpixel = index;
}
static void clear_color( GLcontext *ctx,
GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
osmesa->clearpixel = PACK_RGBA( r, g, b, a );
}
static GLbitfield clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
GLint x, GLint y, GLint width, GLint height )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask;
/* we can't handle color or index masking */
static void set_index( GLcontext *ctx, GLuint index )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
osmesa->pixel = index;
}
static void set_color( GLcontext *ctx,
GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
osmesa->pixel = PACK_RGBA( r, g, b, a );
}
static void buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
*width = osmesa->width;
*height = osmesa->height;
}
GLuint n, GLint x, GLint y,
CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4( x, y );
GLuint i;
GLint rshift = osmesa->rshift;
CONST GLubyte rgba[][4],
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4( x, y );
const GLuint *rgba4 = (const GLuint *) rgba;
GLuint i;
GLuint n, GLint x, GLint y,
CONST GLubyte rgb[][3], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4( x, y );
GLuint i;
GLint rshift = osmesa->rshift;
GLuint n, GLint x, GLint y,
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4(x,y);
GLuint i;
for (i=0;i<n;i++,ptr4++) {
GLuint n, const GLint x[], const GLint y[],
CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLint rshift = osmesa->rshift;
GLint gshift = osmesa->gshift;
GLuint n, const GLint x[], const GLint y[],
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
static void read_rgba_span( const GLcontext *ctx, GLuint n, GLint x, GLint y,
GLubyte rgba[][4] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLuint *ptr4 = PIXELADDR4(x,y);
for (i=0;i<n;i++) {
GLuint n, GLint x, GLint y,
GLubyte rgba[][4] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint *ptr4 = PIXELADDR4(x,y);
MEMCPY( rgba, ptr4, n * 4 * sizeof(GLubyte) );
}
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
GLuint n, GLint x, GLint y,
CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr3 = PIXELADDR3( x, y);
GLuint i;
GLint rind = osmesa->rind;
GLuint n, GLint x, GLint y,
CONST GLubyte rgb[][3], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr3 = PIXELADDR3( x, y);
GLuint i;
GLint rind = osmesa->rind;
GLuint n, GLint x, GLint y,
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte rval = UNPACK_RED(osmesa->pixel);
GLubyte gval = UNPACK_GREEN(osmesa->pixel);
GLuint n, const GLint x[], const GLint y[],
CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLuint n, const GLint x[], const GLint y[],
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLuint n, GLint x, GLint y,
GLubyte rgba[][4] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLint rind = osmesa->rind;
GLint gind = osmesa->gind;
GLuint n, GLint x, GLint y,
const GLuint index[], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
if (mask) {
GLuint n, GLint x, GLint y,
const GLubyte index[], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
if (mask) {
GLuint n, GLint x, GLint y,
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *ptr1 = PIXELADDR1(x,y);
GLuint i;
for (i=0;i<n;i++,ptr1++) {
GLuint n, const GLint x[], const GLint y[],
const GLuint index[], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
GLuint n, const GLint x[], const GLint y[],
const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
static void read_index_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y, GLuint index[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
GLubyte *ptr1 = PIXELADDR1(x,y);
for (i=0;i<n;i++,ptr1++) {
GLuint n, const GLint x[], const GLint y[],
GLuint index[], const GLubyte mask[] )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLuint i;
for (i=0;i<n;i++) {
if (mask[i] ) {
static void flat_rgba_line( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *color = ctx->VB->ColorPtr->data[pvert];
unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] );
static void flat_rgba_z_line( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLubyte *color = ctx->VB->ColorPtr->data[pvert];
unsigned long pixel = PACK_RGBA( color[0], color[1], color[2], color[3] );
static void flat_blend_rgba_line( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
struct vertex_buffer *VB = ctx->VB;
GLint rshift = osmesa->rshift;
GLint gshift = osmesa->gshift;
static void flat_blend_rgba_z_line( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
struct vertex_buffer *VB = ctx->VB;
GLint rshift = osmesa->rshift;
GLint gshift = osmesa->gshift;
static void flat_blend_rgba_z_line_write( GLcontext *ctx,
GLuint vert0, GLuint vert1, GLuint pvert )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
struct vertex_buffer *VB = ctx->VB;
GLint rshift = osmesa->rshift;
GLint gshift = osmesa->gshift;
*/
static line_func choose_line_function( GLcontext *ctx )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
if (ctx->Line.SmoothFlag) return NULL;
if (ctx->Texture.Enabled) return NULL;
static void smooth_rgba_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
GLuint v2, GLuint pv )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
GLint rshift = osmesa->rshift;
GLint gshift = osmesa->gshift;
GLint bshift = osmesa->bshift;
static void flat_rgba_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
GLuint v2, GLuint pv )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
#define INTERP_Z 1
#define SETUP_CODE \
GLubyte r = VB->ColorPtr->data[pv][0]; \
*/
static triangle_func choose_triangle_function( GLcontext *ctx )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
if ((osmesa->format==OSMESA_RGB)||(osmesa->format==OSMESA_BGR)) return NULL;
static void osmesa_update_state( GLcontext *ctx )
{
- OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
+ OSMesaContext osmesa = (OSMesaContext) ctx;
+
+ ASSERT((void *) osmesa == (void *) ctx->DriverCtx);
ctx->Driver.GetString = get_string;
ctx->Driver.UpdateState = osmesa_update_state;