From 06d05afdd687fcd1d59d46c6a86c2e5707e1859b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 8 Dec 2000 00:20:15 +0000 Subject: [PATCH] Initial work on GL_MESA_sprite_point extension. Still need to resolve clipping issues, finalize the spec. --- src/mesa/main/context.c | 3 +- src/mesa/main/enable.c | 120 ++++++++++++++++++++++++++++--------- src/mesa/main/extensions.c | 4 +- src/mesa/main/get.c | 74 +++++++++++++++++++++-- src/mesa/main/mtypes.h | 6 +- src/mesa/main/points.c | 3 +- src/mesa/main/state.c | 9 ++- src/mesa/swrast/s_points.c | 113 +++++++++++++++++++++++++++++++++- 8 files changed, 291 insertions(+), 41 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 504de6e5874..ae3397c1480 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,4 +1,4 @@ -/* $Id: context.c,v 1.110 2000/11/27 18:22:13 brianp Exp $ */ +/* $Id: context.c,v 1.111 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1094,6 +1094,7 @@ init_attrib_groups( GLcontext *ctx ) ctx->Point.MinSize = 0.0; ctx->Point.MaxSize = ctx->Const.MaxPointSize; ctx->Point.Threshold = 1.0; + ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */ /* Polygon group */ ctx->Polygon.CullFlag = GL_FALSE; diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index 2de320d3868..bbc5070d758 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -1,4 +1,4 @@ -/* $Id: enable.c,v 1.35 2000/11/27 18:59:09 brianp Exp $ */ +/* $Id: enable.c,v 1.36 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -503,46 +503,90 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state ) /* GL_SGIS_pixel_texture */ case GL_PIXEL_TEXTURE_SGIS: - /* XXX check for extension */ - ctx->Pixel.PixelTextureEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.SGIS_pixel_texture) { + ctx->Pixel.PixelTextureEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" ); + return; + } break; /* GL_SGIX_pixel_texture */ case GL_PIXEL_TEX_GEN_SGIX: - /* XXX check for extension */ - ctx->Pixel.PixelTextureEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.SGIX_pixel_texture) { + ctx->Pixel.PixelTextureEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" ); + return; + } break; /* GL_SGI_color_table */ case GL_COLOR_TABLE_SGI: - /* XXX check for extension */ - ctx->Pixel.ColorTableEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.SGI_color_table) { + ctx->Pixel.ColorTableEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" ); + return; + } break; case GL_POST_CONVOLUTION_COLOR_TABLE_SGI: - ctx->Pixel.PostConvolutionColorTableEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.SGI_color_table) { + ctx->Pixel.PostConvolutionColorTableEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" ); + return; + } break; case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI: - ctx->Pixel.PostColorMatrixColorTableEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.SGI_color_table) { + ctx->Pixel.PostColorMatrixColorTableEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" ); + return; + } break; /* GL_EXT_convolution */ case GL_CONVOLUTION_1D: - /* XXX check for extension */ - ctx->Pixel.Convolution1DEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.EXT_convolution) { + ctx->Pixel.Convolution1DEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable"); + return; + } break; case GL_CONVOLUTION_2D: - ctx->Pixel.Convolution2DEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.EXT_convolution) { + ctx->Pixel.Convolution2DEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable"); + return; + } break; case GL_SEPARABLE_2D: - ctx->Pixel.Separable2DEnabled = state; - ctx->NewState |= _NEW_PIXEL; + if (ctx->Extensions.EXT_convolution) { + ctx->Pixel.Separable2DEnabled = state; + ctx->NewState |= _NEW_PIXEL; + } + else { + gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable"); + return; + } break; /* GL_ARB_texture_cube_map */ @@ -568,12 +612,30 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state ) /* GL_EXT_secondary_color */ case GL_COLOR_SUM_EXT: - ctx->Fog.ColorSumEnabled = state; - if (state) - SET_BITS(ctx->_TriangleCaps, DD_SEPERATE_SPECULAR); - else if (ctx->Light.Model.ColorControl == GL_SINGLE_COLOR) - CLEAR_BITS(ctx->_TriangleCaps, DD_SEPERATE_SPECULAR); - ctx->NewState |= _NEW_FOG; + if (ctx->Extensions.EXT_secondary_color) { + ctx->Fog.ColorSumEnabled = state; + if (state) + SET_BITS(ctx->_TriangleCaps, DD_SEPERATE_SPECULAR); + else if (ctx->Light.Model.ColorControl == GL_SINGLE_COLOR) + CLEAR_BITS(ctx->_TriangleCaps, DD_SEPERATE_SPECULAR); + ctx->NewState |= _NEW_FOG; + } + else { + gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable"); + return; + } + break; + + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + if (ctx->Extensions.MESA_sprite_point) { + ctx->Point.SpriteMode = state; + ctx->NewState |= _NEW_POINT; + } + else { + gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable"); + return; + } break; default: @@ -820,6 +882,10 @@ _mesa_IsEnabled( GLenum cap ) return GL_FALSE; } + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + return ctx->Point.SpriteMode; + default: gl_error( ctx, GL_INVALID_ENUM, "glIsEnabled" ); return GL_FALSE; diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 24a0f031a27..6c0645b84b8 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -1,4 +1,4 @@ -/* $Id: extensions.c,v 1.42 2000/11/22 07:32:16 joukj Exp $ */ +/* $Id: extensions.c,v 1.43 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -95,6 +95,7 @@ static struct { { ON, "GL_INGR_blend_func_separate", F(INGR_blend_func_separate) }, { ON, "GL_MESA_window_pos", F(MESA_window_pos) }, { ON, "GL_MESA_resize_buffers", F(MESA_resize_buffers) }, + { OFF, "GL_MESA_sprite_point", F(MESA_sprite_point) }, { OFF, "GL_NV_blend_square", F(NV_blend_square) }, { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) }, { ON, "GL_PGI_misc_hints", F(PGI_misc_hints) }, @@ -121,6 +122,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) gl_extensions_enable(ctx, "GL_EXT_texture_env_combine"); gl_extensions_enable(ctx, "GL_HP_occlusion_test"); gl_extensions_enable(ctx, "GL_NV_blend_square"); + gl_extensions_enable(ctx, "GL_MESA_sprite_point"); } diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 012290a44a5..72b8c7a460d 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -1,4 +1,4 @@ -/* $Id: get.c,v 1.44 2000/11/27 18:22:13 brianp Exp $ */ +/* $Id: get.c,v 1.45 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1274,6 +1274,17 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params ) *params = INT_TO_BOOL(ctx->Array.FogCoord.Stride); break; + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + if (ctx->Extensions.MESA_sprite_point) { + *params = ctx->Point.SpriteMode; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetBooleanv" ); + return; + } + break; + default: gl_error( ctx, GL_INVALID_ENUM, "glGetBooleanv" ); } @@ -2472,6 +2483,16 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params ) *params = (GLdouble) ctx->Array.FogCoord.Stride; break; + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + if (ctx->Extensions.MESA_sprite_point) { + *params = (GLdouble) ctx->Point.SpriteMode; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetDoublev" ); + return; + } + break; default: gl_error( ctx, GL_INVALID_ENUM, "glGetDoublev" ); @@ -3645,6 +3666,16 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params ) *params = (GLfloat) ctx->Array.FogCoord.Stride; break; + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + if (ctx->Extensions.MESA_sprite_point) { + *params = (GLfloat) ctx->Point.SpriteMode; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetFloatv" ); + return; + } + break; default: gl_error( ctx, GL_INVALID_ENUM, "glGetFloatv" ); @@ -4834,19 +4865,50 @@ _mesa_GetIntegerv( GLenum pname, GLint *params ) /* GL_EXT_fog_coord */ case GL_CURRENT_FOG_COORDINATE_EXT: - FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT ); - *params = (GLint) ctx->Current.FogCoord; + if (ctx->Extensions.EXT_fog_coord) { + FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT ); + *params = (GLint) ctx->Current.FogCoord; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); + } break; case GL_FOG_COORDINATE_ARRAY_EXT: - *params = (GLint) ctx->Array.FogCoord.Enabled; + if (ctx->Extensions.EXT_fog_coord) { + *params = (GLint) ctx->Array.FogCoord.Enabled; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); + } break; case GL_FOG_COORDINATE_ARRAY_TYPE_EXT: - *params = (GLint) ctx->Array.FogCoord.Type; + if (ctx->Extensions.EXT_fog_coord) { + *params = (GLint) ctx->Array.FogCoord.Type; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); + } break; case GL_FOG_COORDINATE_ARRAY_STRIDE_EXT: - *params = (GLint) ctx->Array.FogCoord.Stride; + if (ctx->Extensions.EXT_fog_coord) { + *params = (GLint) ctx->Array.FogCoord.Stride; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); + } break; + /* GL_MESA_sprite_point */ + case GL_SPRITE_POINT_MESA: + if (ctx->Extensions.MESA_sprite_point) { + *params = (GLint) ctx->Point.SpriteMode; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); + return; + } + break; + default: gl_error( ctx, GL_INVALID_ENUM, "glGetIntegerv" ); } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index ee1fecfb30e..72676708228 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,4 +1,4 @@ -/* $Id: mtypes.h,v 1.4 2000/11/28 00:07:51 brianp Exp $ */ +/* $Id: mtypes.h,v 1.5 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -602,6 +602,7 @@ struct gl_pixel_attrib { struct gl_point_attrib { GLboolean SmoothFlag; /* True if GL_POINT_SMOOTH is enabled */ + GLboolean SpriteMode; /* GL_MESA_sprite_point extension */ GLfloat Size; /* User-specified point size */ GLfloat _Size; /* Size clamped to Const.Min/MaxPointSize */ GLfloat Params[3]; /* GL_EXT_point_parameters */ @@ -816,7 +817,7 @@ struct gl_texture_object { */ struct gl_texture_unit { GLuint Enabled; /* bitmask of TEXTURE0_1D, _2D, _3D, _CUBE */ - GLuint _ReallyEnabled; /* 0 or one of TEXTURE0_1D, _2D, _3D, _CUBE */ + GLuint _ReallyEnabled; /* 0 or one of TEXTURE0_1D, _2D, _3D, _CUBE */ GLenum EnvMode; /* GL_MODULATE, GL_DECAL, GL_BLEND, etc. */ GLfloat EnvColor[4]; @@ -1214,6 +1215,7 @@ struct gl_extensions { GLboolean INGR_blend_func_separate; GLboolean MESA_window_pos; GLboolean MESA_resize_buffers; + GLboolean MESA_sprite_point; GLboolean NV_blend_square; GLboolean NV_texgen_reflection; GLboolean PGI_misc_hints; diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c index 8c84f279e0c..b70e5f05c47 100644 --- a/src/mesa/main/points.c +++ b/src/mesa/main/points.c @@ -1,4 +1,4 @@ -/* $Id: points.c,v 1.24 2000/11/22 07:32:17 joukj Exp $ */ +/* $Id: points.c,v 1.25 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -88,6 +88,7 @@ _mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params) if (tmp != ctx->Point._Attenuated) { ctx->_Enabled ^= ENABLE_POINT_ATTEN; ctx->_TriangleCaps ^= DD_POINT_ATTEN; + /* XXX why is this here and not in state.c? */ ctx->_NeedEyeCoords ^= NEED_EYE_POINT_ATTEN; } } diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 5c4dda99e8d..9ef01d4b54f 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -1,4 +1,4 @@ -/* $Id: state.c,v 1.50 2000/11/28 00:07:51 brianp Exp $ */ +/* $Id: state.c,v 1.51 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -781,6 +781,13 @@ void gl_update_state( GLcontext *ctx ) ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW; } + /* point attenuation requires eye coords */ + if (new_state & _NEW_POINT) { + if (ctx->Point._Attenuated) { + ctx->_NeedEyeCoords |= NEED_EYE_POINT_ATTEN; + } + } + /* ctx->_NeedEyeCoords and ctx->_NeedEyeNormals are now uptodate. * * If the truth value of either has changed, update for the new diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c index 6e7e7010b2b..58cf8e99468 100644 --- a/src/mesa/swrast/s_points.c +++ b/src/mesa/swrast/s_points.c @@ -1,4 +1,4 @@ -/* $Id: s_points.c,v 1.8 2000/12/08 00:18:39 brianp Exp $ */ +/* $Id: s_points.c,v 1.9 2000/12/08 00:20:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -838,6 +838,60 @@ dist_atten_antialiased_rgba_point( GLcontext *ctx, const SWvertex *vert ) } +/* + * Sprite (textured point) + */ +static void +sprite_point( GLcontext *ctx, const SWvertex *vert ) +{ + SWcontext *swctx = SWRAST_CONTEXT(ctx); + const GLfloat radius = vert->pointSize; /* XXX threshold, alpha */ + SWvertex v0, v1, v2, v3; + GLuint unit; + + /* lower left corner */ + v0 = *vert; + v0.win[0] -= radius; + v0.win[1] -= radius; + + /* lower right corner */ + v1 = *vert; + v1.win[0] += radius; + v1.win[1] -= radius; + + /* upper right corner */ + v2 = *vert; + v2.win[0] += radius; + v2.win[1] += radius; + + /* upper left corner */ + v3 = *vert; + v3.win[0] -= radius; + v3.win[1] += radius; + + for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { + if (ctx->Texture.Unit[unit]._ReallyEnabled) { + v0.texcoord[unit][0] = 0.0; + v0.texcoord[unit][1] = 0.0; + v1.texcoord[unit][0] = 1.0; + v1.texcoord[unit][1] = 0.0; + v2.texcoord[unit][0] = 1.0; + v2.texcoord[unit][1] = 1.0; + v3.texcoord[unit][0] = 0.0; + v3.texcoord[unit][1] = 1.0; + } + } + + /* XXX if radius < threshold, attenuate alpha? */ + /* XXX what about clipping? */ + + /* render */ + swctx->Triangle(ctx, &v0, &v1, &v2); + swctx->Triangle(ctx, &v0, &v2, &v3); +} + + + #ifdef DEBUG extern void @@ -889,7 +943,11 @@ _swrast_choose_point( GLcontext *ctx ) GLboolean rgbmode = ctx->Visual.RGBAflag; if (ctx->RenderMode==GL_RENDER) { - if (!ctx->Point._Attenuated) { + if (ctx->Point.SpriteMode) { + /* XXX this is hacked in! */ + swrast->Point = sprite_point; + } + else if (!ctx->Point._Attenuated) { if (ctx->Point.SmoothFlag && rgbmode) { swrast->Point = antialiased_rgba_point; } @@ -943,3 +1001,54 @@ _swrast_choose_point( GLcontext *ctx ) /*_mesa_print_points_function(ctx);*/ } + + +#if 000 /* prototype of new point code */ + +#define RGBA 0x1 +#define SMOOTH 0x2 +#define LARGE 0x4 +#define TEXTURE 0x8 +#define ATTENUATE 0x10 +#define SPRITE 0x20 + +#define FLAGS (RGBA | SMOOTH | LARGE) +#define NAME rgba_smooth_large +#include "s_pointtemp.h" + +#define FLAGS (RGBA | TEXTURE | ATTENUATE) +#define NAME rgba_texture_smooth_attenuate +#include "s_pointtemp.h" + +#define FLAGS (INDEX | LARGE | ATTENUATE) +#define NAME index_large_attenuate +#include "s_pointtemp.h" + + +static void* point_tab[0x20]; + +void +_swrast_choose_point( GLcontext *ctx ) +{ + GLuint index = 0; + + if (ctx->RenderMode==GL_RENDER) { + if (ctx->Visual.RGBAflag) + index |= RGBA; + if (ctx->Point.SmoothFlag) + index |= SMOOTH; + if (ctx->Point._Attenuated || ctx->Point.Size > 1.0) + index |= SIZED; + if (ctx->Texture.ReallyEnabled) + index |= TEXTURE; + swrast->Point = point_tab[index]; + } + else if (ctx->RenderMode==GL_FEEDBACK) { + swrast->Point = gl_feedback_point; + } + else { + /* GL_SELECT mode */ + swrast->Point = gl_select_point; + } +} +#endif -- 2.30.2