1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Mesa 3-D graphics library 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5bf215546Sopenharmony_ci * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef VARRAY_H 28bf215546Sopenharmony_ci#define VARRAY_H 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "bufferobj.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_cistruct gl_interleaved_layout { 33bf215546Sopenharmony_ci bool tflag, cflag, nflag; /* enable/disable flags */ 34bf215546Sopenharmony_ci int tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ 35bf215546Sopenharmony_ci GLenum ctype; /* color type */ 36bf215546Sopenharmony_ci int coffset, noffset, voffset; /* color, normal, vertex offsets */ 37bf215546Sopenharmony_ci int toffset; /* always zero */ 38bf215546Sopenharmony_ci int defstride; /* default stride */ 39bf215546Sopenharmony_ci}; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cibool 42bf215546Sopenharmony_ci_mesa_get_interleaved_layout(GLenum format, 43bf215546Sopenharmony_ci struct gl_interleaved_layout *layout); 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_civoid 46bf215546Sopenharmony_ci_mesa_set_vertex_format(struct gl_vertex_format *vertex_format, 47bf215546Sopenharmony_ci GLubyte size, GLenum16 type, GLenum16 format, 48bf215546Sopenharmony_ci GLboolean normalized, GLboolean integer, 49bf215546Sopenharmony_ci GLboolean doubles); 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/** 53bf215546Sopenharmony_ci * Returns a pointer to the vertex attribute data in a client array, 54bf215546Sopenharmony_ci * or the offset into the vertex buffer for an array that resides in 55bf215546Sopenharmony_ci * a vertex buffer. 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_cistatic inline const GLubyte * 58bf215546Sopenharmony_ci_mesa_vertex_attrib_address(const struct gl_array_attributes *array, 59bf215546Sopenharmony_ci const struct gl_vertex_buffer_binding *binding) 60bf215546Sopenharmony_ci{ 61bf215546Sopenharmony_ci if (binding->BufferObj) 62bf215546Sopenharmony_ci return (const GLubyte *) (binding->Offset + array->RelativeOffset); 63bf215546Sopenharmony_ci else 64bf215546Sopenharmony_ci return array->Ptr; 65bf215546Sopenharmony_ci} 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_cistatic inline bool 69bf215546Sopenharmony_ci_mesa_attr_zero_aliases_vertex(const struct gl_context *ctx) 70bf215546Sopenharmony_ci{ 71bf215546Sopenharmony_ci return ctx->_AttribZeroAliasesVertex; 72bf215546Sopenharmony_ci} 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ciextern void 76bf215546Sopenharmony_ci_mesa_update_array_format(struct gl_context *ctx, 77bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 78bf215546Sopenharmony_ci gl_vert_attrib attrib, GLint size, GLenum type, 79bf215546Sopenharmony_ci GLenum format, GLboolean normalized, 80bf215546Sopenharmony_ci GLboolean integer, GLboolean doubles, 81bf215546Sopenharmony_ci GLuint relativeOffset); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ciextern void 84bf215546Sopenharmony_ci_mesa_enable_vertex_array_attribs(struct gl_context *ctx, 85bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 86bf215546Sopenharmony_ci GLbitfield attrib_bits); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_cistatic inline void 89bf215546Sopenharmony_ci_mesa_enable_vertex_array_attrib(struct gl_context *ctx, 90bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 91bf215546Sopenharmony_ci gl_vert_attrib attrib) 92bf215546Sopenharmony_ci{ 93bf215546Sopenharmony_ci assert(attrib < VERT_ATTRIB_MAX); 94bf215546Sopenharmony_ci _mesa_enable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib)); 95bf215546Sopenharmony_ci} 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ciextern void 99bf215546Sopenharmony_ci_mesa_disable_vertex_array_attribs(struct gl_context *ctx, 100bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 101bf215546Sopenharmony_ci GLbitfield attrib_bits); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_cistatic inline void 104bf215546Sopenharmony_ci_mesa_disable_vertex_array_attrib(struct gl_context *ctx, 105bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 106bf215546Sopenharmony_ci gl_vert_attrib attrib) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci assert(attrib < VERT_ATTRIB_MAX); 109bf215546Sopenharmony_ci _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib)); 110bf215546Sopenharmony_ci} 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ciextern void 114bf215546Sopenharmony_ci_mesa_vertex_attrib_binding(struct gl_context *ctx, 115bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 116bf215546Sopenharmony_ci gl_vert_attrib attribIndex, 117bf215546Sopenharmony_ci GLuint bindingIndex); 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ciextern void 121bf215546Sopenharmony_ci_mesa_bind_vertex_buffer(struct gl_context *ctx, 122bf215546Sopenharmony_ci struct gl_vertex_array_object *vao, 123bf215546Sopenharmony_ci GLuint index, 124bf215546Sopenharmony_ci struct gl_buffer_object *vbo, 125bf215546Sopenharmony_ci GLintptr offset, GLsizei stride, 126bf215546Sopenharmony_ci bool offset_is_int32, bool take_vbo_ownership); 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_cistatic inline unsigned 129bf215546Sopenharmony_ci_mesa_get_prim_restart_index(bool fixed_index, unsigned restart_index, 130bf215546Sopenharmony_ci unsigned index_size) 131bf215546Sopenharmony_ci{ 132bf215546Sopenharmony_ci /* The index_size parameter is meant to be in bytes. */ 133bf215546Sopenharmony_ci assert(index_size == 1 || index_size == 2 || index_size == 4); 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci /* From the OpenGL 4.3 core specification, page 302: 136bf215546Sopenharmony_ci * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are 137bf215546Sopenharmony_ci * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX 138bf215546Sopenharmony_ci * is used." 139bf215546Sopenharmony_ci */ 140bf215546Sopenharmony_ci if (fixed_index) { 141bf215546Sopenharmony_ci /* 1 -> 0xff, 2 -> 0xffff, 4 -> 0xffffffff */ 142bf215546Sopenharmony_ci return 0xffffffffu >> 8 * (4 - index_size); 143bf215546Sopenharmony_ci } 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci return restart_index; 146bf215546Sopenharmony_ci} 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_cistatic inline unsigned 149bf215546Sopenharmony_ci_mesa_primitive_restart_index(const struct gl_context *ctx, 150bf215546Sopenharmony_ci unsigned index_size) 151bf215546Sopenharmony_ci{ 152bf215546Sopenharmony_ci return _mesa_get_prim_restart_index(ctx->Array.PrimitiveRestartFixedIndex, 153bf215546Sopenharmony_ci ctx->Array.RestartIndex, index_size); 154bf215546Sopenharmony_ci} 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_civoid 157bf215546Sopenharmony_ci_mesa_InternalBindVertexBuffers(struct gl_context *ctx, 158bf215546Sopenharmony_ci const struct glthread_attrib_binding *buffers, 159bf215546Sopenharmony_ci GLbitfield buffer_mask, 160bf215546Sopenharmony_ci GLboolean restore_pointers); 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ciextern void 163bf215546Sopenharmony_ci_mesa_print_arrays(struct gl_context *ctx); 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ciextern void 166bf215546Sopenharmony_ci_mesa_init_varray(struct gl_context *ctx); 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ciextern void 169bf215546Sopenharmony_ci_mesa_free_varray_data(struct gl_context *ctx); 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci#endif 172