PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: RendererContext.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_RENDERERCONTEXT_H__ 00024 #define __PLRENDERER_RENDERERCONTEXT_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/Event.h> 00032 #include <PLCore/Core/AbstractContext.h> 00033 #include "PLRenderer/Renderer/Renderer.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Forward declarations ] 00038 //[-------------------------------------------------------] 00039 namespace PLCore { 00040 class String; 00041 } 00042 namespace PLRenderer { 00043 class TextureManager; 00044 class EffectManager; 00045 class MaterialManager; 00046 } 00047 00048 00049 //[-------------------------------------------------------] 00050 //[ Namespace ] 00051 //[-------------------------------------------------------] 00052 namespace PLRenderer { 00053 00054 00055 //[-------------------------------------------------------] 00056 //[ Classes ] 00057 //[-------------------------------------------------------] 00058 /** 00059 * @brief 00060 * Renderer context 00061 * 00062 * @remarks 00063 * The renderer context stores and manages all data related to the renderer like e.g. the used PLRenderer implementation, 00064 * textures and so on. 00065 * 00066 * Please note that the renderer context is by design window independent, it doesn't even know anything about one or multiple 00067 * windows (renderer targets). The renderer instance is connected with the renderer context. So, the renderer doesn't depend 00068 * on an OS window as well, but the internal renderer implementation may need an OS window. If you have an OS main window which is 00069 * valid as long as the renderer context instance exists, it's highly recommended to tell the renderer context of this main window 00070 * during creation, else the internal renderer may create it's own invisible dummy window. Most times, there's no problem with an 00071 * invisible dummy window holding a renderer implementation together. Sadly, there are e.g. some OpenGL ES 2.0 implementations which 00072 * just fail when using multiple windows (the internal invisible dummy window and the real visible one => two windows). 00073 * 00074 * In a nutshell: 00075 * - If you've already got an OS main window which is valid as long as the renderer context instance exists, just tell the renderer 00076 * context about it 00077 * - If you don't have such an OS main window, don't create one just for the renderer context and pass in "NULL_HANDLE", the renderer 00078 * implementation must be able to deal with this situation on it's own 00079 * 00080 * @note 00081 * - There should be only one renderer context instance per application 00082 */ 00083 class RendererContext : public PLCore::AbstractContext { 00084 00085 00086 //[-------------------------------------------------------] 00087 //[ Friends ] 00088 //[-------------------------------------------------------] 00089 friend class RendererBackend; 00090 00091 00092 //[-------------------------------------------------------] 00093 //[ Public events ] 00094 //[-------------------------------------------------------] 00095 public: 00096 PLCore::Event<> EventUpdate; /**< Update event */ 00097 00098 00099 //[-------------------------------------------------------] 00100 //[ Public static functions ] 00101 //[-------------------------------------------------------] 00102 public: 00103 /** 00104 * @brief 00105 * Creates a renderer context instance 00106 * 00107 * @param[in] sBackend 00108 * Name of the renderer backend to use (for example 'PLRendererOpenGL::Renderer') 00109 * @param[in] nNativeWindowHandle 00110 * Handle of a native OS window which is valid as long as the renderer instance exists, "NULL_HANDLE" if there's no such window (see class remarks for more information) 00111 * @param[in] nMode 00112 * Mode hint the renderer should run in, the renderer is not enforced to use this requested mode 00113 * @param[in] nZBufferBits 00114 * Z buffer bits (just a hint, for example 24) 00115 * @param[in] nStencilBits 00116 * Stencil buffer bits (just a hint, for example 8) 00117 * @param[in] nMultisampleAntialiasingSamples 00118 * Multisample antialiasing samples per pixel, <=1 means no antialiasing (just a hint) 00119 * @param[in] sDefaultShaderLanguage 00120 * The name of the default shader language of the renderer (for example "GLSL" or "Cg"), if the string 00121 * is empty, the default is chosen by the renderer implementation, this information is just a hint 00122 * 00123 * @return 00124 * Creates a renderer context instance, a null pointer on error 00125 */ 00126 static PLRENDERER_API RendererContext *CreateInstance(const PLCore::String &sBackend, PLCore::handle nNativeWindowHandle, Renderer::EMode nMode = Renderer::ModeBoth, PLCore::uint32 nZBufferBits = 24, PLCore::uint32 nStencilBits = 8, PLCore::uint32 nMultisampleAntialiasingSamples = 0, const PLCore::String &sDefaultShaderLanguage = ""); 00127 00128 00129 //[-------------------------------------------------------] 00130 //[ Public functions ] 00131 //[-------------------------------------------------------] 00132 public: 00133 /** 00134 * @brief 00135 * Destructor 00136 */ 00137 PLRENDERER_API ~RendererContext(); 00138 00139 /** 00140 * @brief 00141 * Returns the used renderer 00142 * 00143 * @return 00144 * Reference to the used renderer 00145 */ 00146 inline Renderer &GetRenderer() const; 00147 00148 /** 00149 * @brief 00150 * Returns the texture manager of this renderer context 00151 * 00152 * @return 00153 * Reference to the texture manager of this renderer context 00154 */ 00155 PLRENDERER_API TextureManager &GetTextureManager(); 00156 00157 /** 00158 * @brief 00159 * Returns the effect manager of this renderer context 00160 * 00161 * @return 00162 * Reference to the effect manager of this renderer context 00163 */ 00164 PLRENDERER_API EffectManager &GetEffectManager(); 00165 00166 /** 00167 * @brief 00168 * Returns the material manager of this renderer context 00169 * 00170 * @return 00171 * Reference to the material manager of this renderer context 00172 */ 00173 PLRENDERER_API MaterialManager &GetMaterialManager(); 00174 00175 /** 00176 * @brief 00177 * Updates the render context 00178 * 00179 * @note 00180 * - Should be called once per frame 00181 * - Updates the effect manager 00182 * - Emits the update event 00183 * - Updates the renderer ("redraw") 00184 * - Collects renderer context profiling information 00185 */ 00186 PLRENDERER_API void Update(); 00187 00188 00189 //[-------------------------------------------------------] 00190 //[ Private functions ] 00191 //[-------------------------------------------------------] 00192 private: 00193 /** 00194 * @brief 00195 * Constructor 00196 * 00197 * @param[in] cRenderer 00198 * Renderer to use 00199 */ 00200 PLRENDERER_API RendererContext(Renderer &cRenderer); 00201 00202 /** 00203 * @brief 00204 * Copy operator 00205 * 00206 * @param[in] cSource 00207 * Source to copy from 00208 * 00209 * @return 00210 * Reference to this instance 00211 */ 00212 RendererContext &operator =(const RendererContext &cSource); 00213 00214 00215 //[-------------------------------------------------------] 00216 //[ Private data ] 00217 //[-------------------------------------------------------] 00218 private: 00219 Renderer *m_pRenderer; /**< Used renderer, always valid! */ 00220 TextureManager *m_pTextureManager; /**< The texture manager of this renderer context, a null pointer if not yet initialized */ 00221 EffectManager *m_pEffectManager; /**< The effect manager of this renderer context, a null pointer if not yet initialized */ 00222 MaterialManager *m_pMaterialManager; /**< The material manager of this renderer context, a null pointer if not yet initialized */ 00223 00224 00225 }; 00226 00227 00228 //[-------------------------------------------------------] 00229 //[ Namespace ] 00230 //[-------------------------------------------------------] 00231 } // PLRenderer 00232 00233 00234 //[-------------------------------------------------------] 00235 //[ Implementation ] 00236 //[-------------------------------------------------------] 00237 #include "PLRenderer/RendererContext.inl" 00238 00239 00240 #endif // __PLRENDERER_RENDERERCONTEXT_H__
|