OgreGLESRenderSystem.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) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com>
00008 Copyright (c) 2000-2013 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 #include "OgreRenderSystem.h"
00035 
00036 namespace Ogre {
00037     class GLESContext;
00038     class GLESSupport;
00039     class GLESRTTManager;
00040     class GLESGpuProgramManager;
00041     class HardwareBufferManager;
00042     class GLESStateCacheManager;
00043 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
00044     class AndroidResourceManager;
00045 #endif
00046 
00049     class _OgreGLESExport GLESRenderSystem : public RenderSystem
00050     {
00051         private:
00052             typedef HashMap<GLenum, GLint>              TexEnviMap;
00053             typedef HashMap<GLenum, GLfloat>            TexEnvfMap;
00054             typedef HashMap<GLenum, const GLfloat *>    TexEnvfvMap;
00055             typedef HashMap<GLenum, GLfloat>            PointParamfMap;
00056             typedef HashMap<GLenum, const GLfloat *>    PointParamfvMap;
00057             typedef HashMap<GLenum, const GLfloat *>    MaterialfvMap;
00058             typedef HashMap<GLenum, GLfloat>            LightfMap;
00059             typedef HashMap<GLenum, const GLfloat *>    LightfvMap;
00060 
00064             #define MAX_LIGHTS 8
00065             Light* mLights[MAX_LIGHTS];
00066             unsigned short mCurrentLights;
00067 
00069             Matrix4 mViewMatrix;
00070             Matrix4 mWorldMatrix;
00071             Matrix4 mTextureMatrix;
00072 
00074             FilterOptions mMinFilter;
00075             FilterOptions mMipFilter;
00076 
00078             size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
00079 
00081             unsigned short mFixedFunctionTextureUnits;
00082 
00083             GLfloat mAutoTextureMatrix[16];
00084 
00085             bool mUseAutoTextureMatrix;
00086             size_t mTextureCount;
00087             bool mTextureEnabled;
00088         
00090             GLESSupport *mGLSupport;
00091 
00093             GLESStateCacheManager* mStateCacheManager;
00094         
00095             /* The main GL context - main thread only */
00096             GLESContext *mMainContext;
00097 
00098             /* The current GL context  - main thread only */
00099             GLESContext *mCurrentContext;
00100             GLESGpuProgramManager *mGpuProgramManager;
00101             HardwareBufferManager* mHardwareBufferManager;
00102 
00108             GLESRTTManager *mRTTManager;
00109 
00111             unsigned int mDiscardBuffers;
00112         
00114             bool mGLInitialised;
00115 
00116             GLuint getCombinedMinMipFilter(void) const;
00117 
00118             GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
00119             GLint getBlendMode(SceneBlendFactor ogreBlend) const;
00120             void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
00121             void setGLLight(size_t index, Light* lt);
00122 
00124             void setGLLightPositionDirection(Light* lt, GLenum lightindex);
00125             void setLights();
00126 
00127             bool activateGLTextureUnit(size_t unit);
00128             bool activateGLClientTextureUnit(size_t unit);
00129 
00130             // Mipmap count of the actual bounded texture
00131             size_t mCurTexMipCount;
00132         public:
00133             // Default constructor / destructor
00134             GLESRenderSystem();
00135             virtual ~GLESRenderSystem();
00136 
00137             // ----------------------------------
00138             // Overridden RenderSystem functions
00139             // ----------------------------------
00143             const String& getName(void) const;
00147             ConfigOptionMap& getConfigOptions(void);
00151             void setConfigOption(const String &name, const String &value);
00155             String validateConfigOptions(void);
00159             RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
00163             virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
00167             void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
00171             void reinitialise(void); // Used if settings changed mid-rendering
00175             void shutdown(void);
00179             void setAmbientLight(float r, float g, float b);
00183             void setShadingType(ShadeOptions so);
00187             void setLightingEnabled(bool enabled);
00188 
00190             RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00191                 bool fullScreen, const NameValuePairList *miscParams = 0);
00192 
00194             DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
00195 
00197             void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
00198                                             GLenum *stencilFormat );
00199 
00201             virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
00202 
00206             void destroyRenderWindow(RenderWindow* pWin);
00210             String getErrorDescription(long errorNumber) const;
00214             VertexElementType getColourVertexElementType(void) const;
00218             void setNormaliseNormals(bool normalise);
00219     
00220             // -----------------------------
00221             // Low-level overridden members
00222             // -----------------------------
00226             void _useLights(const LightList& lights, unsigned short limit);
00230             bool areFixedFunctionLightsInViewSpace() const { return true; }
00234             void _setWorldMatrix(const Matrix4 &m);
00238             void _setViewMatrix(const Matrix4 &m);
00242             void _setProjectionMatrix(const Matrix4 &m);
00246             void _setSurfaceParams(const ColourValue &ambient,
00247                     const ColourValue &diffuse, const ColourValue &specular,
00248                     const ColourValue &emissive, Real shininess,
00249                     TrackVertexColourType tracking);
00253             void _setPointParameters(Real size, bool attenuationEnabled,
00254                     Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
00258             void _setPointSpritesEnabled(bool enabled);
00262             void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
00266             void _setTextureCoordSet(size_t stage, size_t index);
00270             void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
00271                     const Frustum* frustum = 0);
00275             void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
00279             void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00283             void _setTextureBorderColour(size_t stage, const ColourValue& colour);
00287             void _setTextureMipmapBias(size_t unit, float bias);
00291             void _setTextureMatrix(size_t stage, const Matrix4& xform);
00295             void _setViewport(Viewport *vp);
00299             void _beginFrame(void);
00303             void _endFrame(void);
00307             void _setCullingMode(CullingMode mode);
00311             void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00315             void _setDepthBufferCheckEnabled(bool enabled = true);
00319             void _setDepthBufferWriteEnabled(bool enabled = true);
00323             void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00327             void _setDepthBias(float constantBias, float slopeScaleBias);
00331             void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00335             void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00339             void _convertProjectionMatrix(const Matrix4& matrix,
00340                     Matrix4& dest, bool forGpuProgram = false);
00344             void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00345                     Matrix4& dest, bool forGpuProgram = false);
00349             void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
00350                     Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00354             void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
00355                     Matrix4& dest, bool forGpuProgram = false);
00359             void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00360                     bool forGpuProgram);
00364             void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00368             void enableClipPlane (ushort index, bool enable);
00372             void _setPolygonMode(PolygonMode level);
00376             void setStencilCheckEnabled(bool enabled);
00380             void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00381                     uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 
00382                     StencilOperation stencilFailOp = SOP_KEEP,
00383                     StencilOperation depthFailOp = SOP_KEEP,
00384                     StencilOperation passOp = SOP_KEEP,
00385                     bool twoSidedOperation = false);
00389             void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
00393             virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
00394                 FilterOptions magFilter, FilterOptions mipFilter);
00398             void _setTextureUnitCompareEnabled(size_t unit, bool compare);
00402             void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00406             void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00410             virtual bool hasAnisotropicMipMapFilter() const { return false; }
00414             void setVertexDeclaration(VertexDeclaration* decl);
00418             void setVertexBufferBinding(VertexBufferBinding* binding);
00422             void _render(const RenderOperation& op);
00426             void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
00427 
00428             void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
00429             unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
00430         
00431             void clearFrameBuffer(unsigned int buffers,
00432                 const ColourValue& colour = ColourValue::Black,
00433                 Real depth = 1.0f, unsigned short stencil = 0);
00434             HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00435             Real getHorizontalTexelOffset(void);
00436             Real getVerticalTexelOffset(void);
00437             Real getMinimumDepthInputValue(void);
00438             Real getMaximumDepthInputValue(void);
00439             void registerThread();
00440             void unregisterThread();
00441             void preExtraThreadsStarted();
00442             void postExtraThreadsStarted();
00443             void setClipPlanesImpl(const Ogre::PlaneList& planeList);
00444 
00445             // ----------------------------------
00446             // GLESRenderSystem specific members
00447             // ----------------------------------
00449             GLESContext* _getMainContext() { return mMainContext; }
00457             void _unregisterContext(GLESContext *context);
00460             void _switchContext(GLESContext *context);
00464             void _oneTimeContextInitialization();
00465             void initialiseContext(RenderWindow* primary);
00469             void _setRenderTarget(RenderTarget *target);
00470 
00471             GLint convertCompareFunction(CompareFunction func) const;
00472             GLint convertStencilOp(StencilOperation op, bool invert = false) const;
00473 
00474             void bindGpuProgram(GpuProgram* prg);
00475             void unbindGpuProgram(GpuProgramType gptype);
00476             void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
00477             void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00478 
00480             void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
00482             void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
00484             void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
00486             unsigned int getDisplayMonitorCount() const;
00487 
00489             GLfloat _getCurrentAnisotropy(size_t unit);
00490 
00491             void _setSceneBlendingOperation(SceneBlendOperation op);
00492             void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
00493 
00494             void _destroyDepthBuffer(RenderWindow* pRenderWnd);
00495         
00497             virtual void beginProfileEvent( const String &eventName ) {}
00498 
00500             virtual void endProfileEvent( void ) {}
00501             
00503             virtual void markProfileEvent( const String &eventName ) {}
00504         
00505 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
00506             void resetRenderer(RenderWindow* pRenderWnd);
00507         
00508             static AndroidResourceManager* getResourceManager();
00509     private:
00510             static AndroidResourceManager* mResourceManager;
00511 #endif
00512     };
00513 }
00514 
00515 #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