1848b8605Smrg/*
2848b8605Smrg * Mesa 3-D graphics library
3848b8605Smrg *
4848b8605Smrg * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the "Software"),
8848b8605Smrg * to deal in the Software without restriction, including without limitation
9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
11848b8605Smrg * Software is furnished to do so, subject to the following conditions:
12848b8605Smrg *
13848b8605Smrg * The above copyright notice and this permission notice shall be included
14848b8605Smrg * in all copies or substantial portions of the Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE.
23848b8605Smrg *
24848b8605Smrg * Authors:
25848b8605Smrg *    Keith Whitwell <keithw@vmware.com>
26848b8605Smrg */
27848b8605Smrg
28848b8605Smrg#ifndef _TNL_H
29848b8605Smrg#define _TNL_H
30848b8605Smrg
31848b8605Smrg#include "main/glheader.h"
32848b8605Smrg
33848b8605Smrgstruct gl_context;
34848b8605Smrgstruct gl_program;
35b8e80941Smrgstruct gl_buffer_object;
36b8e80941Smrgstruct gl_transform_feedback_object;
37b8e80941Smrgstruct dd_function_table;
38848b8605Smrg
39848b8605Smrg
40848b8605Smrg/* These are the public-access functions exported from tnl.  (A few
41848b8605Smrg * more are currently hooked into dispatch directly by the module
42848b8605Smrg * itself.)
43848b8605Smrg */
44848b8605Smrgextern GLboolean
45848b8605Smrg_tnl_CreateContext( struct gl_context *ctx );
46848b8605Smrg
47848b8605Smrgextern void
48848b8605Smrg_tnl_DestroyContext( struct gl_context *ctx );
49848b8605Smrg
50848b8605Smrgextern void
51848b8605Smrg_tnl_InvalidateState( struct gl_context *ctx, GLuint new_state );
52848b8605Smrg
53b8e80941Smrgextern void
54b8e80941Smrg_tnl_init_driver_draw_function(struct dd_function_table *functions);
55b8e80941Smrg
56848b8605Smrg/* Functions to revive the tnl module after being unhooked from
57848b8605Smrg * dispatch and/or driver callbacks.
58848b8605Smrg */
59848b8605Smrg
60848b8605Smrgextern void
61848b8605Smrg_tnl_wakeup( struct gl_context *ctx );
62848b8605Smrg
63848b8605Smrg/* Driver configuration options:
64848b8605Smrg */
65848b8605Smrgextern void
66848b8605Smrg_tnl_need_projected_coords( struct gl_context *ctx, GLboolean flag );
67848b8605Smrg
68848b8605Smrg
69b8e80941Smrg/**
70b8e80941Smrg * Vertex array information which is derived from gl_array_attributes
71b8e80941Smrg * and gl_vertex_buffer_binding information.  Used by the TNL module and
72b8e80941Smrg * device drivers.
73b8e80941Smrg */
74b8e80941Smrgstruct tnl_vertex_array
75b8e80941Smrg{
76b8e80941Smrg   /** Vertex attribute array */
77b8e80941Smrg   const struct gl_array_attributes *VertexAttrib;
78b8e80941Smrg   /** Vertex buffer binding */
79b8e80941Smrg   const struct gl_vertex_buffer_binding *BufferBinding;
80b8e80941Smrg};
81b8e80941Smrg
82b8e80941Smrg
83b8e80941Smrgextern const struct tnl_vertex_array*
84b8e80941Smrg_tnl_bind_inputs( struct gl_context *ctx );
85b8e80941Smrg
86b8e80941Smrg
87848b8605Smrg/* Control whether T&L does per-vertex fog
88848b8605Smrg */
89848b8605Smrgextern void
90848b8605Smrg_tnl_allow_vertex_fog( struct gl_context *ctx, GLboolean value );
91848b8605Smrg
92848b8605Smrgextern void
93848b8605Smrg_tnl_allow_pixel_fog( struct gl_context *ctx, GLboolean value );
94848b8605Smrg
95848b8605Smrgextern GLboolean
96848b8605Smrg_tnl_program_string(struct gl_context *ctx, GLenum target, struct gl_program *program);
97848b8605Smrg
98848b8605Smrgstruct _mesa_prim;
99848b8605Smrgstruct _mesa_index_buffer;
100848b8605Smrg
101848b8605Smrgvoid
102b8e80941Smrg_tnl_draw_prims(struct gl_context *ctx,
103b8e80941Smrg                const struct tnl_vertex_array *arrays,
104848b8605Smrg		     const struct _mesa_prim *prim,
105848b8605Smrg		     GLuint nr_prims,
106848b8605Smrg		     const struct _mesa_index_buffer *ib,
107848b8605Smrg		     GLboolean index_bounds_valid,
108848b8605Smrg		     GLuint min_index,
109848b8605Smrg		     GLuint max_index,
110848b8605Smrg		     struct gl_transform_feedback_object *tfb_vertcount,
111b8e80941Smrg                     unsigned stream,
112848b8605Smrg		     struct gl_buffer_object *indirect );
113848b8605Smrg
114b8e80941Smrgvoid
115b8e80941Smrg_tnl_draw(struct gl_context *ctx,
116b8e80941Smrg          const struct _mesa_prim *prim, GLuint nr_prims,
117b8e80941Smrg          const struct _mesa_index_buffer *ib,
118b8e80941Smrg          GLboolean index_bounds_valid, GLuint min_index, GLuint max_index,
119b8e80941Smrg          struct gl_transform_feedback_object *tfb_vertcount, unsigned stream,
120b8e80941Smrg          struct gl_buffer_object *indirect);
121b8e80941Smrg
122848b8605Smrgextern void
123848b8605Smrg_tnl_RasterPos(struct gl_context *ctx, const GLfloat vObj[4]);
124848b8605Smrg
125848b8605Smrgextern void
126848b8605Smrg_tnl_validate_shine_tables( struct gl_context *ctx );
127848b8605Smrg
128b8e80941Smrg
129b8e80941Smrg
130b8e80941Smrg/**
131b8e80941Smrg * For indirect array drawing:
132b8e80941Smrg *
133b8e80941Smrg *    typedef struct {
134b8e80941Smrg *       GLuint count;
135b8e80941Smrg *       GLuint primCount;
136b8e80941Smrg *       GLuint first;
137b8e80941Smrg *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
138b8e80941Smrg *    } DrawArraysIndirectCommand;
139b8e80941Smrg *
140b8e80941Smrg * For indirect indexed drawing:
141b8e80941Smrg *
142b8e80941Smrg *    typedef struct {
143b8e80941Smrg *       GLuint count;
144b8e80941Smrg *       GLuint primCount;
145b8e80941Smrg *       GLuint firstIndex;
146b8e80941Smrg *       GLint  baseVertex;
147b8e80941Smrg *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
148b8e80941Smrg *    } DrawElementsIndirectCommand;
149b8e80941Smrg */
150b8e80941Smrg
151b8e80941Smrg
152b8e80941Smrg/**
153b8e80941Smrg * Draw a number of primitives.
154b8e80941Smrg * \param prims  array [nr_prims] describing what to draw (prim type,
155b8e80941Smrg *               vertex count, first index, instance count, etc).
156b8e80941Smrg * \param arrays array of vertex arrays for draw
157b8e80941Smrg * \param ib  index buffer for indexed drawing, NULL for array drawing
158b8e80941Smrg * \param index_bounds_valid  are min_index and max_index valid?
159b8e80941Smrg * \param min_index  lowest vertex index used
160b8e80941Smrg * \param max_index  highest vertex index used
161b8e80941Smrg * \param tfb_vertcount  if non-null, indicates which transform feedback
162b8e80941Smrg *                       object has the vertex count.
163b8e80941Smrg * \param tfb_stream  If called via DrawTransformFeedbackStream, specifies the
164b8e80941Smrg *                    vertex stream buffer from which to get the vertex count.
165b8e80941Smrg * \param indirect  If any prims are indirect, this specifies the buffer
166b8e80941Smrg *                  to find the "DrawArrays/ElementsIndirectCommand" data.
167b8e80941Smrg *                  This may be deprecated in the future
168b8e80941Smrg */
169b8e80941Smrgtypedef void (*tnl_draw_func)(struct gl_context *ctx,
170b8e80941Smrg                              const struct tnl_vertex_array* arrays,
171b8e80941Smrg                              const struct _mesa_prim *prims,
172b8e80941Smrg                              GLuint nr_prims,
173b8e80941Smrg                              const struct _mesa_index_buffer *ib,
174b8e80941Smrg                              GLboolean index_bounds_valid,
175b8e80941Smrg                              GLuint min_index,
176b8e80941Smrg                              GLuint max_index,
177b8e80941Smrg                              struct gl_transform_feedback_object *tfb_vertcount,
178b8e80941Smrg                              unsigned tfb_stream,
179b8e80941Smrg                              struct gl_buffer_object *indirect);
180b8e80941Smrg
181b8e80941Smrg
182b8e80941Smrg/* Utility function to cope with various constraints on tnl modules or
183b8e80941Smrg * hardware.  This can be used to split an incoming set of arrays and
184b8e80941Smrg * primitives against the following constraints:
185b8e80941Smrg *    - Maximum number of indices in index buffer.
186b8e80941Smrg *    - Maximum number of vertices referenced by index buffer.
187b8e80941Smrg *    - Maximum hardware vertex buffer size.
188b8e80941Smrg */
189b8e80941Smrgstruct split_limits
190b8e80941Smrg{
191b8e80941Smrg   GLuint max_verts;
192b8e80941Smrg   GLuint max_indices;
193b8e80941Smrg   GLuint max_vb_size;		/* bytes */
194b8e80941Smrg};
195b8e80941Smrg
196b8e80941Smrgvoid
197b8e80941Smrg_tnl_split_prims(struct gl_context *ctx,
198b8e80941Smrg                 const struct tnl_vertex_array *arrays,
199b8e80941Smrg                 const struct _mesa_prim *prim,
200b8e80941Smrg                 GLuint nr_prims,
201b8e80941Smrg                 const struct _mesa_index_buffer *ib,
202b8e80941Smrg                 GLuint min_index,
203b8e80941Smrg                 GLuint max_index,
204b8e80941Smrg                 tnl_draw_func draw,
205b8e80941Smrg                 const struct split_limits *limits);
206b8e80941Smrg
207b8e80941Smrg
208848b8605Smrg#endif
209