00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00026 // Headers 00028 #include <SFML/Graphics/RenderImage.hpp> 00029 #include <SFML/Graphics/RenderImageImplFBO.hpp> 00030 #include <SFML/Graphics/RenderImageImplPBuffer.hpp> 00031 #include <SFML/System/Err.hpp> 00032 00033 00034 namespace sf 00035 { 00037 RenderImage::RenderImage() : 00038 myRenderImage(NULL) 00039 { 00040 00041 } 00042 00043 00045 RenderImage::~RenderImage() 00046 { 00047 delete myRenderImage; 00048 } 00049 00050 00052 bool RenderImage::Create(unsigned int width, unsigned int height, bool depthBuffer) 00053 { 00054 // Make sure that render-images are supported 00055 if (!IsAvailable()) 00056 { 00057 Err() << "Impossible to create render image (your system doesn't support this feature)" << std::endl; 00058 return false; 00059 } 00060 00061 // Create the image 00062 if (!myImage.Create(width, height)) 00063 { 00064 Err() << "Impossible to create render image (failed to create the target image)" << std::endl; 00065 return false; 00066 } 00067 00068 // We disable smoothing by default for render images 00069 SetSmooth(false); 00070 00071 // Create the implementation 00072 delete myRenderImage; 00073 if (priv::RenderImageImplFBO::IsSupported()) 00074 { 00075 // Use FBO 00076 myRenderImage = new priv::RenderImageImplFBO; 00077 } 00078 else if (priv::RenderImageImplPBuffer::IsSupported()) 00079 { 00080 // Use P-Buffer 00081 myRenderImage = new priv::RenderImageImplPBuffer; 00082 } 00083 00084 // Initialize the render image 00085 if (!myRenderImage->Create(width, height, myImage.myTexture, depthBuffer)) 00086 return false; 00087 00088 // We can now initialize the render target part 00089 RenderTarget::Initialize(); 00090 00091 return true; 00092 } 00093 00094 00096 void RenderImage::SetSmooth(bool smooth) 00097 { 00098 myImage.SetSmooth(smooth); 00099 } 00100 00101 00103 bool RenderImage::IsSmooth() const 00104 { 00105 return myImage.IsSmooth(); 00106 } 00107 00108 00110 bool RenderImage::SetActive(bool active) 00111 { 00112 return myRenderImage && myRenderImage->Activate(active); 00113 } 00114 00115 00117 void RenderImage::Display() 00118 { 00119 // Update the target image 00120 if (myRenderImage) 00121 { 00122 myRenderImage->UpdateTexture(myImage.myTexture); 00123 00124 myImage.myPixelsFlipped = true; 00125 myImage.myArrayUpdated = false; 00126 myImage.myTextureUpdated = true; 00127 } 00128 } 00129 00130 00132 unsigned int RenderImage::GetWidth() const 00133 { 00134 return myImage.GetWidth(); 00135 } 00136 00137 00139 unsigned int RenderImage::GetHeight() const 00140 { 00141 return myImage.GetHeight(); 00142 } 00143 00144 00146 const Image& RenderImage::GetImage() const 00147 { 00148 return myImage; 00149 } 00150 00151 00153 bool RenderImage::IsAvailable() 00154 { 00155 return priv::RenderImageImplFBO::IsSupported() || 00156 priv::RenderImageImplPBuffer::IsSupported(); 00157 } 00158 00159 00161 bool RenderImage::Activate(bool active) 00162 { 00163 return SetActive(active); 00164 } 00165 00166 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::