2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2005 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Brecht Van Lommel.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file GPU_buffers.h
32 #ifndef __GPU_BUFFERS_H__
33 #define __GPU_BUFFERS_H__
36 /*#define DEBUG_VBO(X) printf(X)*/
47 struct GPUVertPointLink;
49 typedef struct GPUBuffer {
50 int size; /* in bytes */
51 void *pointer; /* used with vertex arrays */
52 unsigned int id; /* used with vertex buffer objects */
55 typedef struct GPUBufferMaterial {
56 /* range of points used for this material */
60 /* original material index */
64 /* meshes are split up by material since changing materials requires
65 * GL state changes that can't occur in the middle of drawing an
68 * some simplifying assumptions are made:
69 * - all quads are treated as two triangles.
70 * - no vertex sharing is used; each triangle gets its own copy of the
71 * vertices it uses (this makes it easy to deal with a vertex used
72 * by faces with different properties, such as smooth/solid shading,
73 * different MCols, etc.)
75 * to avoid confusion between the original MVert vertices and the
76 * arrays of OpenGL vertices, the latter are referred to here and in
77 * the source as `points'. similarly, the OpenGL triangles generated
78 * for MFaces are referred to as triangles rather than faces.
80 typedef struct GPUDrawObject {
88 /* for each triangle, the original MFace index */
89 int *triangle_to_mface;
91 /* for each original vertex, the list of related points */
92 struct GPUVertPointLink *vert_points;
93 /* storage for the vert_points lists */
94 struct GPUVertPointLink *vert_points_mem;
95 int vert_points_usage;
99 GPUBufferMaterial *materials;
102 int tot_triangle_point;
105 /* caches of the original DerivedMesh values */
109 /* if there was a failure allocating some buffer, use old
114 /* used for GLSL materials */
115 typedef struct GPUAttrib {
121 void GPU_global_buffer_pool_free(void);
123 GPUBuffer *GPU_buffer_alloc(int size);
124 void GPU_buffer_free(GPUBuffer *buffer);
126 GPUDrawObject *GPU_drawobject_new(struct DerivedMesh *dm );
127 void GPU_drawobject_free(struct DerivedMesh *dm );
129 /* called before drawing */
130 void GPU_vertex_setup(struct DerivedMesh *dm );
131 void GPU_normal_setup(struct DerivedMesh *dm );
132 void GPU_uv_setup(struct DerivedMesh *dm );
133 void GPU_color_setup(struct DerivedMesh *dm );
134 void GPU_edge_setup(struct DerivedMesh *dm ); /* does not mix with other data */
135 void GPU_uvedge_setup(struct DerivedMesh *dm );
136 int GPU_attrib_element_size( GPUAttrib data[], int numdata );
137 void GPU_interleaved_attrib_setup( GPUBuffer *buffer, GPUAttrib data[], int numdata );
139 /* can't lock more than one buffer at once */
140 void *GPU_buffer_lock( GPUBuffer *buffer );
141 void *GPU_buffer_lock_stream( GPUBuffer *buffer );
142 void GPU_buffer_unlock( GPUBuffer *buffer );
144 /* upload three unsigned chars, representing RGB colors, for each vertex. Resets dm->drawObject->colType to -1 */
145 void GPU_color3_upload(struct DerivedMesh *dm, unsigned char *data );
146 /* switch color rendering on=1/off=0 */
147 void GPU_color_switch( int mode );
149 /* used for drawing edges */
150 void GPU_buffer_draw_elements( GPUBuffer *elements, unsigned int mode, int start, int count );
152 /* called after drawing */
153 void GPU_buffer_unbind(void);
155 /* used to check whether to use the old (without buffers) code */
156 int GPU_buffer_legacy(struct DerivedMesh *dm );
158 /* Buffers for non-DerivedMesh drawing */
159 typedef struct GPU_Buffers GPU_Buffers;
161 GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
162 struct MFace *mface, struct MVert *mvert,
163 int *face_indices, int totface);
165 void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert,
166 int *vert_indices, int totvert, const float *vmask);
168 GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid,
169 unsigned int **grid_hidden, int gridsize);
171 void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids,
172 const struct DMFlagMat *grid_flag_mats,
173 int *grid_indices, int totgrid, const struct CCGKey *key);
175 void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial);
177 void GPU_free_buffers(GPU_Buffers *buffers);