OgreGLES2RenderSystem.h
Go to the documentation of this file.
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) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __GLES2RenderSystem_H__
00030 #define __GLES2RenderSystem_H__
00031 
00032 #include "OgreGLES2Prerequisites.h"
00033 
00034 #include "OgreMaterialManager.h"
00035 #include "OgreRenderSystem.h"
00036 #include "OgreGLES2GpuProgram.h"
00037 
00038 namespace Ogre {
00039     class GLES2Context;
00040     class GLES2Support;
00041     class GLES2RTTManager;
00042     class GLES2GpuProgramManager;
00043     class GLSLESProgramFactory;
00044     class GLES2StateCacheManager;
00045 #if !OGRE_NO_GLES2_CG_SUPPORT
00046     class GLSLESCgProgramFactory;
00047 #endif
00048     class GLSLESGpuProgram;
00049     class HardwareBufferManager;
00050 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
00051     class AndroidResourceManager;
00052 #endif
00053     
00057     class _OgreGLES2Export GLES2RenderSystem : public RenderSystem
00058     {
00059         private:
00061             Matrix4 mViewMatrix;
00062             Matrix4 mWorldMatrix;
00063             Matrix4 mTextureMatrix;
00064 
00066             FilterOptions mMinFilter;
00067             FilterOptions mMipFilter;
00068 
00070             size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
00071 
00073             GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
00074 
00076             unsigned short mFixedFunctionTextureUnits;
00077 
00078             GLfloat mAutoTextureMatrix[16];
00079 
00080             bool mUseAutoTextureMatrix;
00081 
00083             GLES2Support *mGLSupport;
00084 
00086             GLES2StateCacheManager* mStateCacheManager;
00087             
00088             /* The main GL context - main thread only */
00089             GLES2Context *mMainContext;
00090 
00091             /* The current GL context  - main thread only */
00092             GLES2Context *mCurrentContext;
00093 
00094             typedef list<GLES2Context*>::type GLES2ContextList;
00096             GLES2ContextList mBackgroundContextList;
00097 
00098             GLES2GpuProgramManager *mGpuProgramManager;
00099             GLSLESProgramFactory* mGLSLESProgramFactory;
00100 #if !OGRE_NO_GLES2_CG_SUPPORT
00101             GLSLESCgProgramFactory* mGLSLESCgProgramFactory;
00102 #endif
00103             HardwareBufferManager* mHardwareBufferManager;
00104 
00110             GLES2RTTManager *mRTTManager;
00111 
00113             bool mGLInitialised;
00114 
00115             // local data member of _render that were moved here to improve performance
00116             // (save allocations)
00117             vector<GLuint>::type mRenderAttribsBound;
00118             vector<GLuint>::type mRenderInstanceAttribsBound;
00119 
00120             GLint getCombinedMinMipFilter(void) const;
00121 
00122             GLES2GpuProgram* mCurrentVertexProgram;
00123             GLES2GpuProgram* mCurrentFragmentProgram;
00124 
00125             GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
00126             GLenum getBlendMode(SceneBlendFactor ogreBlend) const;
00127             void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer,
00128                                         const size_t vertexStart,
00129                                         vector<GLuint>::type &attribsBound,
00130                                         vector<GLuint>::type &instanceAttribsBound,
00131                                         bool updateVAO);
00132 
00133             // Mipmap count of the actual bounded texture
00134             size_t mCurTexMipCount;
00135             GLint mViewport[4];
00136             GLint mScissor[4];
00137 
00138         public:
00139             // Default constructor / destructor
00140             GLES2RenderSystem();
00141             virtual ~GLES2RenderSystem();
00142         
00143             friend class ShaderGeneratorTechniqueResolverListener;
00144 
00145             // ----------------------------------
00146             // Overridden RenderSystem functions
00147             // ----------------------------------
00151             const String& getName(void) const;
00155             ConfigOptionMap& getConfigOptions(void);
00159             void setConfigOption(const String &name, const String &value);
00163             String validateConfigOptions(void);
00167             RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
00171             virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
00175             void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
00179             void reinitialise(void); // Used if settings changed mid-rendering
00183             void shutdown(void);
00187             void setAmbientLight(float r, float g, float b) { };   // Not supported
00191             void setShadingType(ShadeOptions so) { };   // Not supported
00195             void setLightingEnabled(bool enabled) { };   // Not supported
00196 
00198             RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00199                 bool fullScreen, const NameValuePairList *miscParams = 0);
00200 
00202             DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
00203 
00205             void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
00206                                             GLenum *stencilFormat );
00207 
00209             virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
00210 
00214             void destroyRenderWindow(RenderWindow* pWin);
00218             String getErrorDescription(long errorNumber) const;
00222             VertexElementType getColourVertexElementType(void) const;
00226             void setNormaliseNormals(bool normalise) { };   // Not supported
00227 
00228             // -----------------------------
00229             // Low-level overridden members
00230             // -----------------------------
00234             void _useLights(const LightList& lights, unsigned short limit) { };   // Not supported
00238             bool areFixedFunctionLightsInViewSpace() const { return true; }
00242             void _setWorldMatrix(const Matrix4 &m);
00246             void _setViewMatrix(const Matrix4 &m);
00250             void _setProjectionMatrix(const Matrix4 &m);
00254             void _setSurfaceParams(const ColourValue &ambient,
00255                                    const ColourValue &diffuse, const ColourValue &specular,
00256                                    const ColourValue &emissive, Real shininess,
00257                                    TrackVertexColourType tracking) {}
00261             void _setPointParameters(Real size, bool attenuationEnabled,
00262                                      Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) {}
00266             void _setPointSpritesEnabled(bool enabled) {}
00270             void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
00274             void _setTextureCoordSet(size_t stage, size_t index);
00278             void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
00279                     const Frustum* frustum = 0) { };   // Not supported
00283             void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { };   // Not supported
00287             void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00291             void _setTextureBorderColour(size_t stage, const ColourValue& colour) { };   // Not supported
00295             void _setTextureMipmapBias(size_t unit, float bias) { };   // Not supported
00299             void _setTextureMatrix(size_t stage, const Matrix4& xform) { };   // Not supported
00303             void _setViewport(Viewport *vp);
00307             void _beginFrame(void);
00311             void _endFrame(void);
00315             void _setCullingMode(CullingMode mode);
00319             void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00323             void _setDepthBufferCheckEnabled(bool enabled = true);
00327             void _setDepthBufferWriteEnabled(bool enabled = true);
00331             void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00335             void _setDepthBias(float constantBias, float slopeScaleBias);
00339             void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00343             void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00347             void _convertProjectionMatrix(const Matrix4& matrix,
00348                     Matrix4& dest, bool forGpuProgram = false);
00352             void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00353                     Matrix4& dest, bool forGpuProgram = false);
00357             void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
00358                     Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00362             void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00363                     Matrix4& dest, bool forGpuProgram = false);
00367             void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00368                     bool forGpuProgram);
00372             void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00376             void enableClipPlane (ushort index, bool enable);
00380             void _setPolygonMode(PolygonMode level);
00384             void setStencilCheckEnabled(bool enabled);
00388             void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00389                     uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
00390                     StencilOperation stencilFailOp = SOP_KEEP,
00391                     StencilOperation depthFailOp = SOP_KEEP,
00392                     StencilOperation passOp = SOP_KEEP,
00393                     bool twoSidedOperation = false);
00397             void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
00401             void _setTextureUnitCompareEnabled(size_t unit, bool compare);          
00405             virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
00406                 FilterOptions magFilter, FilterOptions mipFilter);              
00410             void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00414             void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00418             virtual bool hasAnisotropicMipMapFilter() const { return false; }   
00422             void setVertexDeclaration(VertexDeclaration* decl);
00426             void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding);
00430             void setVertexBufferBinding(VertexBufferBinding* binding) {}
00434             void _render(const RenderOperation& op);
00438             void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
00439 
00440             void clearFrameBuffer(unsigned int buffers,
00441                 const ColourValue& colour = ColourValue::Black,
00442                 Real depth = 1.0f, unsigned short stencil = 0);
00443             HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00444             Real getHorizontalTexelOffset(void) { return 0.0; }               // No offset in GL
00445             Real getVerticalTexelOffset(void) { return 0.0; }                 // No offset in GL
00446             Real getMinimumDepthInputValue(void) { return -1.0f; }            // Range [-1.0f, 1.0f]
00447             Real getMaximumDepthInputValue(void) { return 1.0f; }             // Range [-1.0f, 1.0f]
00448             OGRE_MUTEX(mThreadInitMutex);
00449             void registerThread();
00450             void unregisterThread();
00451             void preExtraThreadsStarted();
00452             void postExtraThreadsStarted();
00453             void setClipPlanesImpl(const Ogre::PlaneList& planeList) {}
00454             GLES2Support* getGLSupportRef() { return mGLSupport; }
00455 
00456             // ----------------------------------
00457             // GLES2RenderSystem specific members
00458             // ----------------------------------
00460             GLES2Context* _getMainContext() { return mMainContext; }
00468             void _unregisterContext(GLES2Context *context);
00471             void _switchContext(GLES2Context *context);
00475             void _oneTimeContextInitialization();
00476             void initialiseContext(RenderWindow* primary);
00480             void _setRenderTarget(RenderTarget *target);
00481 
00482             GLES2Support* getGLES2Support() { return mGLSupport; }
00483             GLint convertCompareFunction(CompareFunction func) const;
00484             GLint convertStencilOp(StencilOperation op, bool invert = false) const;
00485 
00486             void bindGpuProgram(GpuProgram* prg);
00487             void unbindGpuProgram(GpuProgramType gptype);
00488             void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
00489             void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00490 
00492             void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
00494             void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
00496             void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
00498             unsigned int getDisplayMonitorCount() const;
00499 
00501             GLfloat _getCurrentAnisotropy(size_t unit);
00502 
00503             void _setSceneBlendingOperation(SceneBlendOperation op);
00504             void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
00505 
00506             unsigned int getDiscardBuffers(void);
00507 
00508             void _destroyDepthBuffer(RenderWindow* pRenderWnd);
00509         
00511             virtual void beginProfileEvent( const String &eventName );
00512             
00514             virtual void endProfileEvent( void );
00515             
00517             virtual void markProfileEvent( const String &eventName );
00518 
00519 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
00520             void resetRenderer(RenderWindow* pRenderWnd);
00521         
00522             static AndroidResourceManager* getResourceManager();
00523     private:
00524             static AndroidResourceManager* mResourceManager;
00525 #endif
00526     };
00527 }
00528 
00529 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:42