| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #ifndef __GLRenderSystem_H__
- #define __GLRenderSystem_H__
- #include "OgreGLPrerequisites.h"
- #include "OgrePlatform.h"
- #include "OgreRenderSystem.h"
- #include "OgreGLHardwareBufferManager.h"
- #include "OgreGLGpuProgramManager.h"
- #include "OgreGLSLProgramFactory.h"
- #include "OgreConfigOptionMap.h"
- #include "OgreVector4.h"
- namespace Ogre {
- /**
- Implementation of GL as a rendering system.
- */
- class _OgreGLExport GLRenderSystem : public RenderSystem
- {
- private:
- /// Rendering loop control
- bool mStopRendering;
- /** Array of up to 8 lights, indexed as per API
- Note that a null value indicates a free slot
- */
- #define MAX_LIGHTS 8
- Light* mLights[MAX_LIGHTS];
- /// View matrix to set world against
- Matrix4 mViewMatrix;
- Matrix4 mWorldMatrix;
- Matrix4 mTextureMatrix;
- /// Last min & mip filtering options, so we can combine them
- FilterOptions mMinFilter;
- FilterOptions mMipFilter;
- /// What texture coord set each texture unit is using
- size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
- /// Holds texture type settings for every stage
- GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
- /// Number of fixed-function texture units
- unsigned short mFixedFunctionTextureUnits;
- void initConfigOptions(void);
- void initInputDevices(void);
- void processInputDevices(void);
- void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
-
- GLint getBlendMode(SceneBlendFactor ogreBlend) const;
- GLint getTextureAddressingMode(TextureState::TextureAddressingMode tam) const;
- void initialiseContext(RenderWindow* primary);
- void setLights();
- /// Store last depth write state
- bool mDepthWrite;
- /// Store last stencil mask state
- uint32 mStencilMask;
- /// Store last colour write state
- bool mColourWrite[4];
- GLint convertCompareFunction(CompareFunction func) const;
- GLint convertStencilOp(StencilOperation op, bool invert = false) const;
- /// Internal method for anisotropy validation
- GLfloat _getCurrentAnisotropy(size_t unit);
-
- /// GL support class, used for creating windows etc.
- GLSupport* mGLSupport;
- bool mUseAutoTextureMatrix;
- GLfloat mAutoTextureMatrix[16];
- /// Check if the GL system has already been initialised
- bool mGLInitialised;
- HardwareBufferManager* mHardwareBufferManager;
- GLGpuProgramManager* mGpuProgramManager;
- GLSLProgramFactory* mGLSLProgramFactory;
- unsigned short mCurrentLights;
- GLuint getCombinedMinMipFilter(void) const;
- GLGpuProgram* mCurrentVertexProgram;
- GLGpuProgram* mCurrentFragmentProgram;
- GLGpuProgram* mCurrentGeometryProgram;
- /* The main GL context - main thread only */
- GLContext *mMainContext;
- /* The current GL context - main thread only */
- GLContext *mCurrentContext;
- typedef list<GLContext*>::type GLContextList;
- /// List of background thread contexts
- GLContextList mBackgroundContextList;
- /** Manager object for creating render textures.
- Direct render to texture via GL_EXT_framebuffer_object is preferable
- to pbuffers, which depend on the GL support used and are generally
- unwieldy and slow. However, FBO support for stencil buffers is poor.
- */
- GLRTTManager *mRTTManager;
- ushort mActiveTextureUnit;
- protected:
- void setClipPlanesImpl(const PlaneList& clipPlanes);
- bool activateGLTextureUnit(size_t unit);
- public:
- // Default constructor / destructor
- GLRenderSystem();
- ~GLRenderSystem();
- // ----------------------------------
- // Overridden RenderSystem functions
- // ----------------------------------
- /** See
- RenderSystem
- */
- const String& getName(void) const;
- /** See
- RenderSystem
- */
- ConfigOptionMap& getConfigOptions(void);
- /** See
- RenderSystem
- */
- void setConfigOption(const String &name, const String &value);
- /** See
- RenderSystem
- */
- String validateConfigOptions(void);
- /** See
- RenderSystem
- */
- RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
- /** See
- RenderSystem
- */
- virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
- /** See
- RenderSystem
- */
- void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
- /** See
- RenderSystem
- */
- void reinitialise(void); // Used if settings changed mid-rendering
- /** See
- RenderSystem
- */
- void shutdown(void);
- /** See
- RenderSystem
- */
- void setAmbientLight(float r, float g, float b);
- /** See
- RenderSystem
- */
- void setShadingType(ShadeOptions so);
- /** See
- RenderSystem
- */
- void setLightingEnabled(bool enabled);
-
- /// @copydoc RenderSystem::_createRenderWindow
- RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
- bool fullScreen, const NameValuePairList *miscParams = 0);
- /// @copydoc RenderSystem::_createRenderWindows
- bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
- RenderWindowList& createdWindows);
-
- /// @copydoc RenderSystem::createMultiRenderTarget
- virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
-
- /** See
- RenderSystem
- */
- void destroyRenderWindow(RenderWindow* pWin);
- /** See
- RenderSystem
- */
- String getErrorDescription(long errorNumber) const;
- /** See
- RenderSystem
- */
- VertexElementType getColourVertexElementType(void) const;
- /** See
- RenderSystem
- */
- void setNormaliseNormals(bool normalise);
- // -----------------------------
- // Low-level overridden members
- // -----------------------------
- /** See
- RenderSystem
- */
- void _useLights(const LightList& lights, unsigned short limit);
- /** See
- RenderSystem
- */
- bool areFixedFunctionLightsInViewSpace() const { return true; }
- /** See
- RenderSystem
- */
- void _setWorldMatrix(const Matrix4 &m);
- /** See
- RenderSystem
- */
- void _setViewMatrix(const Matrix4 &m);
- /** See
- RenderSystem
- */
- void _setProjectionMatrix(const Matrix4 &m);
- /** See
- RenderSystem
- */
- void _setSurfaceParams(const ColourValue &ambient,
- const ColourValue &diffuse, const ColourValue &specular,
- const ColourValue &emissive, Real shininess,
- TrackVertexColourType tracking);
- /** See
- RenderSystem
- */
- void _setPointParameters(Real size, bool attenuationEnabled,
- Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
- /** See
- RenderSystem
- */
- void _setPointSpritesEnabled(bool enabled);
- /** See
- RenderSystem
- */
- void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
- /** See
- RenderSystem
- */
- void _setTextureCoordSet(size_t stage, size_t index);
- /** See
- RenderSystem
- */
- void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
- const Frustum* frustum = 0);
- /** See
- RenderSystem
- */
- void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
- /** See
- RenderSystem
- */
- void _setTextureAddressingMode(size_t stage, const TextureState::UVWAddressingMode& uvw);
- /** See
- RenderSystem
- */
- void _setTextureBorderColour(size_t stage, const ColourValue& colour);
- /** See
- RenderSystem
- */
- void _setTextureMipmapBias(size_t unit, float bias);
- /** See
- RenderSystem
- */
- void _setTextureMatrix(size_t stage, const Matrix4& xform);
- /** See
- RenderSystem
- */
- void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
- /** See
- RenderSystem
- */
- void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
- /** See
- RenderSystem
- */
- void _setSceneBlendingOperation(SceneBlendOperation op);
- /** See
- RenderSystem
- */
- void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
- /** See
- RenderSystem
- */
- void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
- /** See
- RenderSystem
- */
- void _setViewport(Viewport *vp);
- /** See
- RenderSystem
- */
- void _beginFrame(void);
- /** See
- RenderSystem
- */
- void _endFrame(void);
- /** See
- RenderSystem
- */
- void _setCullingMode(CullingMode mode);
- /** See
- RenderSystem
- */
- void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
- /** See
- RenderSystem
- */
- void _setDepthBufferCheckEnabled(bool enabled = true);
- /** See
- RenderSystem
- */
- void _setDepthBufferWriteEnabled(bool enabled = true);
- /** See
- RenderSystem
- */
- void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
- /** See
- RenderSystem
- */
- void _setDepthBias(float constantBias, float slopeScaleBias);
- /** See
- RenderSystem
- */
- void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
- /** See
- RenderSystem
- */
- void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
- /** See
- RenderSystem
- */
- void _convertProjectionMatrix(const Matrix4& matrix,
- Matrix4& dest, bool forGpuProgram = false);
- /** See
- RenderSystem
- */
- void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
- Matrix4& dest, bool forGpuProgram = false);
- /** See
- RenderSystem
- */
- void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
- Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
- /** See
- RenderSystem
- */
- void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
- Matrix4& dest, bool forGpuProgram = false);
- /** See
- RenderSystem
- */
- void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
- bool forGpuProgram);
- /** See
- RenderSystem
- */
- void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
- /** See
- RenderSystem
- */
- void enableClipPlane (ushort index, bool enable);
- /** See
- RenderSystem
- */
- void _setPolygonMode(PolygonMode level);
- /** See
- RenderSystem
- */
- void setStencilCheckEnabled(bool enabled);
- /** See
- RenderSystem.
- */
- void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
- uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
- StencilOperation stencilFailOp = SOP_KEEP,
- StencilOperation depthFailOp = SOP_KEEP,
- StencilOperation passOp = SOP_KEEP,
- bool twoSidedOperation = false);
- /** See
- RenderSystem
- */
- void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
- /** See
- RenderSystem
- */
- void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
- /** See
- RenderSystem
- */
- void setVertexDeclaration(VertexDeclaration* decl);
- /** See
- RenderSystem
- */
- void setVertexBufferBinding(VertexBufferBinding* binding);
- /** See
- RenderSystem
- */
- void _render(const RenderOperation& op);
- /** See
- RenderSystem
- */
- void bindGpuProgram(GpuProgram* prg);
- /** See
- RenderSystem
- */
- void unbindGpuProgram(GpuProgramType gptype);
- /** See
- RenderSystem
- */
- void bindGpuProgramParameters(GpuProgramType gptype,
- GpuProgramParametersSharedPtr params, uint16 variabilityMask);
- /** See
- RenderSystem
- */
- void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
- /** See
- RenderSystem
- */
- void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
- void clearFrameBuffer(unsigned int buffers,
- const ColourValue& colour = ColourValue::Black,
- Real depth = 1.0f, unsigned short stencil = 0);
- HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
- Real getHorizontalTexelOffset(void);
- Real getVerticalTexelOffset(void);
- Real getMinimumDepthInputValue(void);
- Real getMaximumDepthInputValue(void);
- OGRE_MUTEX(mThreadInitMutex)
- void registerThread();
- void unregisterThread();
- void preExtraThreadsStarted();
- void postExtraThreadsStarted();
- // ----------------------------------
- // GLRenderSystem specific members
- // ----------------------------------
- /** One time initialization for the RenderState of a context. Things that
- only need to be set once, like the LightingModel can be defined here.
- */
- void _oneTimeContextInitialization();
- /** Switch GL context, dealing with involved internal cached states too
- */
- void _switchContext(GLContext *context);
- /**
- * Set current render target to target, enabling its GL context if needed
- */
- void _setRenderTarget(RenderTarget *target);
- /** Unregister a render target->context mapping. If the context of target
- is the current context, change the context to the main context so it
- can be destroyed safely.
-
- @note This is automatically called by the destructor of
- GLContext.
- */
- void _unregisterContext(GLContext *context);
- /** Returns the main context */
- GLContext* _getMainContext() {return mMainContext;}
- /// @copydoc RenderSystem::getDisplayMonitorCount
- unsigned int getDisplayMonitorCount() const;
- };
- }
- #endif
|