st_cb_program.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Keith Whitwell <keith@tungstengraphics.com>
00031   */
00032 
00033 #include "main/glheader.h"
00034 #include "main/macros.h"
00035 #include "main/enums.h"
00036 #include "shader/prog_instruction.h"
00037 #include "shader/prog_parameter.h"
00038 #include "shader/program.h"
00039 #include "shader/programopt.h"
00040 #include "shader/shader_api.h"
00041 
00042 #include "cso_cache/cso_context.h"
00043 #include "draw/draw_context.h"
00044 
00045 #include "st_context.h"
00046 #include "st_program.h"
00047 #include "st_atom_shader.h"
00048 #include "st_cb_program.h"
00049 
00050 
00051 static GLuint SerialNo = 1;
00052 
00053 
00058 static void st_bind_program( GLcontext *ctx,
00059                              GLenum target, 
00060                              struct gl_program *prog )
00061 {
00062    struct st_context *st = st_context(ctx);
00063 
00064    switch (target) {
00065    case GL_VERTEX_PROGRAM_ARB: 
00066       st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
00067       break;
00068    case GL_FRAGMENT_PROGRAM_ARB:
00069       st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00070       break;
00071    }
00072 }
00073 
00074 
00079 static void st_use_program( GLcontext *ctx,
00080                             GLuint program )
00081 {
00082    struct st_context *st = st_context(ctx);
00083 
00084    st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00085    st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
00086 
00087    _mesa_use_program(ctx, program);
00088 }
00089 
00090 
00091 
00096 static struct gl_program *st_new_program( GLcontext *ctx,
00097                                           GLenum target,
00098                                           GLuint id )
00099 {
00100    switch (target) {
00101    case GL_VERTEX_PROGRAM_ARB: {
00102       struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
00103 
00104       prog->serialNo = SerialNo++;
00105 
00106       return _mesa_init_vertex_program( ctx, 
00107                                         &prog->Base,
00108                                         target, 
00109                                         id );
00110    }
00111 
00112    case GL_FRAGMENT_PROGRAM_ARB:
00113    case GL_FRAGMENT_PROGRAM_NV: {
00114       struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
00115 
00116       prog->serialNo = SerialNo++;
00117 
00118       return _mesa_init_fragment_program( ctx, 
00119                                           &prog->Base,
00120                                           target, 
00121                                           id );
00122    }
00123 
00124    default:
00125       assert(0);
00126       return NULL;
00127    }
00128 }
00129 
00130 
00131 void
00132 st_delete_program(GLcontext *ctx, struct gl_program *prog)
00133 {
00134    struct st_context *st = st_context(ctx);
00135 
00136    switch( prog->Target ) {
00137    case GL_VERTEX_PROGRAM_ARB:
00138       {
00139          struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
00140 
00141          if (stvp->driver_shader) {
00142             cso_delete_vertex_shader(st->cso_context, stvp->driver_shader);
00143             stvp->driver_shader = NULL;
00144          }
00145 
00146          if (stvp->draw_shader) {
00147 #if FEATURE_feedback || FEATURE_drawpix
00148             /* this would only have been allocated for the RasterPos path */
00149             draw_delete_vertex_shader(st->draw, stvp->draw_shader);
00150             stvp->draw_shader = NULL;
00151 #endif
00152          }
00153 
00154          if (stvp->state.tokens) {
00155             FREE((void *) stvp->state.tokens);
00156             stvp->state.tokens = NULL;
00157          }
00158       }
00159       break;
00160    case GL_FRAGMENT_PROGRAM_ARB:
00161       {
00162          struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
00163 
00164          if (stfp->driver_shader) {
00165             cso_delete_fragment_shader(st->cso_context, stfp->driver_shader);
00166             stfp->driver_shader = NULL;
00167          }
00168          
00169          if (stfp->state.tokens) {
00170             FREE((void *) stfp->state.tokens);
00171             stfp->state.tokens = NULL;
00172          }
00173 
00174          if (stfp->bitmap_program) {
00175             struct gl_program *prg = &stfp->bitmap_program->Base.Base;
00176             _mesa_reference_program(ctx, &prg, NULL);
00177             stfp->bitmap_program = NULL;
00178          }
00179 
00180          st_free_translated_vertex_programs(st, stfp->vertex_programs);
00181       }
00182       break;
00183    default:
00184       assert(0); /* problem */
00185    }
00186 
00187    /* delete base class */
00188    _mesa_delete_program( ctx, prog );
00189 }
00190 
00191 
00192 static GLboolean st_is_program_native( GLcontext *ctx,
00193                                        GLenum target, 
00194                                        struct gl_program *prog )
00195 {
00196    return GL_TRUE;
00197 }
00198 
00199 
00200 static void st_program_string_notify( GLcontext *ctx,
00201                                       GLenum target,
00202                                       struct gl_program *prog )
00203 {
00204    struct st_context *st = st_context(ctx);
00205 
00206    if (target == GL_FRAGMENT_PROGRAM_ARB) {
00207       struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
00208 
00209       stfp->serialNo++;
00210 
00211       if (stfp->driver_shader) {
00212          cso_delete_fragment_shader(st->cso_context, stfp->driver_shader);
00213          stfp->driver_shader = NULL;
00214       }
00215 
00216       if (stfp->state.tokens) {
00217          FREE((void *) stfp->state.tokens);
00218          stfp->state.tokens = NULL;
00219       }
00220 
00221       stfp->param_state = stfp->Base.Base.Parameters->StateFlags;
00222 
00223       if (st->fp == stfp)
00224          st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00225    }
00226    else if (target == GL_VERTEX_PROGRAM_ARB) {
00227       struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
00228 
00229       stvp->serialNo++;
00230 
00231       if (stvp->driver_shader) {
00232          cso_delete_vertex_shader(st->cso_context, stvp->driver_shader);
00233          stvp->driver_shader = NULL;
00234       }
00235 
00236       if (stvp->draw_shader) {
00237 #if FEATURE_feedback || FEATURE_drawpix
00238          /* this would only have been allocated for the RasterPos path */
00239          draw_delete_vertex_shader(st->draw, stvp->draw_shader);
00240          stvp->draw_shader = NULL;
00241 #endif
00242       }
00243 
00244       if (stvp->state.tokens) {
00245          FREE((void *) stvp->state.tokens);
00246          stvp->state.tokens = NULL;
00247       }
00248 
00249       stvp->param_state = stvp->Base.Base.Parameters->StateFlags;
00250 
00251       if (st->vp == stvp)
00252          st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
00253    }
00254 }
00255 
00256 
00257 
00258 void st_init_program_functions(struct dd_function_table *functions)
00259 {
00260    functions->BindProgram = st_bind_program;
00261    functions->UseProgram = st_use_program;
00262    functions->NewProgram = st_new_program;
00263    functions->DeleteProgram = st_delete_program;
00264    functions->IsProgramNative = st_is_program_native;
00265    functions->ProgramStringNotify = st_program_string_notify;
00266 }

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4