1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/imports.h"
37 #include "tnl/t_context.h"
38 #include "tnl/t_pipeline.h"
40 #include "st_context.h"
43 #include "st_cb_bufferobjects.h"
44 #include "pipe/p_context.h"
45 #include "pipe/p_defines.h"
47 #include "vbo/vbo_context.h"
50 * Enabling this causes the VBO module to call draw_vbo() below,
51 * bypassing the T&L module. This only works with VBO-based demos,
52 * such as progs/test/bufferobj.c
54 #define USE_NEW_DRAW 0
58 * TNL stage which feeds into the above.
60 * XXX: this needs to go into each driver using this code, because we
61 * cannot make the leap from ctx->draw_context in this file. The
62 * driver needs to customize tnl anyway, so this isn't a big deal.
64 static GLboolean
draw( GLcontext
* ctx
, struct tnl_pipeline_stage
*stage
)
66 struct st_context
*st
= st_context(ctx
);
67 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
69 /* Validate driver and pipe state:
71 st_validate_state( st
);
73 /* Call into the new draw code to handle the VB:
75 st
->pipe
->draw_vb( st
->pipe
, VB
);
82 const struct tnl_pipeline_stage st_draw
= {
83 "check state and draw",
91 static const struct tnl_pipeline_stage
*st_pipeline
[] = {
92 &_tnl_vertex_transform_stage
,
93 &_tnl_vertex_cull_stage
,
94 &_tnl_normal_transform_stage
,
96 &_tnl_fog_coordinate_stage
,
98 &_tnl_texture_transform_stage
,
99 &_tnl_point_attenuation_stage
,
100 &_tnl_vertex_program_stage
,
101 &st_draw
, /* ADD: escape to pipe */
108 pipe_vertex_format(GLenum format
, GLuint size
)
110 static const GLuint float_fmts
[4] = {
111 PIPE_FORMAT_R32_FLOAT
,
112 PIPE_FORMAT_R32G32_FLOAT
,
113 PIPE_FORMAT_R32G32B32_FLOAT
,
114 PIPE_FORMAT_R32G32B32A32_FLOAT
,
117 assert(format
>= GL_BYTE
);
118 assert(format
<= GL_DOUBLE
);
124 return float_fmts
[size
- 1];
133 * This function gets plugged into the VBO module and is called when
134 * we have something to render.
135 * Basically, translate the information into the format expected by pipe.
138 draw_vbo(GLcontext
*ctx
,
139 const struct gl_client_array
**arrays
,
140 const struct _mesa_prim
*prims
,
142 const struct _mesa_index_buffer
*ib
,
146 struct pipe_context
*pipe
= ctx
->st
->pipe
;
149 /* tell pipe about the vertex array element/attributes */
150 for (attr
= 0; attr
< 16; attr
++) {
151 struct gl_buffer_object
*bufobj
= arrays
[attr
]->BufferObj
;
152 struct pipe_vertex_buffer vbuffer
;
153 struct pipe_vertex_element velement
;
155 if (bufobj
&& bufobj
->Name
) {
156 struct st_buffer_object
*stobj
= st_buffer_object(bufobj
);
158 assert(stobj
->buffer
);
160 vbuffer
.pitch
= arrays
[attr
]->StrideB
; /* in bytes */
161 vbuffer
.max_index
= 0;
162 vbuffer
.buffer
= stobj
->buffer
;
163 vbuffer
.buffer_offset
= 0;
165 /* Recall that for VBOs, the gl_client_array->Ptr field is
166 * really an offset from the start of the VBO, not a pointer.
168 velement
.src_offset
= (unsigned) arrays
[attr
]->Ptr
;
169 velement
.vertex_buffer_index
= attr
;
170 velement
.dst_offset
= 0;
171 velement
.src_format
= pipe_vertex_format(arrays
[attr
]->Type
,
175 /* vertex attribute data is not an a real buffer! */
176 /* XXX we'll want to handle that someday... */
178 vbuffer
.buffer
= NULL
;
181 pipe
->set_vertex_buffer(pipe
, attr
, &vbuffer
);
182 pipe
->set_vertex_element(pipe
, attr
, &velement
);
185 /* do actual drawing */
186 for (i
= 0; i
< nr_prims
; i
++) {
187 pipe
->draw_arrays(pipe
, prims
[i
].mode
, prims
[i
].start
, prims
[i
].count
);
194 /* This is all a hack to keep using tnl until we have vertex programs
197 void st_init_draw( struct st_context
*st
)
199 GLcontext
*ctx
= st
->ctx
;
202 struct vbo_context
*vbo
= (struct vbo_context
*) ctx
->swtnl_im
;
205 assert(vbo
->draw_prims
);
206 vbo
->draw_prims
= draw_vbo
;
209 _tnl_destroy_pipeline( ctx
);
210 _tnl_install_pipeline( ctx
, st_pipeline
);
216 void st_destroy_draw( struct st_context
*st
)