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: 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"> < </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"> > </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.8.2 Updating Pixel Buffers </H3> |
---|
38 | <!--docid::SEC27::--> |
---|
39 | <P> |
---|
40 | |
---|
41 | Pixel 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 | |
---|
49 | The 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> </td><td class=example><pre>// Manually loads an image and puts the contents in a manually created texture |
---|
53 | Image img; |
---|
54 | img.load("elephant.png", "General"); |
---|
55 | // Create RGB texture with 5 mipmaps |
---|
56 | TexturePtr 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. |
---|
63 | tex->getBuffer(0,0)->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 | |
---|
71 | A more advanced method to transfer image data from and to a PixelBuffer is to use locking. By locking a PixelBuffer |
---|
72 | you 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> </td><td class=example><pre>/// Lock the buffer so we can write to it |
---|
76 | buffer->lock(HardwareBuffer::HBL_DISCARD); |
---|
77 | const PixelBox &pb = buffer->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. |
---|
82 | uint32 *data = static_cast<uint32*>(pb.data); |
---|
83 | size_t height = pb.getHeight(); |
---|
84 | size_t width = pb.getWidth(); |
---|
85 | size_t rowSkip = pb.getRowSkip(); // Skip between rows of image |
---|
86 | for(size_t y=0; y<height; ++y) |
---|
87 | { |
---|
88 | for(size_t x=0; x<width; ++x) |
---|
89 | { |
---|
90 | // 0xRRGGBB -> 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) |
---|
96 | buffer->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"> < </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"> > </A>]</TD> |
---|
105 | <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> |
---|
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"> |
---|
112 | This document was generated |
---|
113 | by <I>Steve Streeting</I> on <I>, 12 2006</I> |
---|
114 | using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html |
---|
115 | "><I>texi2html</I></A> |
---|
116 | |
---|
117 | </BODY> |
---|
118 | </HTML> |
---|