• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
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  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 
27 #ifndef VARRAY_H
28 #define VARRAY_H
29 
30 #include "bufferobj.h"
31 
32 struct gl_interleaved_layout {
33    bool tflag, cflag, nflag;      /* enable/disable flags */
34    int tcomps, ccomps, vcomps;    /* components per texcoord, color, vertex */
35    GLenum ctype;                  /* color type */
36    int coffset, noffset, voffset; /* color, normal, vertex offsets */
37    int toffset;                   /* always zero */
38    int defstride;                 /* default stride */
39 };
40 
41 bool
42 _mesa_get_interleaved_layout(GLenum format,
43                              struct gl_interleaved_layout *layout);
44 
45 void
46 _mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
47                         GLubyte size, GLenum16 type, GLenum16 format,
48                         GLboolean normalized, GLboolean integer,
49                         GLboolean doubles);
50 
51 
52 /**
53  * Returns a pointer to the vertex attribute data in a client array,
54  * or the offset into the vertex buffer for an array that resides in
55  * a vertex buffer.
56  */
57 static inline const GLubyte *
_mesa_vertex_attrib_address(const struct gl_array_attributes * array,const struct gl_vertex_buffer_binding * binding)58 _mesa_vertex_attrib_address(const struct gl_array_attributes *array,
59                             const struct gl_vertex_buffer_binding *binding)
60 {
61    if (binding->BufferObj)
62       return (const GLubyte *) (binding->Offset + array->RelativeOffset);
63    else
64       return array->Ptr;
65 }
66 
67 
68 static inline bool
_mesa_attr_zero_aliases_vertex(const struct gl_context * ctx)69 _mesa_attr_zero_aliases_vertex(const struct gl_context *ctx)
70 {
71    return ctx->_AttribZeroAliasesVertex;
72 }
73 
74 
75 extern void
76 _mesa_update_array_format(struct gl_context *ctx,
77                           struct gl_vertex_array_object *vao,
78                           gl_vert_attrib attrib, GLint size, GLenum type,
79                           GLenum format, GLboolean normalized,
80                           GLboolean integer, GLboolean doubles,
81                           GLuint relativeOffset);
82 
83 extern void
84 _mesa_enable_vertex_array_attribs(struct gl_context *ctx,
85                                  struct gl_vertex_array_object *vao,
86                                  GLbitfield attrib_bits);
87 
88 static inline void
_mesa_enable_vertex_array_attrib(struct gl_context * ctx,struct gl_vertex_array_object * vao,gl_vert_attrib attrib)89 _mesa_enable_vertex_array_attrib(struct gl_context *ctx,
90                                  struct gl_vertex_array_object *vao,
91                                  gl_vert_attrib attrib)
92 {
93    assert(attrib < VERT_ATTRIB_MAX);
94    _mesa_enable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib));
95 }
96 
97 
98 extern void
99 _mesa_disable_vertex_array_attribs(struct gl_context *ctx,
100                                    struct gl_vertex_array_object *vao,
101                                    GLbitfield attrib_bits);
102 
103 static inline void
_mesa_disable_vertex_array_attrib(struct gl_context * ctx,struct gl_vertex_array_object * vao,gl_vert_attrib attrib)104 _mesa_disable_vertex_array_attrib(struct gl_context *ctx,
105                                   struct gl_vertex_array_object *vao,
106                                   gl_vert_attrib attrib)
107 {
108    assert(attrib < VERT_ATTRIB_MAX);
109    _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib));
110 }
111 
112 
113 extern void
114 _mesa_vertex_attrib_binding(struct gl_context *ctx,
115                             struct gl_vertex_array_object *vao,
116                             gl_vert_attrib attribIndex,
117                             GLuint bindingIndex);
118 
119 
120 extern void
121 _mesa_bind_vertex_buffer(struct gl_context *ctx,
122                          struct gl_vertex_array_object *vao,
123                          GLuint index,
124                          struct gl_buffer_object *vbo,
125                          GLintptr offset, GLsizei stride,
126                          bool offset_is_int32, bool take_vbo_ownership);
127 
128 static inline unsigned
_mesa_get_prim_restart_index(bool fixed_index,unsigned restart_index,unsigned index_size)129 _mesa_get_prim_restart_index(bool fixed_index, unsigned restart_index,
130                              unsigned index_size)
131 {
132    /* The index_size parameter is meant to be in bytes. */
133    assert(index_size == 1 || index_size == 2 || index_size == 4);
134 
135    /* From the OpenGL 4.3 core specification, page 302:
136     * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
137     *  enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
138     *  is used."
139     */
140    if (fixed_index) {
141       /* 1 -> 0xff, 2 -> 0xffff, 4 -> 0xffffffff */
142       return 0xffffffffu >> 8 * (4 - index_size);
143    }
144 
145    return restart_index;
146 }
147 
148 static inline unsigned
_mesa_primitive_restart_index(const struct gl_context * ctx,unsigned index_size)149 _mesa_primitive_restart_index(const struct gl_context *ctx,
150                               unsigned index_size)
151 {
152    return _mesa_get_prim_restart_index(ctx->Array.PrimitiveRestartFixedIndex,
153                                        ctx->Array.RestartIndex, index_size);
154 }
155 
156 void
157 _mesa_InternalBindVertexBuffers(struct gl_context *ctx,
158                                 const struct glthread_attrib_binding *buffers,
159                                 GLbitfield buffer_mask,
160                                 GLboolean restore_pointers);
161 
162 extern void
163 _mesa_print_arrays(struct gl_context *ctx);
164 
165 extern void
166 _mesa_init_varray(struct gl_context *ctx);
167 
168 extern void
169 _mesa_free_varray_data(struct gl_context *ctx);
170 
171 #endif
172