source: OGRE/trunk/ogrenew/Docs/vbo-update/vbo-update_13.html @ 657

Revision 657, 5.5 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1<HTML>
2<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3<!-- Created on , 12 2006 by texi2html 1.64 -->
4<!--
5Written 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.
9Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
10Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
11 
12-->
13<HEAD>
14<TITLE>Hardware Buffers In OGRE: Updating Vertex Buffers</TITLE>
15
16<META NAME="description" CONTENT="Hardware Buffers In OGRE: Updating Vertex Buffers">
17<META NAME="keywords" CONTENT="Hardware Buffers In OGRE: 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="SEC17"></A>
27<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
28<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_12.html#SEC14"> &lt; </A>]</TD>
29<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_9.html#SEC10"> Up </A>]</TD>
30<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_14.html#SEC18"> &gt; </A>]</TD>
31<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
32<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_toc.html#SEC_Contents">Contents</A>]</TD>
33<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
34<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_abt.html#SEC_About"> ? </A>]</TD>
35</TR></TABLE>
36<HR SIZE=1>
37<H3> 2.6.4 Updating Vertex Buffers </H3>
38<!--docid::SEC17::-->
39The complexity of updating a vertex buffer entirely depends on how its contents are laid out. You can lock a buffer (See section <A HREF="vbo-update_7.html#SEC7">2.4 Locking buffers</A>), but how you write data into it vert much depends on what it contains.<BR><BR>
40Lets 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>&nbsp;</td><td class=example><pre>Real* pReal = static_cast&#60;Real*&#62;(vbuf-&#62;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>
43Firstly, 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>&nbsp;</td><td class=example><pre>// Get base pointer
45unsigned char* pVert = static_cast&#60;unsigned char*&#62;(vbuf-&#62;lock(HardwareBuffer::HBL_READ_ONLY));
46Real* pReal;
47for (size_t v = 0; v &#60; vertexCount; ++v)
48{
49        // Get elements
50        VertexDeclaration::VertexElementList elems = decl-&#62;findElementsBySource(bufferIdx);
51        VertexDeclaration::VertexElementList::iterator i, iend;
52        for (i = elems.begin(); i != elems.end(); ++i)
53        {
54                VertexElement&#38; elem = *i;
55                if (elem.getSemantic() == VES_POSITION)
56                {
57                        elem.baseVertexPointerToElement(pVert, &#38;pReal);
58                        // write position using pReal
59
60                }
61               
62                ...
63               
64               
65        }
66        pVert += vbuf-&#62;getVertexSize();
67}
68vbuf-&#62;unlock();
69</pre></td></tr></table><P>
70
71See 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="vbo-update_12.html#SEC14"> &lt; </A>]</TD>
78<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_9.html#SEC10"> Up </A>]</TD>
79<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_14.html#SEC18"> &gt; </A>]</TD>
80<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
81<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_toc.html#SEC_Contents">Contents</A>]</TD>
82<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
83<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_abt.html#SEC_About"> ? </A>]</TD>
84</TR></TABLE>
85<BR> 
86<FONT SIZE="-1">
87This document was generated
88by <I>Steve Streeting</I> on <I>, 12 2006</I>
89using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
90"><I>texi2html</I></A>
91
92</BODY>
93</HTML>
Note: See TracBrowser for help on using the repository browser.