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-2012 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 #if !OGRE_NO_GLES2_CG_SUPPORT
00045     class GLSLESCgProgramFactory;
00046 #endif
00047     class GLSLESGpuProgram;
00048     class HardwareBufferManager;
00049 
00053     class _OgreGLES2Export GLES2RenderSystem : public RenderSystem
00054     {
00055         private:
00056             typedef HashMap<GLenum, GLuint>  BindBufferMap;
00057 
00059             Matrix4 mViewMatrix;
00060             Matrix4 mWorldMatrix;
00061             Matrix4 mTextureMatrix;
00062 
00064             FilterOptions mMinFilter;
00065             FilterOptions mMipFilter;
00066 
00068             size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
00069 
00071             GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
00072 
00074             unsigned short mFixedFunctionTextureUnits;
00075 
00077             bool mColourWrite[4];
00078 
00080             bool mDepthWrite;
00081 
00083             uint32 mStencilMask;
00084 
00085             GLfloat mAutoTextureMatrix[16];
00086 
00087             bool mUseAutoTextureMatrix;
00088 
00090             GLES2Support *mGLSupport;
00091 
00092             /* The main GL context - main thread only */
00093             GLES2Context *mMainContext;
00094 
00095             /* The current GL context  - main thread only */
00096             GLES2Context *mCurrentContext;
00097             GLES2GpuProgramManager *mGpuProgramManager;
00098             GLSLESProgramFactory* mGLSLESProgramFactory;
00099 #if !OGRE_NO_GLES2_CG_SUPPORT
00100             GLSLESCgProgramFactory* mGLSLESCgProgramFactory;
00101 #endif
00102             HardwareBufferManager* mHardwareBufferManager;
00103 
00109             GLES2RTTManager *mRTTManager;
00110 
00115             GLenum mActiveTextureUnit;
00116             BindBufferMap mActiveBufferMap;
00117 
00119             bool mGLInitialised;
00120 
00122             unsigned int mDiscardBuffers;
00123 
00127             GLenum mPolygonMode;
00128 
00129             // local data member of _render that were moved here to improve performance
00130             // (save allocations)
00131             vector<GLuint>::type mRenderAttribsBound;
00132 
00133             GLint getCombinedMinMipFilter(void) const;
00134 
00135             GLES2GpuProgram* mCurrentVertexProgram;
00136             GLES2GpuProgram* mCurrentFragmentProgram;
00137 
00138             GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
00139             GLenum getBlendMode(SceneBlendFactor ogreBlend) const;
00140 
00141             bool activateGLTextureUnit(size_t unit);
00142 
00143         public:
00144             // Default constructor / destructor
00145             GLES2RenderSystem();
00146             virtual ~GLES2RenderSystem();
00147         
00148             friend class ShaderGeneratorTechniqueResolverListener;
00149 
00150             // ----------------------------------
00151             // Overridden RenderSystem functions
00152             // ----------------------------------
00156             const String& getName(void) const;
00160             ConfigOptionMap& getConfigOptions(void);
00164             void setConfigOption(const String &name, const String &value);
00168             String validateConfigOptions(void);
00172             RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
00176             virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
00180             void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
00184             void reinitialise(void); // Used if settings changed mid-rendering
00188             void shutdown(void);
00192             void setAmbientLight(float r, float g, float b) { };   // Not supported
00196             void setShadingType(ShadeOptions so) { };   // Not supported
00200             void setLightingEnabled(bool enabled) { };   // Not supported
00201 
00203             RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00204                 bool fullScreen, const NameValuePairList *miscParams = 0);
00205 
00207             DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
00208 
00210             void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
00211                                             GLenum *stencilFormat );
00212 
00214             virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
00215 
00219             void destroyRenderWindow(RenderWindow* pWin);
00223             String getErrorDescription(long errorNumber) const;
00227             VertexElementType getColourVertexElementType(void) const;
00231             void setNormaliseNormals(bool normalise) { };   // Not supported
00232 
00233             // -----------------------------
00234             // Low-level overridden members
00235             // -----------------------------
00239             void _useLights(const LightList& lights, unsigned short limit) { };   // Not supported
00243             bool areFixedFunctionLightsInViewSpace() const { return true; }
00247             void _setWorldMatrix(const Matrix4 &m);
00251             void _setViewMatrix(const Matrix4 &m);
00255             void _setProjectionMatrix(const Matrix4 &m);
00259             void _setSurfaceParams(const ColourValue &ambient,
00260                                    const ColourValue &diffuse, const ColourValue &specular,
00261                                    const ColourValue &emissive, Real shininess,
00262                                    TrackVertexColourType tracking) {}
00266             void _setPointParameters(Real size, bool attenuationEnabled,
00267                                      Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) {}
00271             void _setPointSpritesEnabled(bool enabled) {}
00275             void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
00279             void _setTextureCoordSet(size_t stage, size_t index);
00283             void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
00284                     const Frustum* frustum = 0) { };   // Not supported
00288             void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { };   // Not supported
00292             void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00296             void _setTextureBorderColour(size_t stage, const ColourValue& colour) { };   // Not supported
00300             void _setTextureMipmapBias(size_t unit, float bias) { };   // Not supported
00304             void _setTextureMatrix(size_t stage, const Matrix4& xform) { };   // Not supported
00308             void _setViewport(Viewport *vp);
00312             void _beginFrame(void);
00316             void _endFrame(void);
00320             void _setCullingMode(CullingMode mode);
00324             void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00328             void _setDepthBufferCheckEnabled(bool enabled = true);
00332             void _setDepthBufferWriteEnabled(bool enabled = true);
00336             void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00340             void _setDepthBias(float constantBias, float slopeScaleBias);
00344             void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00348             void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00352             void _convertProjectionMatrix(const Matrix4& matrix,
00353                     Matrix4& dest, bool forGpuProgram = false);
00357             void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00358                     Matrix4& dest, bool forGpuProgram = false);
00362             void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
00363                     Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00367             void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00368                     Matrix4& dest, bool forGpuProgram = false);
00372             void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00373                     bool forGpuProgram);
00377             void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00381             void enableClipPlane (ushort index, bool enable);
00385             void _setPolygonMode(PolygonMode level);
00389             void setStencilCheckEnabled(bool enabled);
00393             void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00394                     uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
00395                     StencilOperation stencilFailOp = SOP_KEEP,
00396                     StencilOperation depthFailOp = SOP_KEEP,
00397                     StencilOperation passOp = SOP_KEEP,
00398                     bool twoSidedOperation = false);
00402             void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00406             void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00410             void setVertexDeclaration(VertexDeclaration* decl) {}
00414             void setVertexBufferBinding(VertexBufferBinding* binding) {}
00418             void _render(const RenderOperation& op);
00422             void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
00423         
00424             void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
00425             unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
00426 
00427             void clearFrameBuffer(unsigned int buffers,
00428                 const ColourValue& colour = ColourValue::Black,
00429                 Real depth = 1.0f, unsigned short stencil = 0);
00430             HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00431             Real getHorizontalTexelOffset(void) { return 0.0; }               // No offset in GL
00432             Real getVerticalTexelOffset(void) { return 0.0; }                 // No offset in GL
00433             Real getMinimumDepthInputValue(void) { return -1.0f; }            // Range [-1.0f, 1.0f]
00434             Real getMaximumDepthInputValue(void) { return 1.0f; }             // Range [-1.0f, 1.0f]
00435             void registerThread() {}
00436             void unregisterThread() {}
00437             void preExtraThreadsStarted() {}
00438             void postExtraThreadsStarted() {}
00439             void setClipPlanesImpl(const Ogre::PlaneList& planeList) {}
00440 
00441             // ----------------------------------
00442             // GLES2RenderSystem specific members
00443             // ----------------------------------
00445             GLES2Context* _getMainContext() { return mMainContext; }
00453             void _unregisterContext(GLES2Context *context);
00456             void _switchContext(GLES2Context *context);
00460             void _oneTimeContextInitialization();
00461             void initialiseContext(RenderWindow* primary);
00465             void _setRenderTarget(RenderTarget *target);
00466 
00467             GLES2Support* getGLES2Support() { return mGLSupport; }
00468             GLint convertCompareFunction(CompareFunction func) const;
00469             GLint convertStencilOp(StencilOperation op, bool invert = false) const;
00470 
00471             void bindGpuProgram(GpuProgram* prg);
00472             void unbindGpuProgram(GpuProgramType gptype);
00473             void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
00474             void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00475 
00477             void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
00479             void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
00481             void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
00483             unsigned int getDisplayMonitorCount() const;
00484 
00486             GLfloat _getCurrentAnisotropy(size_t unit);
00487 
00488             GLenum _getPolygonMode(void) { return mPolygonMode; }
00489 
00490             void _setSceneBlendingOperation(SceneBlendOperation op);
00491             void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
00492 
00493             void _bindGLBuffer(GLenum target, GLuint buffer);
00494             void _deleteGLBuffer(GLenum target, GLuint buffer);
00495 
00497             virtual void beginProfileEvent( const String &eventName );
00498             
00500             virtual void endProfileEvent( void );
00501             
00503             virtual void markProfileEvent( const String &eventName );
00504     };
00505 }
00506 
00507 #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 Sun Sep 2 2012 07:27:21