varray.h revision af69d88d
17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 44a49301eSmrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 54a49301eSmrg * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 67117f1b4Smrg * 77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 87117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 97117f1b4Smrg * to deal in the Software without restriction, including without limitation 107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 127117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 137117f1b4Smrg * 147117f1b4Smrg * The above copyright notice and this permission notice shall be included 157117f1b4Smrg * in all copies or substantial portions of the Software. 167117f1b4Smrg * 177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 247117f1b4Smrg */ 257117f1b4Smrg 267117f1b4Smrg 277117f1b4Smrg#ifndef VARRAY_H 287117f1b4Smrg#define VARRAY_H 297117f1b4Smrg 307117f1b4Smrg 313464ebd5Sriastradh#include "glheader.h" 32af69d88dSmrg#include "bufferobj.h" 333464ebd5Sriastradh 343464ebd5Sriastradhstruct gl_client_array; 353464ebd5Sriastradhstruct gl_context; 363464ebd5Sriastradh 373464ebd5Sriastradh 383464ebd5Sriastradh/** 393464ebd5Sriastradh * Compute the index of the last array element that can be safely accessed in 403464ebd5Sriastradh * a vertex array. We can really only do this when the array lives in a VBO. 413464ebd5Sriastradh * The array->_MaxElement field will be updated. 423464ebd5Sriastradh * Later in glDrawArrays/Elements/etc we can do some bounds checking. 433464ebd5Sriastradh */ 44af69d88dSmrgstatic inline void 453464ebd5Sriastradh_mesa_update_array_max_element(struct gl_client_array *array) 463464ebd5Sriastradh{ 473464ebd5Sriastradh assert(array->Enabled); 483464ebd5Sriastradh 493464ebd5Sriastradh if (array->BufferObj->Name) { 503464ebd5Sriastradh GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr; 513464ebd5Sriastradh GLsizeiptrARB bufSize = (GLsizeiptrARB) array->BufferObj->Size; 523464ebd5Sriastradh 533464ebd5Sriastradh if (offset < bufSize) { 54af69d88dSmrg const GLuint stride = array->StrideB ? 55af69d88dSmrg array->StrideB : array->_ElementSize; 56af69d88dSmrg array->_MaxElement = (bufSize - offset + stride 57af69d88dSmrg - array->_ElementSize) / stride; 583464ebd5Sriastradh } 593464ebd5Sriastradh else { 603464ebd5Sriastradh array->_MaxElement = 0; 613464ebd5Sriastradh } 623464ebd5Sriastradh } 633464ebd5Sriastradh else { 643464ebd5Sriastradh /* user-space array, no idea how big it is */ 653464ebd5Sriastradh array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */ 663464ebd5Sriastradh } 673464ebd5Sriastradh} 683464ebd5Sriastradh 697117f1b4Smrg 70af69d88dSmrg/** 71af69d88dSmrg * Returns a pointer to the vertex attribute data in a client array, 72af69d88dSmrg * or the offset into the vertex buffer for an array that resides in 73af69d88dSmrg * a vertex buffer. 74af69d88dSmrg */ 75af69d88dSmrgstatic inline const GLubyte * 76af69d88dSmrg_mesa_vertex_attrib_address(const struct gl_vertex_attrib_array *array, 77af69d88dSmrg const struct gl_vertex_buffer_binding *binding) 78af69d88dSmrg{ 79af69d88dSmrg if (_mesa_is_bufferobj(binding->BufferObj)) 80af69d88dSmrg return (const GLubyte *) (binding->Offset + array->RelativeOffset); 81af69d88dSmrg else 82af69d88dSmrg return array->Ptr; 83af69d88dSmrg} 847117f1b4Smrg 85af69d88dSmrg/** 86af69d88dSmrg * Sets the fields in a gl_client_array to values derived from a 87af69d88dSmrg * gl_vertex_attrib_array and a gl_vertex_buffer_binding. 88af69d88dSmrg */ 89af69d88dSmrgstatic inline void 90af69d88dSmrg_mesa_update_client_array(struct gl_context *ctx, 91af69d88dSmrg struct gl_client_array *dst, 92af69d88dSmrg const struct gl_vertex_attrib_array *src, 93af69d88dSmrg const struct gl_vertex_buffer_binding *binding) 94af69d88dSmrg{ 95af69d88dSmrg dst->Size = src->Size; 96af69d88dSmrg dst->Type = src->Type; 97af69d88dSmrg dst->Format = src->Format; 98af69d88dSmrg dst->Stride = src->Stride; 99af69d88dSmrg dst->StrideB = binding->Stride; 100af69d88dSmrg dst->Ptr = _mesa_vertex_attrib_address(src, binding); 101af69d88dSmrg dst->Enabled = src->Enabled; 102af69d88dSmrg dst->Normalized = src->Normalized; 103af69d88dSmrg dst->Integer = src->Integer; 104af69d88dSmrg dst->InstanceDivisor = binding->InstanceDivisor; 105af69d88dSmrg dst->_ElementSize = src->_ElementSize; 106af69d88dSmrg _mesa_reference_buffer_object(ctx, &dst->BufferObj, binding->BufferObj); 107af69d88dSmrg} 1087117f1b4Smrg 109af69d88dSmrgstatic inline bool 110af69d88dSmrg_mesa_attr_zero_aliases_vertex(struct gl_context *ctx) 111af69d88dSmrg{ 112af69d88dSmrg const bool is_forward_compatible_context = 113af69d88dSmrg ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT; 114af69d88dSmrg 115af69d88dSmrg /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES 116af69d88dSmrg * 2.0. Note that we cannot just check for API_OPENGL_COMPAT here because 117af69d88dSmrg * that will erroneously allow this usage in a 3.0 forward-compatible 118af69d88dSmrg * context too. 119af69d88dSmrg */ 120af69d88dSmrg return (ctx->API == API_OPENGLES 121af69d88dSmrg || (ctx->API == API_OPENGL_COMPAT 122af69d88dSmrg && !is_forward_compatible_context)); 123af69d88dSmrg} 1247117f1b4Smrg 1257117f1b4Smrgextern void GLAPIENTRY 126af69d88dSmrg_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, 127af69d88dSmrg const GLvoid *ptr); 1287117f1b4Smrg 1297117f1b4Smrg 1307117f1b4Smrgextern void GLAPIENTRY 1317117f1b4Smrg_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 1327117f1b4Smrg 1337117f1b4Smrg 1347117f1b4Smrgextern void GLAPIENTRY 1357117f1b4Smrg_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); 1367117f1b4Smrg 1377117f1b4Smrg 1387117f1b4Smrgextern void GLAPIENTRY 1397117f1b4Smrg_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 1407117f1b4Smrg 1417117f1b4Smrg 1427117f1b4Smrgextern void GLAPIENTRY 1437117f1b4Smrg_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, 1447117f1b4Smrg const GLvoid *ptr); 1457117f1b4Smrg 1467117f1b4Smrg 1477117f1b4Smrgextern void GLAPIENTRY 1487117f1b4Smrg_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr); 1497117f1b4Smrg 1507117f1b4Smrg 1517117f1b4Smrgextern void GLAPIENTRY 1527117f1b4Smrg_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, 1537117f1b4Smrg GLsizei count, const GLvoid *ptr); 1547117f1b4Smrg 1557117f1b4Smrg 1567117f1b4Smrgextern void GLAPIENTRY 1577117f1b4Smrg_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, 1587117f1b4Smrg const GLvoid *ptr); 1597117f1b4Smrg 1607117f1b4Smrg 1617117f1b4Smrgextern void GLAPIENTRY 1627117f1b4Smrg_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, 1637117f1b4Smrg const GLvoid *ptr); 1647117f1b4Smrg 1657117f1b4Smrg 1667117f1b4Smrgextern void GLAPIENTRY 1677117f1b4Smrg_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, 1687117f1b4Smrg const GLvoid *ptr); 1697117f1b4Smrg 1707117f1b4Smrg 1717117f1b4Smrgextern void GLAPIENTRY 1727117f1b4Smrg_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, 1737117f1b4Smrg GLsizei count, const GLvoid *ptr); 1747117f1b4Smrg 1757117f1b4Smrg 1767117f1b4Smrgextern void GLAPIENTRY 1777117f1b4Smrg_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr); 1787117f1b4Smrg 1797117f1b4Smrg 1807117f1b4Smrgextern void GLAPIENTRY 181af69d88dSmrg_mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 1827117f1b4Smrg 1837117f1b4Smrg 1847117f1b4Smrgextern void GLAPIENTRY 185af69d88dSmrg_mesa_SecondaryColorPointer(GLint size, GLenum type, 1867117f1b4Smrg GLsizei stride, const GLvoid *ptr); 1877117f1b4Smrg 1887117f1b4Smrg 189c1f859d4Smrgextern void GLAPIENTRY 190af69d88dSmrg_mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr); 191c1f859d4Smrg 192c1f859d4Smrg 1937117f1b4Smrgextern void GLAPIENTRY 194af69d88dSmrg_mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type, 1957117f1b4Smrg GLboolean normalized, GLsizei stride, 1967117f1b4Smrg const GLvoid *pointer); 1977117f1b4Smrg 1983464ebd5Sriastradhvoid GLAPIENTRY 1993464ebd5Sriastradh_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type, 2003464ebd5Sriastradh GLsizei stride, const GLvoid *ptr); 2013464ebd5Sriastradh 2023464ebd5Sriastradh 2033464ebd5Sriastradhextern void GLAPIENTRY 204af69d88dSmrg_mesa_EnableVertexAttribArray(GLuint index); 2053464ebd5Sriastradh 2063464ebd5Sriastradh 2073464ebd5Sriastradhextern void GLAPIENTRY 208af69d88dSmrg_mesa_DisableVertexAttribArray(GLuint index); 2093464ebd5Sriastradh 2103464ebd5Sriastradh 2113464ebd5Sriastradhextern void GLAPIENTRY 212af69d88dSmrg_mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params); 2133464ebd5Sriastradh 2143464ebd5Sriastradh 2153464ebd5Sriastradhextern void GLAPIENTRY 216af69d88dSmrg_mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); 2173464ebd5Sriastradh 2183464ebd5Sriastradh 2193464ebd5Sriastradhextern void GLAPIENTRY 220af69d88dSmrg_mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params); 2213464ebd5Sriastradh 2223464ebd5Sriastradh 2233464ebd5Sriastradhextern void GLAPIENTRY 2243464ebd5Sriastradh_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params); 2253464ebd5Sriastradh 2263464ebd5Sriastradh 2273464ebd5Sriastradhextern void GLAPIENTRY 2283464ebd5Sriastradh_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params); 2293464ebd5Sriastradh 2303464ebd5Sriastradh 2313464ebd5Sriastradhextern void GLAPIENTRY 232af69d88dSmrg_mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer); 2333464ebd5Sriastradh 2347117f1b4Smrg 2357117f1b4Smrgextern void GLAPIENTRY 2367117f1b4Smrg_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); 2377117f1b4Smrg 2387117f1b4Smrg 2397117f1b4Smrgextern void GLAPIENTRY 240af69d88dSmrg_mesa_MultiDrawArrays( GLenum mode, const GLint *first, 2413464ebd5Sriastradh const GLsizei *count, GLsizei primcount ); 2427117f1b4Smrg 2437117f1b4Smrgextern void GLAPIENTRY 2447117f1b4Smrg_mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, 2457117f1b4Smrg const GLvoid **indices, GLsizei primcount ); 2467117f1b4Smrg 2474a49301eSmrgextern void GLAPIENTRY 2484a49301eSmrg_mesa_MultiDrawElementsBaseVertex( GLenum mode, 2494a49301eSmrg const GLsizei *count, GLenum type, 2504a49301eSmrg const GLvoid **indices, GLsizei primcount, 2514a49301eSmrg const GLint *basevertex); 2527117f1b4Smrg 2537117f1b4Smrgextern void GLAPIENTRY 2547117f1b4Smrg_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, 2557117f1b4Smrg const GLsizei * count, 2567117f1b4Smrg GLsizei primcount, GLint modestride ); 2577117f1b4Smrg 2587117f1b4Smrg 2597117f1b4Smrgextern void GLAPIENTRY 2607117f1b4Smrg_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, 2617117f1b4Smrg GLenum type, const GLvoid * const * indices, 2627117f1b4Smrg GLsizei primcount, GLint modestride ); 2637117f1b4Smrg 264c1f859d4Smrgextern void GLAPIENTRY 265c1f859d4Smrg_mesa_LockArraysEXT(GLint first, GLsizei count); 266c1f859d4Smrg 267c1f859d4Smrgextern void GLAPIENTRY 268c1f859d4Smrg_mesa_UnlockArraysEXT( void ); 2697117f1b4Smrg 2704a49301eSmrg 2714a49301eSmrgextern void GLAPIENTRY 2724a49301eSmrg_mesa_DrawArrays(GLenum mode, GLint first, GLsizei count); 2734a49301eSmrg 274af69d88dSmrgextern void GLAPIENTRY 275af69d88dSmrg_mesa_DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, 276af69d88dSmrg GLsizei primcount); 277af69d88dSmrg 2784a49301eSmrgextern void GLAPIENTRY 2794a49301eSmrg_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, 2804a49301eSmrg const GLvoid *indices); 2814a49301eSmrg 2824a49301eSmrgextern void GLAPIENTRY 2834a49301eSmrg_mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, 2844a49301eSmrg GLenum type, const GLvoid *indices); 2854a49301eSmrg 2864a49301eSmrgextern void GLAPIENTRY 2874a49301eSmrg_mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, 2884a49301eSmrg const GLvoid *indices, GLint basevertex); 2894a49301eSmrg 2904a49301eSmrgextern void GLAPIENTRY 2914a49301eSmrg_mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, 2924a49301eSmrg GLsizei count, GLenum type, 2934a49301eSmrg const GLvoid *indices, 2944a49301eSmrg GLint basevertex); 2954a49301eSmrg 296af69d88dSmrgextern void GLAPIENTRY 297af69d88dSmrg_mesa_DrawTransformFeedback(GLenum mode, GLuint name); 298af69d88dSmrg 2993464ebd5Sriastradhextern void GLAPIENTRY 3003464ebd5Sriastradh_mesa_PrimitiveRestartIndex(GLuint index); 3013464ebd5Sriastradh 3023464ebd5Sriastradh 3033464ebd5Sriastradhextern void GLAPIENTRY 3043464ebd5Sriastradh_mesa_VertexAttribDivisor(GLuint index, GLuint divisor); 3053464ebd5Sriastradh 306af69d88dSmrgextern unsigned 307af69d88dSmrg_mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type); 308af69d88dSmrg 309af69d88dSmrgextern void GLAPIENTRY 310af69d88dSmrg_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, 311af69d88dSmrg GLsizei stride); 312af69d88dSmrg 313af69d88dSmrgextern void GLAPIENTRY 314af69d88dSmrg_mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers, 315af69d88dSmrg const GLintptr *offsets, const GLsizei *strides); 316af69d88dSmrg 317af69d88dSmrgextern void GLAPIENTRY 318af69d88dSmrg_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, 319af69d88dSmrg GLboolean normalized, GLuint relativeOffset); 320af69d88dSmrg 321af69d88dSmrgextern void GLAPIENTRY 322af69d88dSmrg_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, 323af69d88dSmrg GLuint relativeOffset); 324af69d88dSmrg 325af69d88dSmrgextern void GLAPIENTRY 326af69d88dSmrg_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, 327af69d88dSmrg GLuint relativeOffset); 328af69d88dSmrg 329af69d88dSmrgextern void GLAPIENTRY 330af69d88dSmrg_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex); 331af69d88dSmrg 332af69d88dSmrgextern void GLAPIENTRY 333af69d88dSmrg_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor); 334af69d88dSmrg 3354a49301eSmrg 3364a49301eSmrgextern void 3373464ebd5Sriastradh_mesa_copy_client_array(struct gl_context *ctx, 3384a49301eSmrg struct gl_client_array *dst, 3394a49301eSmrg struct gl_client_array *src); 3404a49301eSmrg 341af69d88dSmrgextern void 342af69d88dSmrg_mesa_copy_vertex_attrib_array(struct gl_context *ctx, 343af69d88dSmrg struct gl_vertex_attrib_array *dst, 344af69d88dSmrg const struct gl_vertex_attrib_array *src); 345af69d88dSmrg 346af69d88dSmrgextern void 347af69d88dSmrg_mesa_copy_vertex_buffer_binding(struct gl_context *ctx, 348af69d88dSmrg struct gl_vertex_buffer_binding *dst, 349af69d88dSmrg const struct gl_vertex_buffer_binding *src); 3504a49301eSmrg 3514a49301eSmrgextern void 3523464ebd5Sriastradh_mesa_print_arrays(struct gl_context *ctx); 3534a49301eSmrg 3547117f1b4Smrgextern void 3553464ebd5Sriastradh_mesa_init_varray( struct gl_context * ctx ); 3567117f1b4Smrg 3574a49301eSmrgextern void 3583464ebd5Sriastradh_mesa_free_varray_data(struct gl_context *ctx); 3594a49301eSmrg 3607117f1b4Smrg#endif 361