From d09f4e2007b3043ceb9dd3cb9cfab0dcd0226ba6 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 2 Aug 2007 14:20:40 -0600 Subject: initial work for textured-quad glDrawPixels --- src/mesa/state_tracker/st_cb_drawpixels.h | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/mesa/state_tracker/st_cb_drawpixels.h (limited to 'src/mesa/state_tracker/st_cb_drawpixels.h') diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h new file mode 100644 index 0000000000..8c36aaa931 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef ST_CB_DRAWPIXELS_H +#define ST_CB_DRAWPIXELS_H + + +void st_init_cb_drawpixels( struct st_context *st ); + +void st_destroy_cb_drawpixels( struct st_context *st ); + + +#endif /* ST_CB_DRAWPIXELS_H */ -- cgit v1.2.3 From 6da9234fd437f97267e7831f034c78b31156d939 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 6 Aug 2007 20:53:28 +0100 Subject: New st_init_*_functions() to initialize the driver functions table. We need to do these initializations before initializing the Mesa context because context init involves creating texture/program/etc objects. --- src/mesa/state_tracker/st_cb_bufferobjects.c | 18 ++++++++--------- src/mesa/state_tracker/st_cb_bufferobjects.h | 11 +++++------ src/mesa/state_tracker/st_cb_clear.c | 10 +--------- src/mesa/state_tracker/st_cb_clear.h | 5 +++-- src/mesa/state_tracker/st_cb_drawpixels.c | 8 +------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 +--- src/mesa/state_tracker/st_cb_fbo.c | 9 +-------- src/mesa/state_tracker/st_cb_fbo.h | 5 ++--- src/mesa/state_tracker/st_cb_program.c | 29 ++++++++++------------------ src/mesa/state_tracker/st_cb_texture.c | 12 +++--------- src/mesa/state_tracker/st_cb_texture.h | 6 +----- src/mesa/state_tracker/st_context.c | 18 +++++++++++++++++ src/mesa/state_tracker/st_context.h | 7 +++---- src/mesa/state_tracker/st_program.h | 5 +++-- 14 files changed, 60 insertions(+), 87 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_drawpixels.h') diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a667b3e775..d020eb2007 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -192,15 +192,13 @@ st_bufferobj_unmap(GLcontext *ctx, void -st_init_cb_bufferobjects( struct st_context *st ) +st_init_bufferobject_functions(struct dd_function_table *functions) { - GLcontext *ctx = st->ctx; - - ctx->Driver.NewBufferObject = st_bufferobj_alloc; - ctx->Driver.DeleteBuffer = st_bufferobj_free; - ctx->Driver.BufferData = st_bufferobj_data; - ctx->Driver.BufferSubData = st_bufferobj_subdata; - ctx->Driver.GetBufferSubData = st_bufferobj_get_subdata; - ctx->Driver.MapBuffer = st_bufferobj_map; - ctx->Driver.UnmapBuffer = st_bufferobj_unmap; + functions->NewBufferObject = st_bufferobj_alloc; + functions->DeleteBuffer = st_bufferobj_free; + functions->BufferData = st_bufferobj_data; + functions->BufferSubData = st_bufferobj_subdata; + functions->GetBufferSubData = st_bufferobj_get_subdata; + functions->MapBuffer = st_bufferobj_map; + functions->UnmapBuffer = st_bufferobj_unmap; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index 2787411c5f..2090a743e0 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.h +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -1,4 +1,4 @@ - /************************************************************************** +/************************************************************************** * * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. @@ -43,11 +43,6 @@ struct st_buffer_object }; -/* Hook the bufferobject implementation into mesa: - */ -void st_init_cb_bufferobjects( struct st_context *st ); - - /* Are the obj->Name tests necessary? Unfortunately yes, mesa * allocates a couple of gl_buffer_object structs statically, and the * Name == 0 test is the only way to identify them and avoid casting @@ -63,4 +58,8 @@ st_buffer_object(struct gl_buffer_object *obj) } +extern void +st_init_bufferobject_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c907b0ed22..0ec7784d84 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -418,15 +418,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) } -void st_init_cb_clear( struct st_context *st ) +void st_init_clear_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->Clear = st_clear; } - - -void st_destroy_cb_clear( struct st_context *st ) -{ -} - diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index 32086971b5..c715e56bd5 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -29,9 +29,10 @@ #ifndef ST_CB_CLEAR_H #define ST_CB_CLEAR_H -extern void st_init_cb_clear( struct st_context *st ); -extern void st_destroy_cb_clear( struct st_context *st ); +extern void +st_init_clear_functions(struct dd_function_table *functions); + #endif /* ST_CB_CLEAR_H */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 13f5c5f3c7..92a4e305d1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -262,14 +262,8 @@ st_drawpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } -void st_init_cb_drawpixels( struct st_context *st ) +void st_init_drawpixels_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->DrawPixels = st_drawpixels; } - -void st_destroy_cb_drawpixels( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 8c36aaa931..71ba487020 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,9 +30,7 @@ #define ST_CB_DRAWPIXELS_H -void st_init_cb_drawpixels( struct st_context *st ); - -void st_destroy_cb_drawpixels( struct st_context *st ); +extern void st_init_drawpixels_functions(struct dd_function_table *functions); #endif /* ST_CB_DRAWPIXELS_H */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6b9ae88dbe..d0205fd635 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -322,10 +322,8 @@ st_finish_render_texture(GLcontext *ctx, -void st_init_cb_fbo( struct st_context *st ) +void st_init_fbo_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->NewFramebuffer = st_new_framebuffer; functions->NewRenderbuffer = st_new_renderbuffer; functions->BindFramebuffer = st_bind_framebuffer; @@ -336,8 +334,3 @@ void st_init_cb_fbo( struct st_context *st ) functions->ResizeBuffers = st_resize_buffers; */ } - - -void st_destroy_cb_fbo( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index f4fa66df59..6142434ec6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,9 +30,8 @@ #define ST_CB_FBO_H -extern void st_init_cb_fbo( struct st_context *st ); - -extern void st_destroy_cb_fbo( struct st_context *st ); +extern void +st_init_fbo_functions(struct dd_function_table *functions); #endif /* ST_CB_FBO_H */ diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 6da2aeb2f2..ed47c12066 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -32,7 +32,6 @@ #include "st_context.h" #include "st_program.h" - #include "glheader.h" #include "macros.h" #include "enums.h" @@ -44,6 +43,11 @@ #include "pipe/tgsi/mesa/tgsi_mesa.h" +/* Counter to track program string changes: + */ +static GLuint program_id = 0; + + static void st_bind_program( GLcontext *ctx, GLenum target, struct gl_program *prog ) @@ -70,7 +74,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_VERTEX_PROGRAM_ARB: { struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_vertex_program( ctx, @@ -84,7 +88,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_fragment_program( ctx, @@ -124,7 +128,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->FragmentProgram._Current->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { @@ -133,7 +137,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->VertexProgram._Current->Base) st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: @@ -144,15 +148,8 @@ static void st_program_string_notify( GLcontext *ctx, -void st_init_cb_program( struct st_context *st ) +void st_init_program_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - - /* Need these flags: - */ - st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; - #if 0 assert(functions->ProgramStringNotify == _tnl_program_string); #endif @@ -162,9 +159,3 @@ void st_init_cb_program( struct st_context *st ) functions->IsProgramNative = st_is_program_native; functions->ProgramStringNotify = st_program_string_notify; } - - -void st_destroy_cb_program( struct st_context *st ) -{ -} - diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index a0245b553f..5872ae3e74 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1241,7 +1241,7 @@ do_copy_texsubimage(GLcontext *ctx, get_teximage_source(ctx, internalFormat); if (!stImage->mt || !src) { - DBG("%s fail %p %p\n", __FUNCTION__, stImage->mt, src); + DBG("%s fail %p %p\n", __FUNCTION__, (void *) stImage->mt, (void *) src); return GL_FALSE; } @@ -1726,10 +1726,9 @@ st_tex_unmap_images(struct pipe_context *pipe, -void st_init_cb_texture( struct st_context *st ) +void +st_init_texture_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->ChooseTextureFormat = st_ChooseTextureFormat; functions->TexImage1D = st_TexImage1D; functions->TexImage2D = st_TexImage2D; @@ -1756,8 +1755,3 @@ void st_init_cb_texture( struct st_context *st ) functions->TextureMemCpy = do_memcpy; } - - -void st_destroy_cb_texture( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index c474d16465..c732881c39 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -9,11 +9,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, extern void -st_init_cb_texture( struct st_context *st ); - - -extern void -st_destroy_cb_texture( struct st_context *st ); +st_init_texture_functions(struct dd_function_table *functions); #endif /* ST_CB_TEXTURE_H */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2b96286770..0ea06c692d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -28,6 +28,7 @@ #include "imports.h" #include "st_public.h" #include "st_context.h" +#include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" @@ -61,10 +62,17 @@ struct st_context *st_create_context( GLcontext *ctx, st_init_atoms( st ); st_init_draw( st ); + /* Need these flags: + */ + st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + +#if 0 st_init_cb_clear( st ); st_init_cb_program( st ); st_init_cb_drawpixels( st ); st_init_cb_texture( st ); +#endif return st; } @@ -75,11 +83,13 @@ void st_destroy_context( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); +#if 0 st_destroy_cb_clear( st ); st_destroy_cb_program( st ); st_destroy_cb_drawpixels( st ); /*st_destroy_cb_teximage( st );*/ st_destroy_cb_texture( st ); +#endif st->pipe->destroy( st->pipe ); FREE( st ); @@ -87,3 +97,11 @@ void st_destroy_context( struct st_context *st ) +void st_init_driver_functions(struct dd_function_table *functions) +{ + st_init_bufferobject_functions(functions); + st_init_clear_functions(functions); + st_init_drawpixels_functions(functions); + st_init_program_functions(functions); + st_init_texture_functions(functions); +} diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ef3cdb3b09..fe73630c75 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,10 +97,6 @@ struct st_context struct st_state_flags dirty; - /* Counter to track program string changes: - */ - GLuint program_id; - GLfloat polygon_offset_scale; /* ?? */ }; @@ -113,4 +109,7 @@ static INLINE struct st_context *st_context(GLcontext *ctx) } +extern void st_init_driver_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index f6d5f6d76c..8dcb2ceb48 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -87,8 +87,9 @@ struct st_vertex_program GLuint param_state; }; -void st_init_cb_program( struct st_context *st ); -void st_destroy_cb_program( struct st_context *st ); + +extern void st_init_program_functions(struct dd_function_table *functions); + static inline struct st_fragment_program * st_fragment_program( struct gl_fragment_program *fp ) -- cgit v1.2.3 From 0b64ee6960f9e099bc1a6ca6fa10720fee875b3a Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 8 Feb 2008 14:51:32 -0700 Subject: gallium: added inClipCoords param to st_draw_vertices() to indicate coord system of vertices Also, export st_make_passthrough_vertex_shader() from st_cb_drawpixels.c --- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 18 +++++++++--------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 ++++ src/mesa/state_tracker/st_draw.c | 21 ++++++++++++--------- src/mesa/state_tracker/st_draw.h | 3 ++- 5 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_drawpixels.h') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 0cd469c156..ab98b54bab 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -251,7 +251,7 @@ draw_quad(GLcontext *ctx, verts[i][1][3] = color[3]; } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 34d420fcff..07886e7982 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -355,8 +355,8 @@ make_fragment_shader_z(struct st_context *st) * Create a simple vertex shader that just passes through the * vertex position and texcoord (and optionally, color). */ -static struct st_vertex_program * -make_vertex_shader(struct st_context *st, GLboolean passColor) +struct st_vertex_program * +st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) { /* only make programs once and re-use */ static struct st_vertex_program *progs[2] = { NULL, NULL }; @@ -572,7 +572,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][1][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE); } @@ -625,7 +625,7 @@ draw_quad_colored(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[i][2][3] = 1.0; /*Q*/ } - st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3); + st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 3, GL_FALSE); } @@ -945,7 +945,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (format == GL_DEPTH_COMPONENT) { ps = st->state.framebuffer.zsbuf; stfp = make_fragment_shader_z(ctx->st); - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); color = ctx->Current.RasterColor; } else if (format == GL_STENCIL_INDEX) { @@ -956,7 +956,7 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, else { ps = st->state.framebuffer.cbufs[0]; stfp = combined_drawpix_fragment_program(ctx); - stvp = make_vertex_shader(ctx->st, GL_FALSE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE); color = NULL; } @@ -1111,7 +1111,7 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_context *st = ctx->st; struct pipe_texture *pt; - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); @@ -1229,13 +1229,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, rbRead = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); color = NULL; stfp = combined_drawpix_fragment_program(ctx); - stvp = make_vertex_shader(ctx->st, GL_FALSE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE); } else { rbRead = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer); color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0]; stfp = make_fragment_shader_z(ctx->st); - stvp = make_vertex_shader(ctx->st, GL_TRUE); + stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); } psRead = rbRead->surface; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 71ba487020..b8b906f06b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,6 +30,10 @@ #define ST_CB_DRAWPIXELS_H +extern struct st_vertex_program * +st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor); + + extern void st_init_drawpixels_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index c9b8e78485..ae9f5c8b11 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -354,7 +354,8 @@ st_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs) + unsigned numAttribs, + GLboolean inClipCoords) { const float width = ctx->DrawBuffer->Width; const float height = ctx->DrawBuffer->Height; @@ -367,14 +368,16 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, assert(numAttribs > 0); - /* convert to clip coords */ - for (i = 0; i < numVertex; i++) { - float x = verts[i * numAttribs * 4 + 0]; - float y = verts[i * numAttribs * 4 + 1]; - x = x / width * 2.0 - 1.0; - y = y / height * 2.0 - 1.0; - verts[i * numAttribs * 4 + 0] = x; - verts[i * numAttribs * 4 + 1] = y; + if (!inClipCoords) { + /* convert to clip coords */ + for (i = 0; i < numVertex; i++) { + float x = verts[i * numAttribs * 4 + 0]; + float y = verts[i * numAttribs * 4 + 1]; + x = x / width * 2.0 - 1.0; + y = y / height * 2.0 - 1.0; + verts[i * numAttribs * 4 + 0] = x; + verts[i * numAttribs * 4 + 1] = y; + } } /* XXX create one-time */ diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h index 89ee790c57..171bde57e5 100644 --- a/src/mesa/state_tracker/st_draw.h +++ b/src/mesa/state_tracker/st_draw.h @@ -62,7 +62,8 @@ st_feedback_draw_vbo(GLcontext *ctx, void st_draw_vertices(GLcontext *ctx, unsigned prim, unsigned numVertex, float *verts, - unsigned numAttribs); + unsigned numAttribs, + GLboolean inClipCoords); #endif -- cgit v1.2.3 From f6cd3778c54c0329c3f497a7368a158087d653d3 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Mar 2008 14:50:17 -0600 Subject: gallium: glBitmap code now separe from glDraw/CopyPixels code Also, glBitmap now re-uses the vertex buffer to avoid frequent allocations/ deallocations. And, use u_simple_shaders utility code. --- src/mesa/sources | 1 + src/mesa/state_tracker/st_cb_drawpixels.c | 295 +----------------------------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 - src/mesa/state_tracker/st_context.c | 7 +- src/mesa/state_tracker/st_context.h | 3 + 5 files changed, 16 insertions(+), 294 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_drawpixels.h') diff --git a/src/mesa/sources b/src/mesa/sources index 287af7121a..d109dce5bc 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -172,6 +172,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_atom_texture.c \ state_tracker/st_atom_viewport.c \ state_tracker/st_cb_accum.c \ + state_tracker/st_cb_bitmap.c \ state_tracker/st_cb_blit.c \ state_tracker/st_cb_bufferobjects.c \ state_tracker/st_cb_clear.c \ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 99d5e3e848..b4cd93cd54 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,6 +56,7 @@ #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "util/p_tile.h" +#include "util/u_draw_quad.h" #include "shader/prog_instruction.h" #include "cso_cache/cso_context.h" @@ -85,140 +86,6 @@ is_passthrough_program(const struct gl_fragment_program *prog) } -/** - * Make fragment program for glBitmap: - * Sample the texture and kill the fragment if the bit is 0. - * This program will be combined with the user's fragment program. - */ -static struct st_fragment_program * -make_bitmap_fragment_program(GLcontext *ctx) -{ - struct st_fragment_program *stfp; - struct gl_program *p; - GLuint ic = 0; - - p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - if (!p) - return NULL; - - p->NumInstructions = 5; - - p->Instructions = _mesa_alloc_instructions(p->NumInstructions); - if (!p->Instructions) { - ctx->Driver.DeleteProgram(ctx, p); - return NULL; - } - _mesa_init_instructions(p->Instructions, p->NumInstructions); - - /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */ - p->Instructions[ic].Opcode = OPCODE_TEX; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; - p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; - p->Instructions[ic].TexSrcUnit = 0; - p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX; - ic++; - - /* SWZ tmp0.x, tmp0.x, 1111; # tmp0.x = 1.0 */ - p->Instructions[ic].Opcode = OPCODE_SWZ; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].DstReg.WriteMask = WRITEMASK_X; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - p->Instructions[ic].SrcReg[0].Swizzle - = MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE ); - ic++; - - /* SUB tmp0, tmp0.wwww, tmp0.xxxx; # tmp0.w -= 1 */ - p->Instructions[ic].Opcode = OPCODE_SUB; - p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; - p->Instructions[ic].DstReg.Index = 0; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_WWWW; - p->Instructions[ic].SrcReg[1].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[1].Index = 0; - p->Instructions[ic].SrcReg[1].Swizzle = SWIZZLE_XXXX; /* 1.0 */ - ic++; - - /* KIL if tmp0 < 0 */ - p->Instructions[ic].Opcode = OPCODE_KIL; - p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - p->Instructions[ic].SrcReg[0].Index = 0; - ic++; - - /* END; */ - p->Instructions[ic++].Opcode = OPCODE_END; - - assert(ic == p->NumInstructions); - - p->InputsRead = FRAG_BIT_TEX0; - p->OutputsWritten = 0x0; - - stfp = (struct st_fragment_program *) p; - stfp->Base.UsesKill = GL_TRUE; - st_translate_fragment_program(ctx->st, stfp, NULL); - - return stfp; -} - - -/** - * Combine basic bitmap fragment program with the user-defined program. - */ -static struct st_fragment_program * -combined_bitmap_fragment_program(GLcontext *ctx) -{ - struct st_context *st = ctx->st; - struct st_fragment_program *stfp; - - if (!st->bitmap.program) { - /* create the basic bitmap fragment program */ - st->bitmap.program = make_bitmap_fragment_program(ctx); - } - - if (st->bitmap.user_prog_sn == st->fp->serialNo) { - /* re-use */ - stfp = st->bitmap.combined_prog; - } - else { - /* Concatenate the bitmap program with the current user-defined program. - */ - stfp = (struct st_fragment_program *) - _mesa_combine_programs(ctx, - &st->bitmap.program->Base.Base, - &st->fp->Base.Base); - -#if 0 - { - struct gl_program *p = &stfp->Base.Base; - printf("Combined bitmap program:\n"); - _mesa_print_program(p); - printf("InputsRead: 0x%x\n", p->InputsRead); - printf("OutputsWritten: 0x%x\n", p->OutputsWritten); - _mesa_print_parameter_list(p->Parameters); - } -#endif - - /* translate to TGSI tokens */ - st_translate_fragment_program(st, stfp, NULL); - - /* save new program, update serial numbers */ - st->bitmap.user_prog_sn = st->fp->serialNo; - st->bitmap.combined_prog = stfp; - } - - /* Ideally we'd have updated the pipe constants during the normal - * st/atom mechanism. But we can't since this is specific to glBitmap. - */ - st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); - - return stfp; -} - - /** * Make fragment shader for glDraw/CopyPixels. This shader is made @@ -351,7 +218,7 @@ make_fragment_shader_z(struct st_context *st) * Create a simple vertex shader that just passes through the * vertex position and texcoord (and optionally, color). */ -struct st_vertex_program * +static struct st_vertex_program * st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) { /* only make programs once and re-use */ @@ -655,14 +522,14 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_rasterizer(cso); cso_save_viewport(cso); - /* setup state: just scissor */ + /* rasterizer state: just scissor */ { - struct pipe_rasterizer_state setup; - memset(&setup, 0, sizeof(setup)); + struct pipe_rasterizer_state rasterizer; + memset(&rasterizer, 0, sizeof(rasterizer)); if (ctx->Scissor.Enabled) - setup.scissor = 1; + rasterizer.scissor = 1; - cso_set_rasterizer(cso, &setup); + cso_set_rasterizer(cso, &rasterizer); } /* fragment shader state: TEX lookup program */ @@ -990,153 +857,6 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, -/** - * Create a texture which represents a bitmap image. - */ -static struct pipe_texture * -make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_surface *surface; - uint format = 0, cpp, comp; - ubyte *dest; - struct pipe_texture *pt; - int row, col; - - /* find a texture format we know */ - if (screen->is_format_supported( screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE )) { - format = PIPE_FORMAT_U_I8; - cpp = 1; - comp = 0; - } - else if (screen->is_format_supported( screen, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_TEXTURE )) { - format = PIPE_FORMAT_A8R8G8B8_UNORM; - cpp = 4; - comp = 3; /* alpha channel */ /*XXX little-endian dependency */ - } - else { - /* XXX support more formats */ - assert( 0 ); - } - - /** - * Create a texture. - */ - pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, width, height, - 1, 0); - if (!pt) - return NULL; - - if (unpack->BufferObj && unpack->BufferObj->Name) { - /* - pt->region = buffer_object_region(unpack->BufferObj); - */ - printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); - } - - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); - - /* map texture surface */ - dest = pipe_surface_map(surface); - - /* Put image into texture surface. - * Note that the image is actually going to be upside down in - * the texture. We deal with that with texcoords. - */ - - for (row = 0; row < height; row++) { - const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, - bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * surface->pitch * cpp; - - if (unpack->LsbFirst) { - /* Lsb first */ - GLubyte mask = 1U << (unpack->SkipPixels & 0x7); - for (col = 0; col < width; col++) { - - /* set texel to 255 if bit is set */ - destRow[comp] = (*src & mask) ? 255 : 0; - destRow += cpp; - - if (mask == 128U) { - src++; - mask = 1U; - } - else { - mask = mask << 1; - } - } - - /* get ready for next row */ - if (mask != 1) - src++; - } - else { - /* Msb first */ - GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); - for (col = 0; col < width; col++) { - - /* set texel to 255 if bit is set */ - destRow[comp] =(*src & mask) ? 255 : 0; - destRow += cpp; - - if (mask == 1U) { - src++; - mask = 128U; - } - else { - mask = mask >> 1; - } - } - - /* get ready for next row */ - if (mask != 128) - src++; - } - - } /* row */ - - /* Release surface */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); - - pt->format = format; - - return pt; -} - - - -static void -st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) -{ - struct st_fragment_program *stfp; - struct st_vertex_program *stvp; - struct st_context *st = ctx->st; - struct pipe_texture *pt; - - stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); - stfp = combined_bitmap_fragment_program(ctx); - - st_validate_state(st); - - pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); - if (pt) { - draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], - width, height, 1.0, 1.0, - pt, stvp, stfp, - ctx->Current.RasterColor, GL_FALSE); - - pipe_texture_reference(&pt, NULL); - } -} - - static void copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, @@ -1337,5 +1057,4 @@ void st_init_drawpixels_functions(struct dd_function_table *functions) { functions->DrawPixels = st_DrawPixels; functions->CopyPixels = st_CopyPixels; - functions->Bitmap = st_Bitmap; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index b8b906f06b..71ba487020 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,10 +30,6 @@ #define ST_CB_DRAWPIXELS_H -extern struct st_vertex_program * -st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor); - - extern void st_init_drawpixels_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index b1681be2eb..d9e8722976 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -35,8 +35,9 @@ #include "st_public.h" #include "st_context.h" #include "st_cb_accum.h" -#include "st_cb_bufferobjects.h" +#include "st_cb_bitmap.h" #include "st_cb_blit.h" +#include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_fbo.h" @@ -154,6 +155,7 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); st_destroy_generate_mipmap(st); + st_destroy_bitmap(st); st_destroy_blit(st); st_destroy_clear(st); @@ -221,8 +223,9 @@ void st_init_driver_functions(struct dd_function_table *functions) _mesa_init_glsl_driver_functions(functions); st_init_accum_functions(functions); - st_init_bufferobject_functions(functions); + st_init_bitmap_functions(functions); st_init_blit_functions(functions); + st_init_bufferobject_functions(functions); st_init_clear_functions(functions); st_init_drawpixels_functions(functions); st_init_fbo_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2563c7fed0..2d37086799 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -147,6 +147,9 @@ struct st_context struct st_fragment_program *program; /**< bitmap tex/kil program */ GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; + void *vs; + float vertices[4][3][4]; /**< vertex pos + color + texcoord */ + struct pipe_buffer *vbuf; } bitmap; /** for glClear */ -- cgit v1.2.3 From 5c431c22227fdc552b34a5feabf1d339dcfe9848 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 20 May 2008 13:38:45 -0600 Subject: gallium: clean-up glDraw/CopyPixels shaders when destroying context --- src/mesa/state_tracker/st_cb_drawpixels.c | 39 +++++++++++++++++++++---------- src/mesa/state_tracker/st_cb_drawpixels.h | 3 +++ src/mesa/state_tracker/st_context.c | 1 + src/mesa/state_tracker/st_context.h | 6 +++++ 4 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_drawpixels.h') diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 56b949cf96..fbbe8d2d64 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -164,14 +164,16 @@ static struct st_fragment_program * make_fragment_shader_z(struct st_context *st) { GLcontext *ctx = st->ctx; - /* only make programs once and re-use */ - static struct st_fragment_program *stfp = NULL; struct gl_program *p; GLuint ic = 0; - if (stfp) - return stfp; + if (st->drawpix.z_shader) { + return st->drawpix.z_shader; + } + /* + * Create shader now + */ p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) return NULL; @@ -213,10 +215,10 @@ make_fragment_shader_z(struct st_context *st) p->OutputsWritten = (1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR); p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ - stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL); + st->drawpix.z_shader = (struct st_fragment_program *) p; + st_translate_fragment_program(st, st->drawpix.z_shader, NULL); - return stfp; + return st->drawpix.z_shader; } @@ -228,16 +230,17 @@ make_fragment_shader_z(struct st_context *st) static struct st_vertex_program * st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) { - /* only make programs once and re-use */ - static struct st_vertex_program *progs[2] = { NULL, NULL }; GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; GLuint ic = 0; - if (progs[passColor]) - return progs[passColor]; + if (st->drawpix.vert_shaders[passColor]) + return st->drawpix.vert_shaders[passColor]; + /* + * Create shader now + */ p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); if (!p) return NULL; @@ -293,7 +296,7 @@ st_make_passthrough_vertex_shader(struct st_context *st, GLboolean passColor) stvp = (struct st_vertex_program *) p; st_translate_vertex_program(st, stvp, NULL); - progs[passColor] = stvp; + st->drawpix.vert_shaders[passColor] = stvp; return stvp; } @@ -1042,3 +1045,15 @@ void st_init_drawpixels_functions(struct dd_function_table *functions) functions->DrawPixels = st_DrawPixels; functions->CopyPixels = st_CopyPixels; } + + +void +st_destroy_drawpix(struct st_context *st) +{ + st_reference_fragprog(st, &st->drawpix.z_shader, NULL); + st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL); + st_reference_vertprog(st, &st->drawpix.vert_shaders[0], NULL); + st_reference_vertprog(st, &st->drawpix.vert_shaders[1], NULL); +} + + diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 71ba487020..26fe864d18 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -32,5 +32,8 @@ extern void st_init_drawpixels_functions(struct dd_function_table *functions); +extern void +st_destroy_drawpix(struct st_context *st); + #endif /* ST_CB_DRAWPIXELS_H */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index fb397ea510..b407fd884b 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -168,6 +168,7 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_bitmap(st); st_destroy_blit(st); st_destroy_clear(st); + st_destroy_drawpix(st); _vbo_DestroyContext(st->ctx); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1ca779d0a9..46c16e45e6 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -152,6 +152,12 @@ struct st_context struct bitmap_cache *cache; } bitmap; + /** for glDraw/CopyPixels */ + struct { + struct st_fragment_program *z_shader; + struct st_vertex_program *vert_shaders[2]; + } drawpix; + /** for glClear */ struct { struct pipe_shader_state vert_shader; -- cgit v1.2.3