PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Surface.h * 00003 * 00004 * Copyright (C) 2002-2012 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 __PLRENDERER_SURFACE_H__ 00024 #define __PLRENDERER_SURFACE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/String/String.h> 00032 #include <PLCore/Container/List.h> 00033 #include <PLCore/Base/Event/Event.h> 00034 #include <PLMath/Vector2i.h> 00035 #include "PLRenderer/PLRenderer.h" 00036 00037 00038 //[-------------------------------------------------------] 00039 //[ Namespace ] 00040 //[-------------------------------------------------------] 00041 namespace PLRenderer { 00042 00043 00044 //[-------------------------------------------------------] 00045 //[ Forward declarations ] 00046 //[-------------------------------------------------------] 00047 class Renderer; 00048 class SurfaceHandler; 00049 class SurfacePainter; 00050 00051 00052 //[-------------------------------------------------------] 00053 //[ Classes ] 00054 //[-------------------------------------------------------] 00055 /** 00056 * @brief 00057 * Abstract renderer surface where we can render in 00058 */ 00059 class Surface { 00060 00061 00062 //[-------------------------------------------------------] 00063 //[ Friends ] 00064 //[-------------------------------------------------------] 00065 friend class Renderer; 00066 friend class SurfaceHandler; 00067 friend class SurfacePainter; 00068 friend class RendererBackend; 00069 00070 00071 //[-------------------------------------------------------] 00072 //[ Public definitions ] 00073 //[-------------------------------------------------------] 00074 public: 00075 /** 00076 * @brief 00077 * Surface types 00078 */ 00079 enum EType { 00080 Window = 0, /**< Render to window */ 00081 TextureBuffer = 1 /**< Render to texture buffer */ 00082 }; 00083 00084 00085 //[-------------------------------------------------------] 00086 //[ Events ] 00087 //[-------------------------------------------------------] 00088 public: 00089 PLCore::Event<> EventPaintBegin; /**< Paint begin event - emitted BEFORE any painting begins */ 00090 PLCore::Event<> EventPaint; /**< Paint event - emitted BEFORE any painting */ 00091 PLCore::Event<> EventPaintEnd; /**< Paint end event - emitted AFTER any painting ends */ 00092 00093 00094 //[-------------------------------------------------------] 00095 //[ Public functions ] 00096 //[-------------------------------------------------------] 00097 public: 00098 /** 00099 * @brief 00100 * Destructor 00101 */ 00102 PLRENDERER_API virtual ~Surface(); 00103 00104 /** 00105 * @brief 00106 * Returns the owner renderer 00107 * 00108 * @return 00109 * The owner renderer 00110 */ 00111 inline Renderer &GetRenderer() const; 00112 00113 /** 00114 * @brief 00115 * Returns the surface type 00116 * 00117 * @return 00118 * Surface type 00119 */ 00120 inline EType GetType() const; 00121 00122 /** 00123 * @brief 00124 * Returns whether the surface is active or not 00125 * 00126 * @return 00127 * 'true' if the surface is active, else 'false' 00128 */ 00129 inline bool IsActive() const; 00130 00131 /** 00132 * @brief 00133 * Sets whether the surface is active or not 00134 * 00135 * @param[in] bActive 00136 * 'true' if the surface is active, else 'false' 00137 */ 00138 inline void SetActive(bool bActive = true); 00139 00140 /** 00141 * @brief 00142 * Returns the surface painter 00143 * 00144 * @return 00145 * The surface painter, a null pointer if there's no surface painter 00146 */ 00147 inline SurfacePainter *GetPainter() const; 00148 00149 /** 00150 * @brief 00151 * Set a surface painter 00152 * 00153 * @param[in] pPainter 00154 * Pointer to the surface painter, can be a null pointer 00155 * @param[in] bDestroy 00156 * Destroy the current set surface painter? (if there's one) 00157 * 00158 * @return 00159 * 'true' if all went fine, else 'false' 00160 * 00161 * @remarks 00162 * The painter will be destroyed by the surface, so don't delete it again! 00163 */ 00164 PLRENDERER_API bool SetPainter(SurfacePainter *pPainter, bool bDestroy = true); 00165 00166 /** 00167 * @brief 00168 * Draws the surface 00169 * 00170 * @remarks 00171 * Just calls the OnPaint() function if there's a surface painter and if this surface 00172 * is active. 00173 */ 00174 PLRENDERER_API void Draw(); 00175 00176 /** 00177 * @brief 00178 * Returns the whether the surface is flipped along the y axis 00179 * 00180 * @return 00181 * 'true' if the surface is flipped along the y axis, else 'false' 00182 */ 00183 inline bool IsSwapY() const; 00184 00185 /** 00186 * @brief 00187 * Sets the whether the surface is flipped along the y axis 00188 * 00189 * @param[in] bSwapY 00190 * 'true' if the surface is flipped along the y axis, else 'false' 00191 */ 00192 inline void SetSwapY(bool bSwapY = false); 00193 00194 00195 //[-------------------------------------------------------] 00196 //[ Public virtual Surface functions ] 00197 //[-------------------------------------------------------] 00198 public: 00199 /** 00200 * @brief 00201 * Returns the size of this renderer surface 00202 * 00203 * @return 00204 * The size of this renderer surface 00205 */ 00206 virtual PLMath::Vector2i GetSize() const = 0; 00207 00208 /** 00209 * @brief 00210 * Returns the whether the surface is flipped along the y axis 00211 * 00212 * @return 00213 * 'true' if the surface is flipped along the y axis, else 'false' 00214 * 00215 * @note 00216 * - By overwriting this function, the renderer backend can decide by itself how 00217 * to flip the surface 00218 */ 00219 PLRENDERER_API virtual bool IsAPISwapY() const; 00220 00221 00222 //[-------------------------------------------------------] 00223 //[ Protected functions ] 00224 //[-------------------------------------------------------] 00225 protected: 00226 /** 00227 * @brief 00228 * Constructor 00229 * 00230 * @param[in] cRenderer 00231 * Owner renderer 00232 * @param[in] nType 00233 * Surface type 00234 */ 00235 PLRENDERER_API Surface(Renderer &cRenderer, EType nType); 00236 00237 00238 //[-------------------------------------------------------] 00239 //[ Protected virtual Surface functions ] 00240 //[-------------------------------------------------------] 00241 protected: 00242 /** 00243 * @brief 00244 * Initializes the surface 00245 * 00246 * @return 00247 * 'true' if all went fine, else 'false' 00248 */ 00249 virtual bool Init() = 0; 00250 00251 /** 00252 * @brief 00253 * De-initializes the surface 00254 */ 00255 virtual void DeInit() = 0; 00256 00257 /** 00258 * @brief 00259 * Makes this surface to the renderers current render target 00260 * 00261 * @param[in] nFace 00262 * Cube map face to render in (0-5) - only used if this is a cube texture buffer render target 00263 * 00264 * @return 00265 * 'true' if all went fine, else 'false' 00266 */ 00267 virtual bool MakeCurrent(PLCore::uint8 nFace = 0) = 0; 00268 00269 /** 00270 * @brief 00271 * Unmakes this surface from the renderers current render target 00272 * 00273 * @return 00274 * 'true' if all went fine, else 'false' 00275 */ 00276 PLRENDERER_API virtual bool UnmakeCurrent(); 00277 00278 /** 00279 * @brief 00280 * Presents the contents of the next buffer in the sequence 00281 * of back buffers owned by the device 00282 * 00283 * @return 00284 * 'true' if all went fine, else 'false' 00285 */ 00286 virtual bool Present() = 0; 00287 00288 /** 00289 * @brief 00290 * Backups the surface device data 00291 * 00292 * @note 00293 * - Used for instance if the display mode is changed to backup/restore 00294 * all surface device data 00295 * - Normally only used inside Renderer::BackupDeviceObjects()/Renderer::RestoreDeviceObjects() 00296 */ 00297 PLRENDERER_API virtual void BackupDeviceData(); 00298 00299 /** 00300 * @brief 00301 * Restores the surface device data 00302 * 00303 * @see 00304 * - BackupDeviceData() 00305 */ 00306 PLRENDERER_API virtual void RestoreDeviceData(); 00307 00308 00309 //[-------------------------------------------------------] 00310 //[ Private functions ] 00311 //[-------------------------------------------------------] 00312 private: 00313 /** 00314 * @brief 00315 * Copy constructor 00316 * 00317 * @param[in] cSource 00318 * Source to copy from 00319 */ 00320 Surface(const Surface &cSource); 00321 00322 /** 00323 * @brief 00324 * Copy operator 00325 * 00326 * @param[in] cSource 00327 * Source to copy from 00328 * 00329 * @return 00330 * Reference to this instance 00331 */ 00332 Surface &operator =(const Surface &cSource); 00333 00334 00335 //[-------------------------------------------------------] 00336 //[ Private data ] 00337 //[-------------------------------------------------------] 00338 private: 00339 Renderer *m_pRenderer; /**< Owner renderer (always valid!) */ 00340 EType m_nType; /**< Surface type */ 00341 bool m_bActive; /**< Is the surface active? */ 00342 bool m_bSwapY; /**< Is the surface flipped along the y axis? */ 00343 SurfacePainter *m_pPainter; /**< The used surface painter, can be a null pointer */ 00344 /** List of surface handlers */ 00345 PLCore::List<SurfaceHandler*> m_lstHandler; 00346 00347 00348 }; 00349 00350 00351 //[-------------------------------------------------------] 00352 //[ Namespace ] 00353 //[-------------------------------------------------------] 00354 } // PLRenderer 00355 00356 00357 //[-------------------------------------------------------] 00358 //[ Implementation ] 00359 //[-------------------------------------------------------] 00360 #include "PLRenderer/Renderer/Surface.inl" 00361 00362 00363 #endif // __PLRENDERER_SURFACE_H__
|