@@ -47,6 +47,16 @@ class Mesh : public Ref
4747 POINTS = GL_POINTS
4848 };
4949
50+ /* *
51+ * Defines mapping access/usage.
52+ */
53+ enum MapAccess
54+ {
55+ MAP_READ_ONLY = GL_READ_ONLY,
56+ MAP_WRITE_ONLY = GL_WRITE_ONLY,
57+ MAP_READ_WRITE = GL_READ_WRITE
58+ };
59+
5060 /* *
5161 * Constructs a new mesh with the specified vertex format.
5262 *
@@ -200,14 +210,47 @@ class Mesh : public Ref
200210 */
201211 void setPrimitiveType (Mesh::PrimitiveType type);
202212
213+ /* *
214+ * Maps the vertex buffer for the specified access.
215+ *
216+ * Mapping vertex data causes a synchronizing issue. To avoid gpu idle
217+ * If GPU is still working with the buffer object, mapVertexBuffer will not
218+ * return until GPU finishes its job with the corresponding buffer object.
219+ *
220+ * To avoid waiting (idle), you can call first setVertexBuffer with NULL pointer,
221+ * then call mapVertexBuffer(). In this case, the previous data will be discarded
222+ * and mapVertexBuffer() returns a new allocated pointer immediately even if GPU is
223+ * still working with the previous data.
224+ *
225+ * However, this method is valid only if you want to update entire data set because
226+ * you discard the previous data. If you want to change only portion of data or to
227+ * read data, you better not release the previous data.
228+ *
229+ * After modifying the data of VBO, it must be unmapped the buffer object from the client's
230+ * memory. unmapVertexBuffer returns true if success. When it returns false, the contents of
231+ * vertex buffer become corrupted while the buffer was mapped. The corruption results from screen
232+ * resolution change or window system specific events. In this case, the data must be resubmitted.
233+ *
234+ * @param access The access for which the data can be use. Ex. read, write, read_write.
235+ * @return The mapped vertex buffer
236+ */
237+ void * mapVertexBuffer (Mesh::MapAccess access);
238+
239+ /* *
240+ * Unmaps the vertex buffer.
241+ *
242+ * @return false if unmapping buffer was unsuccessful
243+ */
244+ bool unmapVertexBuffer ();
245+
203246 /* *
204247 * Sets the specified vertex data into the mapped vertex buffer.
205248 *
206249 * @param vertexData The vertex data to be set.
207250 * @param vertexStart The index of the starting vertex (0 by default).
208251 * @param vertexCount The number of vertices to be set (default is 0, for all vertices).
209252 */
210- void setVertexData (const float * vertexData, unsigned int vertexStart = 0 , unsigned int vertexCount = 0 );
253+ void setVertexData (const void * vertexData, unsigned int vertexStart = 0 , unsigned int vertexCount = 0 );
211254
212255 /* *
213256 * Creates and adds a new part of primitive data defining how the vertices are connected.
0 commit comments