PixelLightAPI  .
SCRenderToTexture.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SCRenderToTexture.h                            *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSCENE_SCENENODE_RENDERTOTEXTURE_H__
00024 #define __PLSCENE_SCENENODE_RENDERTOTEXTURE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLScene/Scene/SceneContainer.h"
00032 #include "PLScene/Scene/SceneNodeHandler.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLRenderer {
00039     class Texture;
00040     class TextureHandler;
00041     class SurfaceTextureBuffer;
00042 }
00043 
00044 
00045 //[-------------------------------------------------------]
00046 //[ Namespace                                             ]
00047 //[-------------------------------------------------------]
00048 namespace PLScene {
00049 
00050 
00051 //[-------------------------------------------------------]
00052 //[ Classes                                               ]
00053 //[-------------------------------------------------------]
00054 /**
00055 *  @brief
00056 *    Render to texture scene container
00057 *
00058 *  @remarks
00059 *    This scene container can render it's sub-scene or another linked scene using a given
00060 *    camera into a texture. If you want to render the scene into a cube texture, set the
00061 *    variable 'Cube' to 'true'. In this case, only the position of the given camera is used.
00062 *    This for instance can be used to render correct dynamic reflections.
00063 *
00064 *  @note
00065 *    - For 2D textures, non-power-of-two dimensions are supported
00066 *    - If a camera scene node is used and this node is inactive, the texture is not updated
00067 */
00068 class SCRenderToTexture : public SceneContainer {
00069 
00070 
00071     //[-------------------------------------------------------]
00072     //[ Public definitions                                    ]
00073     //[-------------------------------------------------------]
00074     public:
00075         /**
00076         *  @brief
00077         *    Scene node debug flags (SceneNode debug flags extension)
00078         */
00079         enum EDebugFlags {
00080             DebugNoTexturePreview = 1<<8    /**< Do not draw the texture preview */
00081         };
00082         pl_enum(EDebugFlags)
00083             pl_enum_base(SceneContainer::EDebugFlags)
00084             pl_enum_value(DebugNoTexturePreview, "Do not draw the texture preview")
00085         pl_enum_end
00086 
00087         /**
00088         *  @brief
00089         *    Surface formats
00090         */
00091         enum EFormat {
00092             R8G8B8   = 0,   /**< 8 bits per red, green and blue component */
00093             R8G8B8A8 = 1    /**< 8 bits per red, green, blue and alpha component */
00094         };
00095         pl_enum(EFormat)
00096             pl_enum_value(R8G8B8,   "8 bits per red, green and blue component")
00097             pl_enum_value(R8G8B8A8, "8 bits per red, green, blue and alpha component")
00098         pl_enum_end
00099 
00100         /**
00101         *  @brief
00102         *    Surface flags
00103         */
00104         enum ESurfaceFlags {
00105             Depth   = 1<<0, /**< Surface has a depth buffer */
00106             Stencil = 1<<1, /**< Surface has a stencil buffer */
00107             Mipmaps = 1<<2  /**< Surface has mipmaps */
00108         };
00109         pl_enum(ESurfaceFlags)
00110             pl_enum_value(Depth,    "Surface has a depth buffer")
00111             pl_enum_value(Stencil,  "Surface has a stencil buffer")
00112             pl_enum_value(Mipmaps,  "Surface has mipmaps")
00113         pl_enum_end
00114 
00115 
00116     //[-------------------------------------------------------]
00117     //[ RTTI interface                                        ]
00118     //[-------------------------------------------------------]
00119     pl_class(PLS_RTTI_EXPORT, SCRenderToTexture, "PLScene", PLScene::SceneContainer, "Render to texture scene container")
00120         // Attributes
00121         pl_attribute(Cube,          bool,                           false,                  ReadWrite,  GetSet,         "Render to cube texture? If 'true', only 'Width' is used which must be a power of two", "")
00122         pl_attribute(Width,         PLCore::uint16,                 512,                    ReadWrite,  GetSet,         "Texture width",                                                                        "Min='16'")
00123         pl_attribute(Height,        PLCore::uint16,                 512,                    ReadWrite,  GetSet,         "Texture height",                                                                       "Min='16'")
00124         pl_attribute(Format,        pl_enum_type(EFormat),          R8G8B8A8,               ReadWrite,  GetSet,         "Texture format",                                                                       "")
00125         pl_attribute(SurfaceFlags,  pl_flag_type(ESurfaceFlags),    Depth|Mipmaps,          ReadWrite,  GetSet,         "Texture surface flags",                                                                "")
00126         pl_attribute(TextureName,   PLCore::String,                 "",                     ReadWrite,  GetSet,         "Name of the resulting texture",                                                        "")
00127         pl_attribute(FPSLimit,      float,                          30.0f,                  ReadWrite,  DirectValue,    "Frames per second limitation, if 0, there's no limitation",                            "Min='0.0'")
00128         pl_attribute(Painter,       PLCore::String,                 "PLScene::SPScene", ReadWrite,  GetSet,         "Name of the used surface painter",                                                     "")
00129         pl_attribute(SceneRenderer, PLCore::String,                 "Forward.sr",           ReadWrite,  GetSet,         "Name of the used scene renderer, only used if the painter is derived of 'SPScene'",    "")
00130         pl_attribute(SceneName,     PLCore::String,                 "Parent",               ReadWrite,  GetSet,         "Name of the scene to renderer, only used if the painter is derived of 'SPScene'",      "")
00131         pl_attribute(CameraName,    PLCore::String,                 "",                     ReadWrite,  DirectValue,    "Name of the camera to use, only used if the painter is derived of 'SPScene'",          "")
00132             // Overwritten SceneNode attributes
00133         pl_attribute(Flags,         pl_flag_type(EFlags),           NoCulling|NoRecursion,  ReadWrite,  GetSet,         "Flags",                                                                                "")
00134         pl_attribute(DebugFlags,    pl_flag_type(EDebugFlags),      0,                      ReadWrite,  GetSet,         "Debug flags",                                                                          "")
00135         // Constructors
00136         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00137     pl_class_end
00138 
00139 
00140     //[-------------------------------------------------------]
00141     //[ Public RTTI get/set functions                         ]
00142     //[-------------------------------------------------------]
00143     public:
00144         PLS_API bool GetCube() const;
00145         PLS_API void SetCube(bool bValue);
00146         PLS_API PLCore::uint16 GetWidth() const;
00147         PLS_API void SetWidth(PLCore::uint16 nValue);
00148         PLS_API PLCore::uint16 GetHeight() const;
00149         PLS_API void SetHeight(PLCore::uint16 nValue);
00150         PLS_API EFormat GetFormat() const;
00151         PLS_API void SetFormat(EFormat nValue);
00152         PLS_API PLCore::uint32 GetSurfaceFlags() const;
00153         PLS_API void SetSurfaceFlags(PLCore::uint32 nValue);
00154         PLS_API PLCore::String GetTextureName() const;
00155         PLS_API void SetTextureName(const PLCore::String &sValue);
00156         PLS_API PLCore::String GetPainter() const;
00157         PLS_API void SetPainter(const PLCore::String &sValue);
00158         PLS_API PLCore::String GetSceneRenderer() const;
00159         PLS_API void SetSceneRenderer(const PLCore::String &sValue);
00160         PLS_API PLCore::String GetSceneName() const;
00161         PLS_API void SetSceneName(const PLCore::String &sValue);
00162 
00163 
00164     //[-------------------------------------------------------]
00165     //[ Public functions                                      ]
00166     //[-------------------------------------------------------]
00167     public:
00168         /**
00169         *  @brief
00170         *    Default constructor
00171         */
00172         PLS_API SCRenderToTexture();
00173 
00174         /**
00175         *  @brief
00176         *    Destructor
00177         */
00178         PLS_API virtual ~SCRenderToTexture();
00179 
00180         /**
00181         *  @brief
00182         *    Returns the texture buffer surface we render in
00183         *
00184         *  @return
00185         *   The texture buffer surface we render in, a null pointer on error
00186         */
00187         PLS_API PLRenderer::SurfaceTextureBuffer *GetSurfaceTextureBuffer() const;
00188 
00189         /**
00190         *  @brief
00191         *    Returns the resulting texture
00192         *
00193         *  @return
00194         *   The resulting texture, a null pointer on error
00195         */
00196         PLS_API PLRenderer::Texture *GetTexture() const;
00197 
00198 
00199     //[-------------------------------------------------------]
00200     //[ Protected data                                        ]
00201     //[-------------------------------------------------------]
00202     protected:
00203         bool                              m_bCube;                  /**< Render to cube texture? If 'true', only 'Width' is used which must be a power of two */
00204         PLCore::uint16                    m_nWidth;                 /**< Texture width */
00205         PLCore::uint16                    m_nHeight;                /**< Texture height */
00206         EFormat                           m_nFormat;                /**< Texture format */
00207         PLCore::uint32                    m_nSurfaceFlags;          /**< Texture surface flags */
00208         PLCore::String                    m_sTextureName;           /**< Name of the resulting texture */
00209         PLCore::String                    m_sPainter;               /**< Name of the used surface painter */
00210         PLCore::String                    m_sSceneRenderer;         /**< Name of the used scene renderer, only used if the painter is derived of 'SPScene' */
00211         PLCore::String                    m_sSceneName;             /**< Name of the scene to renderer, only used if the painter is derived of 'SPScene' */
00212         PLCore::uint64                    m_nFPSLimitLastTime;      /**< Time when the last update was done */
00213         PLRenderer::SurfaceTextureBuffer *m_pSurfaceTextureBuffer;  /**< Render to texture buffer, can be a null pointer */
00214         PLRenderer::TextureHandler       *m_pTextureHandler;        /**< The resulting texture (ALWAYS valid!) */
00215 
00216 
00217     //[-------------------------------------------------------]
00218     //[ Private functions                                     ]
00219     //[-------------------------------------------------------]
00220     private:
00221         /**
00222         *  @brief
00223         *    Creates/recreates the texture surface
00224         */
00225         void CreateSurfaceTexture();
00226 
00227 
00228     //[-------------------------------------------------------]
00229     //[ Public virtual SceneNode functions                    ]
00230     //[-------------------------------------------------------]
00231     public:
00232         PLS_API virtual void DrawPre(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode = nullptr) override;
00233         PLS_API virtual void DrawDebug(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode = nullptr) override;
00234 
00235 
00236     //[-------------------------------------------------------]
00237     //[ Protected virtual SceneNode functions                 ]
00238     //[-------------------------------------------------------]
00239     protected:
00240         PLS_API virtual void InitFunction() override;
00241 
00242 
00243 };
00244 
00245 
00246 //[-------------------------------------------------------]
00247 //[ Namespace                                             ]
00248 //[-------------------------------------------------------]
00249 } // PLScene
00250 
00251 
00252 #endif // __PLSCENE_SCENENODE_RENDERTOTEXTURE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported