source: OGRE/trunk/ogrenew/Docs/vbo-update/vbo-update_19.html @ 692

Revision 692, 5.4 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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 Pixel Buffers</TITLE>
15
16<META NAME="description" CONTENT="Hardware Buffers In OGRE: Updating Pixel Buffers">
17<META NAME="keywords" CONTENT="Hardware Buffers In OGRE: Updating Pixel 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="SEC27"></A>
27<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
28<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_18.html#SEC23"> &lt; </A>]</TD>
29<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_17.html#SEC22"> Up </A>]</TD>
30<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_20.html#SEC30"> &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.8.2 Updating Pixel Buffers </H3>
38<!--docid::SEC27::-->
39<P>
40
41Pixel Buffers can be updated in two different ways; a simple, convient way and a more difficult (but in some cases faster) method. Both methods make use of PixelBox objects (See section <A HREF="vbo-update_22.html#SEC35">2.8.5 Pixel boxes</A>) to represent image data in memory.
42</P><P>
43
44<A NAME="SEC28"></A>
45<H3> blitFromMemory </H3>
46<!--docid::SEC28::-->
47<P>
48
49The easy method to get an image into a PixelBuffer is by using HardwarePixelBuffer::blitFromMemory. This takes a PixelBox object and does all necessary pixel format conversion and scaling for you. For example, to create a manual texture and load an image into it, all you have to do is
50</P><P>
51
52<TABLE><tr><td>&nbsp;</td><td class=example><pre>// Manually loads an image and puts the contents in a manually created texture
53Image img;
54img.load("elephant.png", "General");
55// Create RGB texture with 5 mipmaps
56TexturePtr tex = TextureManager::getSingleton().createManual(
57    "elephant",
58    "General",
59    TEX_TYPE_2D,
60    img.getWidth(), img.getHeight(),
61    5, PF_X8R8G8B8);
62// Copy face 0 mipmap 0 of the image to face 0 mipmap 0 of the texture.
63tex-&#62;getBuffer(0,0)-&#62;blitFromMemory(img.getPixelBox(0,0));
64</pre></td></tr></table></P><P>
65
66<A NAME="SEC29"></A>
67<H3> Direct memory locking </H3>
68<!--docid::SEC29::-->
69<P>
70
71A more advanced method to transfer image data from and to a PixelBuffer is to use locking. By locking a PixelBuffer
72you can directly access its contents in whatever the internal format of the buffer inside the GPU is.
73</P><P>
74
75<TABLE><tr><td>&nbsp;</td><td class=example><pre>/// Lock the buffer so we can write to it
76buffer-&#62;lock(HardwareBuffer::HBL_DISCARD);
77const PixelBox &#38;pb = buffer-&#62;getCurrentLock();
78
79/// Update the contents of pb here
80/// Image data starts at pb.data and has format pb.format
81/// Here we assume data.format is PF_X8R8G8B8 so we can address pixels as uint32.
82uint32 *data = static_cast&#60;uint32*&#62;(pb.data);
83size_t height = pb.getHeight();
84size_t width = pb.getWidth();
85size_t rowSkip = pb.getRowSkip(); // Skip between rows of image
86for(size_t y=0; y&#60;height; ++y)
87{
88    for(size_t x=0; x&#60;width; ++x)
89{
90        // 0xRRGGBB -&#62; fill the buffer with yellow pixels
91        data[rowSkip*y + x] = 0x00FFFF00;
92}
93}
94
95/// Unlock the buffer again (frees it for use by the GPU)
96buffer-&#62;unlock();
97</pre></td></tr></table></P><P>
98
99<A NAME="Texture Types"></A>
100<HR SIZE=1>
101<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
102<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_18.html#SEC23"> &lt; </A>]</TD>
103<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_17.html#SEC22"> Up </A>]</TD>
104<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_20.html#SEC30"> &gt; </A>]</TD>
105<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>
106<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_toc.html#SEC_Contents">Contents</A>]</TD>
107<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
108<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="vbo-update_abt.html#SEC_About"> ? </A>]</TD>
109</TR></TABLE>
110<BR> 
111<FONT SIZE="-1">
112This document was generated
113by <I>Steve Streeting</I> on <I>, 12 2006</I>
114using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
115"><I>texi2html</I></A>
116
117</BODY>
118</HTML>
Note: See TracBrowser for help on using the repository browser.