2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
39 #include "brw_fallback.h"
42 static void _playback_copy_to_current( GLcontext
*ctx
,
43 const struct brw_save_vertex_list
*node
)
45 struct brw_save_context
*save
= IMM_CONTEXT(ctx
)->save
;
46 GLfloat vertex
[BRW_ATTRIB_MAX
* 4], *data
= vertex
;
50 offset
= node
->buffer_offset
+ (node
->count
-1) * node
->vertex_size
;
52 offset
= node
->buffer_offset
;
54 ctx
->Driver
.GetBufferSubData( ctx
, 0, offset
, node
->vertex_size
,
55 data
, node
->vertex_store
->bufferobj
);
57 for (i
= BRW_ATTRIB_POS
+1 ; i
<= BRW_ATTRIB_INDEX
; i
++) {
58 if (node
->attrsz
[i
]) {
59 COPY_CLEAN_4V(save
->current
[i
], node
->attrsz
[i
], data
);
60 data
+= node
->attrsz
[i
];
62 if (i
>= BRW_ATTRIB_MAT_FRONT_AMBIENT
&&
63 i
<= BRW_ATTRIB_MAT_BACK_INDEXES
)
64 ctx
->NewState
|= _NEW_LIGHT
;
68 /* Edgeflag requires special treatment:
70 if (node
->attrsz
[BRW_ATTRIB_EDGEFLAG
]) {
71 ctx
->Current
.EdgeFlag
= (data
[0] == 1.0);
76 /* Colormaterial -- this kindof sucks.
78 if (ctx
->Light
.ColorMaterialEnabled
) {
79 _mesa_update_color_material(ctx
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
83 /* CurrentExecPrimitive
85 if (node
->prim_count
) {
86 const struct brw_draw_prim
*prim
= &node
->prim
[node
->prim_count
- 1];
88 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
90 ctx
->Driver
.CurrentExecPrimitive
= prim
->mode
;
96 /* Treat the vertex storage as a VBO, define vertex arrays pointing
99 static void brw_bind_vertex_list( struct brw_save_context
*save
,
100 const struct brw_save_vertex_list
*node
)
102 struct gl_client_array
*arrays
= save
->arrays
;
103 GLuint data
= node
->buffer_offset
;
106 memset(arrays
, 0, BRW_ATTRIB_MAX
* sizeof(arrays
[0]));
108 for (attr
= 0; attr
<= BRW_ATTRIB_INDEX
; attr
++) {
109 if (node
->attrsz
[attr
]) {
110 arrays
[attr
].Ptr
= (const GLubyte
*)data
;
111 arrays
[attr
].Size
= node
->attrsz
[attr
];
112 arrays
[attr
].StrideB
= node
->vertex_size
* sizeof(GLfloat
);
113 arrays
[attr
].Stride
= node
->vertex_size
* sizeof(GLfloat
);
114 arrays
[attr
].Type
= GL_FLOAT
;
115 arrays
[attr
].Enabled
= 1;
116 arrays
[attr
].BufferObj
= node
->vertex_store
->bufferobj
;
117 arrays
[attr
]._MaxElement
= node
->count
; /* ??? */
119 assert(arrays
[attr
].BufferObj
->Name
);
121 data
+= node
->attrsz
[attr
] * sizeof(GLfloat
);
126 static void brw_save_loopback_vertex_list( GLcontext
*ctx
,
127 const struct brw_save_vertex_list
*list
)
129 const char *buffer
= ctx
->Driver
.MapBuffer(ctx
,
131 GL_DYNAMIC_READ_ARB
, /* ? */
132 list
->vertex_store
->bufferobj
);
134 brw_loopback_vertex_list( ctx
,
135 (const GLfloat
*)(buffer
+ list
->buffer_offset
),
142 ctx
->Driver
.UnmapBuffer(ctx
, GL_ARRAY_BUFFER_ARB
,
143 list
->vertex_store
->bufferobj
);
148 * Execute the buffer and save copied verts.
150 void brw_save_playback_vertex_list( GLcontext
*ctx
, void *data
)
152 const struct brw_save_vertex_list
*node
= (const struct brw_save_vertex_list
*) data
;
153 struct brw_save_context
*save
= IMM_CONTEXT(ctx
)->save
;
155 FLUSH_CURRENT(ctx
, 0);
157 if (node
->prim_count
> 0 && node
->count
> 0) {
159 if (ctx
->Driver
.CurrentExecPrimitive
!= PRIM_OUTSIDE_BEGIN_END
&&
160 node
->prim
[0].begin
) {
162 /* Degenerate case: list is called inside begin/end pair and
163 * includes operations such as glBegin or glDrawArrays.
166 _mesa_printf("displaylist recursive begin");
168 brw_save_loopback_vertex_list( ctx
, node
);
171 else if (save
->replay_flags
) {
172 /* Various degnerate cases: translate into immediate mode
173 * calls rather than trying to execute in place.
175 brw_save_loopback_vertex_list( ctx
, node
);
180 _mesa_update_state( ctx
);
182 if ((ctx
->VertexProgram
.Enabled
&& !ctx
->VertexProgram
._Enabled
) ||
183 (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
)) {
184 _mesa_error(ctx
, GL_INVALID_OPERATION
,
185 "glBegin (invalid vertex/fragment program)");
189 brw_bind_vertex_list( save
, node
);
191 if (!brw_draw_prims( save
->ctx
,
196 0, /* Node is a VBO, so this is ok */
200 brw_save_loopback_vertex_list( ctx
, node
);
208 _playback_copy_to_current( ctx
, node
);