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>Hardware Buffers In OGRE: Vertex Buffer Bindings</TITLE> |
---|
15 | |
---|
16 | <META NAME="description" CONTENT="Hardware Buffers In OGRE: Vertex Buffer Bindings"> |
---|
17 | <META NAME="keywords" CONTENT="Hardware Buffers In OGRE: Vertex Buffer Bindings"> |
---|
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="SEC14"></A> |
---|
27 | <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> |
---|
28 | <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_11.html#SEC12"> < </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_13.html#SEC17"> > </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="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.3 Vertex Buffer Bindings </H3> |
---|
38 | <!--docid::SEC14::--> |
---|
39 | Vertex buffer bindings are about associating a vertex buffer with a source index used in <A HREF="vbo-update_11.html#SEC12">2.6.2 Vertex Declarations</A>. |
---|
40 | <A NAME="SEC15"></A> |
---|
41 | <H3> Creating the Vertex Buffer </H3> |
---|
42 | <!--docid::SEC15::--> |
---|
43 | Firstly, lets look at how you create a vertex buffer: |
---|
44 | <TABLE><tr><td> </td><td class=example><pre>HardwareVertexBufferSharedPtr vbuf = |
---|
45 | HardwareBufferManager::getSingleton().createVertexBuffer( |
---|
46 | 3*sizeof(Real), // size of one whole vertex |
---|
47 | numVertices, // number of vertices |
---|
48 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage |
---|
49 | false); // no shadow buffer |
---|
50 | </pre></td></tr></table><P> |
---|
51 | |
---|
52 | Notice that we use <A HREF="vbo-update_4.html#SEC4">2.1 The Hardware Buffer Manager</A> to create our vertex buffer, and that a class called HardwareVertexBufferSharedPtr is returned from the method, rather than a raw pointer. This is because vertex buffers are reference counted - you are able to use a single vertex buffer as a source for multiple pieces of geometry therefore a standard pointer would not be good enough, because you would not know when all the different users of it had finished with it. The HardwareVertexBufferSharedPtr class manages its own destruction by keeping a reference count of the number of times it is being used - when the last HardwareVertexBufferSharedPtr is destroyed, the buffer itself automatically destroys itself.<BR><BR> |
---|
53 | </P><P> |
---|
54 | |
---|
55 | The parameters to the creation of a vertex buffer are as follows: |
---|
56 | <DL COMPACT> |
---|
57 | <DT>vertexSize |
---|
58 | <DD>The size in bytes of a whole vertex in this buffer. A vertex may include multiple elements, and in fact the contents of the vertex data may be reinterpreted by different vertex declarations if you wish. Therefore you must tell the buffer manager how large a whole vertex is, but not the internal format of the vertex, since that is down to the declaration to interpret. In the above example, the size is set to the size of 3 floating point values - this would be enough to hold a standard 3D position or normal, or a 3D texture coordinate, per vertex. |
---|
59 | <DT>numVertices |
---|
60 | <DD>The number of vertices in this buffer. Remember, not all the vertices have to be used at once - it can be beneficial to create large buffers which are shared between many chunks of geometry because changing vertex buffer bindings is a render state switch, and those are best minimised. |
---|
61 | <DT>usage |
---|
62 | <DD>This tells the system how you intend to use the buffer. See section <A HREF="vbo-update_5.html#SEC5">2.2 Buffer Usage</A> |
---|
63 | <DT>useShadowBuffer |
---|
64 | <DD>Tells the system whether you want this buffer backed by a system-memory copy. See section <A HREF="vbo-update_6.html#SEC6">2.3 Shadow Buffers</A> |
---|
65 | </DL> |
---|
66 | <P> |
---|
67 | |
---|
68 | <A NAME="SEC16"></A> |
---|
69 | <H3> Binding the Vertex Buffer </H3> |
---|
70 | <!--docid::SEC16::--> |
---|
71 | The second part of the process is to bind this buffer which you have created to a source index. To do this, you call: |
---|
72 | <TABLE><tr><td> </td><td class=example><pre>vertexBufferBinding->setBinding(0, vbuf); |
---|
73 | </pre></td></tr></table>This results in the vertex buffer you created earlier being bound to source index 0, so any vertex element which is pulling its data from source index 0 will retrieve data from this buffer. <BR><BR> |
---|
74 | There are also methods for retrieving buffers from the binding data - see the API reference for full details. |
---|
75 | <P> |
---|
76 | |
---|
77 | <A NAME="Updating Vertex Buffers"></A> |
---|
78 | <HR SIZE=1> |
---|
79 | <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> |
---|
80 | <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_11.html#SEC12"> < </A>]</TD> |
---|
81 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_9.html#SEC10"> Up </A>]</TD> |
---|
82 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_13.html#SEC17"> > </A>]</TD> |
---|
83 | <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> |
---|
84 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_toc.html#SEC_Contents">Contents</A>]</TD> |
---|
85 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD> |
---|
86 | <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_abt.html#SEC_About"> ? </A>]</TD> |
---|
87 | </TR></TABLE> |
---|
88 | <BR> |
---|
89 | <FONT SIZE="-1"> |
---|
90 | This document was generated |
---|
91 | by <I>Steve Streeting</I> on <I>, 12 2006</I> |
---|
92 | using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html |
---|
93 | "><I>texi2html</I></A> |
---|
94 | |
---|
95 | </BODY> |
---|
96 | </HTML> |
---|