00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com> 00008 Copyright (c) 2000-2012 Torus Knot Software Ltd 00009 00010 Permission is hereby granted, free of charge, to any person obtaining a copy 00011 of this software and associated documentation files (the "Software"), to deal 00012 in the Software without restriction, including without limitation the rights 00013 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00014 copies of the Software, and to permit persons to whom the Software is 00015 furnished to do so, subject to the following conditions: 00016 00017 The above copyright notice and this permission notice shall be included in 00018 all copies or substantial portions of the Software. 00019 00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00026 THE SOFTWARE. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 00030 #ifndef __GLESRenderSystem_H__ 00031 #define __GLESRenderSystem_H__ 00032 00033 #include "OgreGLESPrerequisites.h" 00034 00035 #include "OgreRenderSystem.h" 00036 00037 namespace Ogre { 00038 class GLESContext; 00039 class GLESSupport; 00040 class GLESRTTManager; 00041 class GLESGpuProgramManager; 00042 class HardwareBufferManager; 00043 00047 class _OgreGLESExport GLESRenderSystem : public RenderSystem 00048 { 00049 private: 00050 typedef HashMap<GLenum, GLint> TexEnviMap; 00051 typedef HashMap<GLenum, GLfloat> TexEnvfMap; 00052 typedef HashMap<GLenum, const GLfloat *> TexEnvfvMap; 00053 typedef HashMap<GLenum, GLfloat> PointParamfMap; 00054 typedef HashMap<GLenum, const GLfloat *> PointParamfvMap; 00055 typedef HashMap<GLenum, const GLfloat *> MaterialfvMap; 00056 typedef HashMap<GLenum, GLfloat> LightfMap; 00057 typedef HashMap<GLenum, const GLfloat *> LightfvMap; 00058 00062 #define MAX_LIGHTS 8 00063 Light* mLights[MAX_LIGHTS]; 00064 unsigned short mCurrentLights; 00065 00067 Matrix4 mViewMatrix; 00068 Matrix4 mWorldMatrix; 00069 Matrix4 mTextureMatrix; 00070 00072 FilterOptions mMinFilter; 00073 FilterOptions mMipFilter; 00074 00076 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS]; 00077 00079 unsigned short mFixedFunctionTextureUnits; 00080 00082 bool mColourWrite[4]; 00083 00085 GLboolean mDepthWrite; 00086 00088 uint32 mStencilMask; 00089 00090 GLfloat mAutoTextureMatrix[16]; 00091 00092 bool mUseAutoTextureMatrix; 00093 size_t mTextureCount; 00094 bool mTextureEnabled; 00095 00097 GLESSupport *mGLSupport; 00098 00099 /* The main GL context - main thread only */ 00100 GLESContext *mMainContext; 00101 00102 /* The current GL context - main thread only */ 00103 GLESContext *mCurrentContext; 00104 GLESGpuProgramManager *mGpuProgramManager; 00105 HardwareBufferManager* mHardwareBufferManager; 00106 00112 GLESRTTManager *mRTTManager; 00113 00118 ushort mActiveTextureUnit; 00119 ushort mActiveClientTextureUnit; 00120 TexEnviMap mActiveTexEnviMap; 00121 TexEnvfMap mActiveTexEnvfMap; 00122 TexEnvfvMap mActiveTexEnvfvMap; 00123 PointParamfMap mActivePointParamfMap; 00124 PointParamfvMap mActivePointParamfvMap; 00125 MaterialfvMap mActiveMaterialfvMap; 00126 LightfMap mActiveLightfMap; 00127 LightfvMap mActiveLightfvMap; 00128 GLint mActiveSourceBlend; 00129 GLint mActiveDestBlend; 00130 GLint mActiveDepthFunc; 00131 GLenum mActiveShadeModel; 00132 GLenum mActiveMatrixMode; 00133 GLfloat mActivePointSize; 00134 GLenum mActiveCullFaceMode; 00135 GLfloat mTexMaxAnisotropy; 00136 GLfloat mMaxTexMaxAnisotropy; 00137 GLclampf mActiveClearDepth; 00138 ColourValue mActiveClearColor; 00139 GLenum mActiveAlphaFunc; 00140 GLclampf mActiveAlphaFuncValue; 00141 00143 bool mGLInitialised; 00144 00146 unsigned int mDiscardBuffers; 00147 00151 GLenum mPolygonMode; 00152 00153 GLuint getCombinedMinMipFilter(void) const; 00154 00155 GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const; 00156 GLint getBlendMode(SceneBlendFactor ogreBlend) const; 00157 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00158 void setGLLight(size_t index, Light* lt); 00159 00161 void setGLLightPositionDirection(Light* lt, GLenum lightindex); 00162 void setLights(); 00163 00164 bool activateGLTextureUnit(size_t unit); 00165 bool activateGLClientTextureUnit(size_t unit); 00166 void setGLTexEnvi(GLenum target, GLenum name, GLint param); 00167 void setGLTexEnvf(GLenum target, GLenum name, GLfloat param); 00168 void setGLTexEnvfv(GLenum target, GLenum name, const GLfloat *param); 00169 void setGLPointParamf(GLenum name, GLfloat param); 00170 void setGLPointParamfv(GLenum name, const GLfloat *param); 00171 void setGLMaterialfv(GLenum face, GLenum name, const GLfloat *param); 00172 void setGLMatrixMode(GLenum mode); 00173 void setGLDepthMask(GLboolean flag); 00174 void setGLClearDepthf(GLclampf depth); 00175 void setGLColorMask(bool red, bool green, bool blue, bool alpha); 00176 void setGLLightf(GLenum light, GLenum name, GLfloat param); 00177 void setGLLightfv(GLenum light, GLenum name, const GLfloat *param); 00178 00179 public: 00180 // Default constructor / destructor 00181 GLESRenderSystem(); 00182 virtual ~GLESRenderSystem(); 00183 00184 // ---------------------------------- 00185 // Overridden RenderSystem functions 00186 // ---------------------------------- 00190 const String& getName(void) const; 00194 ConfigOptionMap& getConfigOptions(void); 00198 void setConfigOption(const String &name, const String &value); 00202 String validateConfigOptions(void); 00206 RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType"); 00210 virtual RenderSystemCapabilities* createRenderSystemCapabilities() const; 00214 void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary); 00218 void reinitialise(void); // Used if settings changed mid-rendering 00222 void shutdown(void); 00226 void setAmbientLight(float r, float g, float b); 00230 void setShadingType(ShadeOptions so); 00234 void setLightingEnabled(bool enabled); 00235 00237 RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 00238 bool fullScreen, const NameValuePairList *miscParams = 0); 00239 00241 DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ); 00242 00244 void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat, 00245 GLenum *stencilFormat ); 00246 00248 virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 00249 00253 void destroyRenderWindow(RenderWindow* pWin); 00257 String getErrorDescription(long errorNumber) const; 00261 VertexElementType getColourVertexElementType(void) const; 00265 void setNormaliseNormals(bool normalise); 00266 00267 // ----------------------------- 00268 // Low-level overridden members 00269 // ----------------------------- 00273 void _useLights(const LightList& lights, unsigned short limit); 00277 bool areFixedFunctionLightsInViewSpace() const { return true; } 00281 void _setWorldMatrix(const Matrix4 &m); 00285 void _setViewMatrix(const Matrix4 &m); 00289 void _setProjectionMatrix(const Matrix4 &m); 00293 void _setSurfaceParams(const ColourValue &ambient, 00294 const ColourValue &diffuse, const ColourValue &specular, 00295 const ColourValue &emissive, Real shininess, 00296 TrackVertexColourType tracking); 00300 void _setPointParameters(Real size, bool attenuationEnabled, 00301 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize); 00305 void _setPointSpritesEnabled(bool enabled); 00309 void _setTexture(size_t unit, bool enabled, const TexturePtr &tex); 00313 void _setTextureCoordSet(size_t stage, size_t index); 00317 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00318 const Frustum* frustum = 0); 00322 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00326 void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw); 00330 void _setTextureBorderColour(size_t stage, const ColourValue& colour); 00334 void _setTextureMipmapBias(size_t unit, float bias); 00338 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00342 void _setViewport(Viewport *vp); 00346 void _beginFrame(void); 00350 void _endFrame(void); 00354 void _setCullingMode(CullingMode mode); 00358 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00362 void _setDepthBufferCheckEnabled(bool enabled = true); 00366 void _setDepthBufferWriteEnabled(bool enabled = true); 00370 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00374 void _setDepthBias(float constantBias, float slopeScaleBias); 00378 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00382 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00386 void _convertProjectionMatrix(const Matrix4& matrix, 00387 Matrix4& dest, bool forGpuProgram = false); 00391 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00392 Matrix4& dest, bool forGpuProgram = false); 00396 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00397 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00401 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00402 Matrix4& dest, bool forGpuProgram = false); 00406 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00407 bool forGpuProgram); 00411 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00415 void enableClipPlane (ushort index, bool enable); 00419 void _setPolygonMode(PolygonMode level); 00423 void setStencilCheckEnabled(bool enabled); 00427 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00428 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00429 StencilOperation stencilFailOp = SOP_KEEP, 00430 StencilOperation depthFailOp = SOP_KEEP, 00431 StencilOperation passOp = SOP_KEEP, 00432 bool twoSidedOperation = false); 00436 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00440 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00444 void setVertexDeclaration(VertexDeclaration* decl); 00448 void setVertexBufferBinding(VertexBufferBinding* binding); 00452 void _render(const RenderOperation& op); 00456 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600); 00457 00458 void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; } 00459 unsigned int getDiscardBuffers(void) { return mDiscardBuffers; } 00460 00461 void clearFrameBuffer(unsigned int buffers, 00462 const ColourValue& colour = ColourValue::Black, 00463 Real depth = 1.0f, unsigned short stencil = 0); 00464 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00465 Real getHorizontalTexelOffset(void); 00466 Real getVerticalTexelOffset(void); 00467 Real getMinimumDepthInputValue(void); 00468 Real getMaximumDepthInputValue(void); 00469 void registerThread(); 00470 void unregisterThread(); 00471 void preExtraThreadsStarted(); 00472 void postExtraThreadsStarted(); 00473 void setClipPlanesImpl(const Ogre::PlaneList& planeList); 00474 00475 // ---------------------------------- 00476 // GLESRenderSystem specific members 00477 // ---------------------------------- 00479 GLESContext* _getMainContext() { return mMainContext; } 00487 void _unregisterContext(GLESContext *context); 00490 void _switchContext(GLESContext *context); 00494 void _oneTimeContextInitialization(); 00495 void initialiseContext(RenderWindow* primary); 00499 void _setRenderTarget(RenderTarget *target); 00500 00501 GLint convertCompareFunction(CompareFunction func) const; 00502 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00503 00504 void bindGpuProgram(GpuProgram* prg); 00505 void unbindGpuProgram(GpuProgramType gptype); 00506 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask); 00507 void bindGpuProgramPassIterationParameters(GpuProgramType gptype); 00508 00510 void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op ); 00512 void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp ); 00514 void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage ); 00516 unsigned int getDisplayMonitorCount() const; 00517 00518 GLenum _getPolygonMode(void) { return mPolygonMode; } 00519 00521 GLfloat _getCurrentAnisotropy(size_t unit); 00522 00523 void _setSceneBlendingOperation(SceneBlendOperation op); 00524 void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp); 00525 00527 virtual void beginProfileEvent( const String &eventName ) {} 00528 00530 virtual void endProfileEvent( void ) {} 00531 00533 virtual void markProfileEvent( const String &eventName ) {} 00534 }; 00535 } 00536 00537 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21