2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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.
25 * Keith Whitwell <keith@tungstengraphics.com>
30 #define NR_MAT_ATTRIBS 12
32 static GLuint
check_size( const GLfloat
*attr
)
34 if (attr
[3] != 1.0) return 4;
35 if (attr
[2] != 0.0) return 3;
36 if (attr
[1] != 0.0) return 2;
41 static void init_legacy_currval(struct gl_context
*ctx
)
43 struct vbo_context
*vbo
= vbo_context(ctx
);
44 struct gl_client_array
*arrays
= vbo
->legacy_currval
;
47 memset(arrays
, 0, sizeof(*arrays
) * VERT_ATTRIB_MAX
);
49 /* Set up a constant (StrideB == 0) array for each current
52 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
53 struct gl_client_array
*cl
= &arrays
[i
];
55 /* Size will have to be determined at runtime:
57 cl
->Size
= check_size(ctx
->Current
.Attrib
[i
]);
62 cl
->Ptr
= (const void *)ctx
->Current
.Attrib
[i
];
63 cl
->_ElementSize
= cl
->Size
* sizeof(GLfloat
);
64 _mesa_reference_buffer_object(ctx
, &cl
->BufferObj
,
65 ctx
->Shared
->NullBufferObj
);
70 static void init_mat_currval(struct gl_context
*ctx
)
72 struct vbo_context
*vbo
= vbo_context(ctx
);
73 struct gl_client_array
*arrays
= vbo
->mat_currval
;
76 ASSERT(NR_MAT_ATTRIBS
== MAT_ATTRIB_MAX
);
78 memset(arrays
, 0, sizeof(*arrays
) * NR_MAT_ATTRIBS
);
80 /* Set up a constant (StrideB == 0) array for each current
83 for (i
= 0; i
< NR_MAT_ATTRIBS
; i
++) {
84 struct gl_client_array
*cl
= &arrays
[i
];
86 /* Size is fixed for the material attributes, for others will
87 * be determined at runtime:
90 case MAT_ATTRIB_FRONT_SHININESS
:
91 case MAT_ATTRIB_BACK_SHININESS
:
94 case MAT_ATTRIB_FRONT_INDEXES
:
95 case MAT_ATTRIB_BACK_INDEXES
:
103 cl
->Ptr
= (const void*)ctx
->Light
.Material
.Attrib
[i
];
108 cl
->_ElementSize
= cl
->Size
* sizeof(GLfloat
);
109 _mesa_reference_buffer_object(ctx
, &cl
->BufferObj
,
110 ctx
->Shared
->NullBufferObj
);
115 GLboolean
_vbo_CreateContext( struct gl_context
*ctx
)
117 struct vbo_context
*vbo
= CALLOC_STRUCT(vbo_context
);
119 ctx
->swtnl_im
= (void *)vbo
;
121 /* Initialize the arrayelt helper
123 if (!ctx
->aelt_context
&&
124 !_ae_create_context( ctx
)) {
128 /* TODO: remove these pointers.
130 vbo
->legacy_currval
= &vbo
->currval
[VBO_ATTRIB_POS
];
131 vbo
->mat_currval
= &vbo
->currval
[VBO_ATTRIB_MAT_FRONT_AMBIENT
];
133 init_legacy_currval( ctx
);
134 init_mat_currval( ctx
);
137 /* Hook our functions into exec and compile dispatch tables. These
138 * will pretty much be permanently installed, which means that the
139 * vtxfmt mechanism can be removed now.
141 vbo_exec_init( ctx
);
142 vbo_save_init( ctx
);
150 void _vbo_InvalidateState( struct gl_context
*ctx
, GLuint new_state
)
152 vbo_exec_invalidate_state(ctx
, new_state
);
156 void _vbo_DestroyContext( struct gl_context
*ctx
)
158 struct vbo_context
*vbo
= vbo_context(ctx
);
160 if (ctx
->aelt_context
) {
161 _ae_destroy_context( ctx
);
162 ctx
->aelt_context
= NULL
;
168 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
169 _mesa_reference_buffer_object(ctx
, &vbo
->currval
[i
].BufferObj
, NULL
);
172 vbo_exec_destroy(ctx
);
173 vbo_save_destroy(ctx
);
175 ctx
->swtnl_im
= NULL
;
180 void vbo_set_draw_func(struct gl_context
*ctx
, vbo_draw_func func
)
182 struct vbo_context
*vbo
= vbo_context(ctx
);
183 vbo
->draw_prims
= func
;