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)*/
49 struct GPUVertPointLink;
52 typedef struct GPUBuffer {
53 int size; /* in bytes */
54 void *pointer; /* used with vertex arrays */
55 unsigned int id; /* used with vertex buffer objects */
58 typedef struct GPUBufferMaterial {
59 /* range of points used for this material */
63 /* original material index */
67 /* meshes are split up by material since changing materials requires
68 * GL state changes that can't occur in the middle of drawing an
71 * some simplifying assumptions are made:
72 * - all quads are treated as two triangles.
73 * - no vertex sharing is used; each triangle gets its own copy of the
74 * vertices it uses (this makes it easy to deal with a vertex used
75 * by faces with different properties, such as smooth/solid shading,
76 * different MCols, etc.)
78 * to avoid confusion between the original MVert vertices and the
79 * arrays of OpenGL vertices, the latter are referred to here and in
80 * the source as `points'. similarly, the OpenGL triangles generated
81 * for MFaces are referred to as triangles rather than faces.
83 typedef struct GPUDrawObject {
91 /* for each triangle, the original MFace index */
92 int *triangle_to_mface;
94 /* for each original vertex, the list of related points */
95 struct GPUVertPointLink *vert_points;
96 /* storage for the vert_points lists */
97 struct GPUVertPointLink *vert_points_mem;
98 int vert_points_usage;
102 GPUBufferMaterial *materials;
105 int tot_triangle_point;
108 /* caches of the original DerivedMesh values */
112 /* if there was a failure allocating some buffer, use old
117 /* used for GLSL materials */
118 typedef struct GPUAttrib {
124 void GPU_global_buffer_pool_free(void);
126 GPUBuffer *GPU_buffer_alloc(int size);
127 void GPU_buffer_free(GPUBuffer *buffer);
129 GPUDrawObject *GPU_drawobject_new(struct DerivedMesh *dm);
130 void GPU_drawobject_free(struct DerivedMesh *dm);
132 /* called before drawing */
133 void GPU_vertex_setup(struct DerivedMesh *dm);
134 void GPU_normal_setup(struct DerivedMesh *dm);
135 void GPU_uv_setup(struct DerivedMesh *dm);
136 /* colType is the cddata MCol type to use! */
137 void GPU_color_setup(struct DerivedMesh *dm, int colType);
138 void GPU_edge_setup(struct DerivedMesh *dm); /* does not mix with other data */
139 void GPU_uvedge_setup(struct DerivedMesh *dm);
140 int GPU_attrib_element_size(GPUAttrib data[], int numdata);
141 void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numdata);
143 /* can't lock more than one buffer at once */
144 void *GPU_buffer_lock(GPUBuffer *buffer);
145 void *GPU_buffer_lock_stream(GPUBuffer *buffer);
146 void GPU_buffer_unlock(GPUBuffer *buffer);
148 /* switch color rendering on=1/off=0 */
149 void GPU_color_switch(int mode);
151 /* used for drawing edges */
152 void GPU_buffer_draw_elements(GPUBuffer *elements, unsigned int mode, int start, int count);
154 /* called after drawing */
155 void GPU_buffer_unbind(void);
157 /* used to check whether to use the old (without buffers) code */
158 int GPU_buffer_legacy(struct DerivedMesh *dm);
160 /* Buffers for non-DerivedMesh drawing */
161 typedef struct GPU_Buffers GPU_Buffers;
163 GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
164 struct MFace *mface, struct MVert *mvert,
165 int *face_indices, int totface);
167 void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert,
168 int *vert_indices, int totvert, const float *vmask,
169 int (*face_vert_indices)[4], int show_diffuse_color);
171 GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid,
172 unsigned int **grid_hidden, int gridsize);
174 GPU_Buffers *GPU_build_bmesh_buffers(int smooth_shading);
176 void GPU_update_bmesh_buffers(GPU_Buffers *buffers,
178 struct GHash *bm_faces,
179 struct GHash *bm_unique_verts,
180 struct GHash *bm_other_verts);
182 void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids,
183 const struct DMFlagMat *grid_flag_mats,
184 int *grid_indices, int totgrid, const struct CCGKey *key,
185 int show_diffuse_color);
187 void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial,
190 int GPU_buffers_diffuse_changed(GPU_Buffers *buffers, int show_diffuse_color);
192 void GPU_free_buffers(GPU_Buffers *buffers);