1 | <HTML> |
---|
2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
3 | <!-- Created on , 12 2006 by texi2html 1.64 --> |
---|
4 | <!-- |
---|
5 | Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) |
---|
6 | Karl Berry <karl@freefriends.org> |
---|
7 | Olaf Bachmann <obachman@mathematik.uni-kl.de> |
---|
8 | and many others. |
---|
9 | Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de> |
---|
10 | Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> |
---|
11 | |
---|
12 | --> |
---|
13 | <HEAD> |
---|
14 | <TITLE>OGRE Manual v1.2.0 ('Dagon'): Updating Vertex Buffers</TITLE> |
---|
15 | |
---|
16 | <META NAME="description" CONTENT="OGRE Manual v1.2.0 ('Dagon'): Updating Vertex Buffers"> |
---|
17 | <META NAME="keywords" CONTENT="OGRE Manual v1.2.0 ('Dagon'): Updating Vertex Buffers"> |
---|
18 | <META NAME="resource-type" CONTENT="document"> |
---|
19 | <META NAME="distribution" CONTENT="global"> |
---|
20 | <META NAME="Generator" CONTENT="texi2html 1.64"> |
---|
21 | <LINK TYPE="text/css" rel="stylesheet" href="../style.css"> |
---|
22 | </HEAD> |
---|
23 | |
---|
24 | <BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"> |
---|
25 | |
---|
26 | <A NAME="SEC244"></A> |
---|
27 | <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> |
---|
28 | <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_50.html#SEC241"> < </A>]</TD> |
---|
29 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_47.html#SEC237"> Up </A>]</TD> |
---|
30 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_52.html#SEC245"> > </A>]</TD> |
---|
31 | <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD> |
---|
32 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD> |
---|
33 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD> |
---|
34 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD> |
---|
35 | </TR></TABLE> |
---|
36 | <HR SIZE=1> |
---|
37 | <H3> 5.6.4 Updating Vertex Buffers </H3> |
---|
38 | <!--docid::SEC244::--> |
---|
39 | The complexity of updating a vertex buffer entirely depends on how its contents are laid out. You can lock a buffer (See section <A HREF="manual_45.html#SEC234">5.4 Locking buffers</A>), but how you write data into it vert much depends on what it contains.<BR><BR> |
---|
40 | Lets start with a vert simple example. Lets say you have a buffer which only contains vertex positions, so it only contains sets of 3 floating point numbers per vertex. In this case, all you need to do to write data into it is: |
---|
41 | <TABLE><tr><td> </td><td class=example><pre>Real* pReal = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
42 | </pre></td></tr></table>... then you just write positions in chunks of 3 reals. If you have other floating point data in there, it's a little more complex but the principle is largely the same, you just need to write alternate elements. But what if you have elements of different types, or you need to derive how to write the vertex data from the elements themselves? Well, there are some useful methods on the VertexElement class to help you out.<BR><BR> |
---|
43 | Firstly, you lock the buffer but assign the result to a unsigned char* rather than a specific type. Then, for each element whcih is sourcing from this buffer (which you can find out by calling VertexDeclaration::findElementsBySource) you call VertexElement::baseVertexPointerToElement. This offsets a pointer which points at the base of a vertex in a buffer to the beginning of the element in question, and allows you to use a pointer of the right type to boot. Here's a full example: |
---|
44 | <TABLE><tr><td> </td><td class=example><pre>// Get base pointer |
---|
45 | unsigned char* pVert = static_cast<unsigned char*>(vbuf->lock(HardwareBuffer::HBL_READ_ONLY)); |
---|
46 | Real* pReal; |
---|
47 | for (size_t v = 0; v < vertexCount; ++v) |
---|
48 | { |
---|
49 | // Get elements |
---|
50 | VertexDeclaration::VertexElementList elems = decl->findElementsBySource(bufferIdx); |
---|
51 | VertexDeclaration::VertexElementList::iterator i, iend; |
---|
52 | for (i = elems.begin(); i != elems.end(); ++i) |
---|
53 | { |
---|
54 | VertexElement& elem = *i; |
---|
55 | if (elem.getSemantic() == VES_POSITION) |
---|
56 | { |
---|
57 | elem.baseVertexPointerToElement(pVert, &pReal); |
---|
58 | // write position using pReal |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | ... |
---|
63 | |
---|
64 | |
---|
65 | } |
---|
66 | pVert += vbuf->getVertexSize(); |
---|
67 | } |
---|
68 | vbuf->unlock(); |
---|
69 | </pre></td></tr></table><P> |
---|
70 | |
---|
71 | See the API docs for full details of all the helper methods on VertexDeclaration and VertexElement to assist you in manipulating vertex buffer data pointers. |
---|
72 | </P><P> |
---|
73 | |
---|
74 | <A NAME="Hardware Index Buffers"></A> |
---|
75 | <HR SIZE=1> |
---|
76 | <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> |
---|
77 | <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_50.html#SEC241"> < </A>]</TD> |
---|
78 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_47.html#SEC237"> Up </A>]</TD> |
---|
79 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_52.html#SEC245"> > </A>]</TD> |
---|
80 | <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD> |
---|
81 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD> |
---|
82 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD> |
---|
83 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD> |
---|
84 | </TR></TABLE> |
---|
85 | <BR> |
---|
86 | <FONT SIZE="-1"> |
---|
87 | This document was generated |
---|
88 | by <I>Steve Streeting</I> on <I>, 12 2006</I> |
---|
89 | using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html |
---|
90 | "><I>texi2html</I></A> |
---|
91 | |
---|
92 | </BODY> |
---|
93 | </HTML> |
---|