Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28.  /*
  29.   * Authors:
  30.   *   Keith Whitwell <keith@tungstengraphics.com>
  31.   */
  32.    
  33.  
  34. #ifndef ST_PROGRAM_H
  35. #define ST_PROGRAM_H
  36.  
  37. #include "main/mtypes.h"
  38. #include "program/program.h"
  39. #include "pipe/p_state.h"
  40. #include "st_context.h"
  41.  
  42.  
  43. /**
  44.  * Derived from Mesa gl_fragment_program:
  45.  */
  46. struct st_fragment_program
  47. {
  48.    struct gl_fragment_program Base;
  49.    GLuint serialNo;
  50.  
  51.    struct pipe_shader_state tgsi;
  52.    void *driver_shader;
  53.  
  54.    /** Program prefixed with glBitmap prologue */
  55.    struct st_fragment_program *bitmap_program;
  56.    uint bitmap_sampler;
  57. };
  58.  
  59.  
  60.  
  61. struct st_vp_varient_key
  62. {
  63.    boolean passthrough_edgeflags;
  64. };
  65.  
  66.  
  67. /**
  68.  * This represents a vertex program, especially translated to match
  69.  * the inputs of a particular fragment shader.
  70.  */
  71. struct st_vp_varient
  72. {
  73.    /* Parameters which generated this translated version of a vertex
  74.     * shader:
  75.     */
  76.    struct st_vp_varient_key key;
  77.  
  78.    /**
  79.     * TGSI tokens (to later generate a 'draw' module shader for
  80.     * selection/feedback/rasterpos)
  81.     */
  82.    struct pipe_shader_state tgsi;
  83.  
  84.    /** Driver's compiled shader */
  85.    void *driver_shader;
  86.  
  87.    /** For using our private draw module (glRasterPos) */
  88.    struct draw_vertex_shader *draw_shader;
  89.  
  90.    /** Next in linked list */
  91.    struct st_vp_varient *next;  
  92.  
  93.    /** similar to that in st_vertex_program, but with information about edgeflags too */
  94.    GLuint num_inputs;
  95. };
  96.  
  97.  
  98. /**
  99.  * Derived from Mesa gl_fragment_program:
  100.  */
  101. struct st_vertex_program
  102. {
  103.    struct gl_vertex_program Base;  /**< The Mesa vertex program */
  104.    GLuint serialNo, lastSerialNo;
  105.  
  106.    /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
  107.    GLuint input_to_index[VERT_ATTRIB_MAX];
  108.    /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
  109.    GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
  110.    GLuint num_inputs;
  111.  
  112.    /** Maps VERT_RESULT_x to slot */
  113.    GLuint result_to_output[VERT_RESULT_MAX];
  114.    ubyte output_semantic_name[VERT_RESULT_MAX];
  115.    ubyte output_semantic_index[VERT_RESULT_MAX];
  116.    GLuint num_outputs;
  117.  
  118.    /** List of translated varients of this vertex program.
  119.     */
  120.    struct st_vp_varient *varients;
  121. };
  122.  
  123. /**
  124.  * Derived from Mesa gl_geometry_program:
  125.  */
  126. struct st_geometry_program
  127. {
  128.    struct gl_geometry_program Base;  /**< The Mesa geometry program */
  129.    GLuint serialNo;
  130.  
  131.    /** map GP input back to VP output */
  132.    GLuint input_map[PIPE_MAX_SHADER_INPUTS];
  133.  
  134.    /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
  135.    GLuint input_to_index[GEOM_ATTRIB_MAX];
  136.    /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
  137.    GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
  138.  
  139.    GLuint num_inputs;
  140.  
  141.    GLuint input_to_slot[GEOM_ATTRIB_MAX];  /**< Maps GEOM_ATTRIB_x to slot */
  142.    GLuint num_input_slots;
  143.  
  144.    ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
  145.    ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
  146.  
  147.    struct pipe_shader_state tgsi;
  148.    void *driver_shader;
  149. };
  150.  
  151. static INLINE struct st_fragment_program *
  152. st_fragment_program( struct gl_fragment_program *fp )
  153. {
  154.    return (struct st_fragment_program *)fp;
  155. }
  156.  
  157.  
  158. static INLINE struct st_vertex_program *
  159. st_vertex_program( struct gl_vertex_program *vp )
  160. {
  161.    return (struct st_vertex_program *)vp;
  162. }
  163.  
  164. static INLINE struct st_geometry_program *
  165. st_geometry_program( struct gl_geometry_program *vp )
  166. {
  167.    return (struct st_geometry_program *)vp;
  168. }
  169.  
  170. static INLINE void
  171. st_reference_vertprog(struct st_context *st,
  172.                       struct st_vertex_program **ptr,
  173.                       struct st_vertex_program *prog)
  174. {
  175.    _mesa_reference_program(st->ctx,
  176.                            (struct gl_program **) ptr,
  177.                            (struct gl_program *) prog);
  178. }
  179.  
  180. static INLINE void
  181. st_reference_geomprog(struct st_context *st,
  182.                       struct st_geometry_program **ptr,
  183.                       struct st_geometry_program *prog)
  184. {
  185.    _mesa_reference_program(st->ctx,
  186.                            (struct gl_program **) ptr,
  187.                            (struct gl_program *) prog);
  188. }
  189.  
  190. static INLINE void
  191. st_reference_fragprog(struct st_context *st,
  192.                       struct st_fragment_program **ptr,
  193.                       struct st_fragment_program *prog)
  194. {
  195.    _mesa_reference_program(st->ctx,
  196.                            (struct gl_program **) ptr,
  197.                            (struct gl_program *) prog);
  198. }
  199.  
  200.  
  201. extern void
  202. st_translate_fragment_program(struct st_context *st,
  203.                               struct st_fragment_program *fp);
  204.  
  205. extern void
  206. st_translate_geometry_program(struct st_context *st,
  207.                               struct st_geometry_program *stgp);
  208.  
  209. /* Called after program string change, discard all previous
  210.  * compilation results.
  211.  */
  212. extern void
  213. st_prepare_vertex_program(struct st_context *st,
  214.                           struct st_vertex_program *stvp);
  215.  
  216. extern struct st_vp_varient *
  217. st_translate_vertex_program(struct st_context *st,
  218.                             struct st_vertex_program *stvp,
  219.                             const struct st_vp_varient_key *key);
  220.  
  221. void
  222. st_vp_release_varients( struct st_context *st,
  223.                         struct st_vertex_program *stvp );
  224.  
  225. extern void
  226. st_print_shaders(struct gl_context *ctx);
  227.  
  228.  
  229. #endif
  230.