OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGL3PlusRenderSystem.h
Go to the documentation of this file.
1 /*
2  -----------------------------------------------------------------------------
3  This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5  For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9  Permission is hereby granted, free of charge, to any person obtaining a copy
10  of this software and associated documentation files (the "Software"), to deal
11  in the Software without restriction, including without limitation the rights
12  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  copies of the Software, and to permit persons to whom the Software is
14  furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  THE SOFTWARE.
26  -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __GL3PlusRenderSystem_H__
30 #define __GL3PlusRenderSystem_H__
31 
33 
34 #include "OgreMaterialManager.h"
35 #include "OgreRenderSystem.h"
36 #include "OgreGLSLShader.h"
37 
38 namespace Ogre {
39  class GL3PlusContext;
40  class GL3PlusSupport;
41  class GL3PlusRTTManager;
42  class GLSLShaderManager;
43  class GLSLShaderFactory;
44  class HardwareBufferManager;
45 
50  {
51  private:
54 
55  typedef HashMap<GLenum, GLuint> BindBufferMap;
56 
61 
65 
67 
72 
74  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
75 
77  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
78 
80 
83 
84  void initConfigOptions(void);
85 
87  bool mColourWrite[4];
88 
91 
94 
95  GLfloat mAutoTextureMatrix[16];
96 
98 
101 
102  /* The main GL context - main thread only */
104 
105  /* The current GL context - main thread only */
107 
111 
115 
122 
129 
132 
133  // local data members of _render that were moved here to improve performance
134  // (save allocations)
137 
141  GLenum mPolygonMode;
142 
143  GLint getCombinedMinMipFilter(void) const;
144 
151 
152  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
153  GLenum getBlendMode(SceneBlendFactor ogreBlend) const;
154 
155  bool activateGLTextureUnit(size_t unit);
156  void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer,
157  const size_t vertexStart,
158  vector<GLuint>::type &attribsBound,
159  vector<GLuint>::type &instanceAttribsBound,
160  bool updateVAO);
161 
162  public:
163  // Default constructor / destructor
166 
167  friend class ShaderGeneratorTechniqueResolverListener;
168 
169  // ----------------------------------
170  // Overridden RenderSystem functions
171  // ----------------------------------
175  const String& getName(void) const;
179  ConfigOptionMap& getConfigOptions(void);
183  void setConfigOption(const String &name, const String &value);
187  String validateConfigOptions(void);
191  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
195  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
199  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
203  void reinitialise(void); // Used if settings changed mid-rendering
207  void shutdown(void);
211  void setAmbientLight(float r, float g, float b) { }; // Not supported
215  void setShadingType(ShadeOptions so) { }; // Not supported
219  void setLightingEnabled(bool enabled) { }; // Not supported
220 
222  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
223  bool fullScreen, const NameValuePairList *miscParams = 0);
224 
226  bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
227  RenderWindowList& createdWindows);
228 
230  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
231 
233  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
234  GLenum *stencilFormat );
235 
237  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
238 
242  void destroyRenderWindow(RenderWindow* pWin);
246  String getErrorDescription(long errorNumber) const;
250  VertexElementType getColourVertexElementType(void) const;
254  void setNormaliseNormals(bool normalise) { }; // Not supported
255 
256  // -----------------------------
257  // Low-level overridden members
258  // -----------------------------
262  void _useLights(const LightList& lights, unsigned short limit) { }; // Not supported
266  bool areFixedFunctionLightsInViewSpace() const { return true; }
270  void _setWorldMatrix(const Matrix4 &m);
274  void _setViewMatrix(const Matrix4 &m);
278  void _setProjectionMatrix(const Matrix4 &m);
282  void _setSurfaceParams(const ColourValue &ambient,
283  const ColourValue &diffuse, const ColourValue &specular,
284  const ColourValue &emissive, Real shininess,
285  TrackVertexColourType tracking) {}
289  void _setPointParameters(Real size, bool attenuationEnabled,
290  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
294  void _setPointSpritesEnabled(bool enabled);
298  void _setVertexTexture(size_t unit, const TexturePtr &tex);
302  void _setGeometryTexture(size_t unit, const TexturePtr &tex);
306  void _setComputeTexture(size_t unit, const TexturePtr &tex);
310  void _setTessellationHullTexture(size_t unit, const TexturePtr &tex);
314  void _setTessellationDomainTexture(size_t unit, const TexturePtr &tex);
318  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
322  void _setTextureCoordSet(size_t stage, size_t index);
327  const Frustum* frustum = 0) { }; // Not supported
331  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { }; // Not supported
335  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
339  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
343  void _setTextureMipmapBias(size_t unit, float bias);
347  void _setTextureMatrix(size_t stage, const Matrix4& xform) { }; // Not supported
351  void _setViewport(Viewport *vp);
355  void _beginFrame(void);
359  void _endFrame(void);
363  void _setCullingMode(CullingMode mode);
367  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
371  void _setDepthBufferCheckEnabled(bool enabled = true);
375  void _setDepthBufferWriteEnabled(bool enabled = true);
379  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
383  void _setDepthBias(float constantBias, float slopeScaleBias);
387  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
391  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
395  void _convertProjectionMatrix(const Matrix4& matrix,
396  Matrix4& dest, bool forGpuProgram = false);
400  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
401  Matrix4& dest, bool forGpuProgram = false);
405  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
406  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
410  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
411  Matrix4& dest, bool forGpuProgram = false);
415  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
416  bool forGpuProgram);
420  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
424  void enableClipPlane (ushort index, bool enable);
428  void _setPolygonMode(PolygonMode level);
432  void setStencilCheckEnabled(bool enabled);
436  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
437  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
438  StencilOperation stencilFailOp = SOP_KEEP,
439  StencilOperation depthFailOp = SOP_KEEP,
440  StencilOperation passOp = SOP_KEEP,
441  bool twoSidedOperation = false,
442  bool readBackAsTexture = false);
446  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
450  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
454  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
458  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
474  void _render(const RenderOperation& op);
478  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
479 
480  void clearFrameBuffer(unsigned int buffers,
481  const ColourValue& colour = ColourValue::Black,
482  Real depth = 1.0f, unsigned short stencil = 0);
483  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
484  Real getHorizontalTexelOffset(void) { return 0.0; } // No offset in GL
485  Real getVerticalTexelOffset(void) { return 0.0; } // No offset in GL
486  Real getMinimumDepthInputValue(void) { return -1.0f; } // Range [-1.0f, 1.0f]
487  Real getMaximumDepthInputValue(void) { return 1.0f; } // Range [-1.0f, 1.0f]
488  OGRE_MUTEX(mThreadInitMutex);
489  void registerThread();
490  void unregisterThread();
491  void preExtraThreadsStarted();
492  void postExtraThreadsStarted();
493  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
494 
495  // ----------------------------------
496  // GL3PlusRenderSystem specific members
497  // ----------------------------------
499  GL3PlusContext* _getMainContext() { return mMainContext; }
507  void _unregisterContext(GL3PlusContext *context);
510  void _switchContext(GL3PlusContext *context);
514  void _oneTimeContextInitialization();
515  void initialiseContext(RenderWindow* primary);
519  void _setRenderTarget(RenderTarget *target);
520 
521  GLint convertCompareFunction(CompareFunction func) const;
522  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
523 
524  void bindGpuProgram(GpuProgram* prg);
525  void unbindGpuProgram(GpuProgramType gptype);
526  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
527  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
528 
530  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
532  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
534  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
536  unsigned int getDisplayMonitorCount() const;
537 
538  GLenum _getPolygonMode(void) { return mPolygonMode; }
539 
540  void _setSceneBlendingOperation(SceneBlendOperation op);
541  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
543  virtual bool hasAnisotropicMipMapFilter() const { return false; }
544 
546  virtual void beginProfileEvent( const String &eventName );
547 
549  virtual void endProfileEvent( void );
550 
552  virtual void markProfileEvent( const String &eventName );
553  };
554 }
555 
556 #endif
Leave the stencil buffer unchanged.
Definition: OgreCommon.h:90
Manages the target rendering window.
Matrix4 mViewMatrix
View matrix to set world against.
Real getMaximumDepthInputValue(void)
Gets the maximum (farthest) depth value to be used when rendering using identity transforms.
A 'canvas' which can receive the results of a rendering operation.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
Singleton wrapper for hardware buffer manager.
virtual bool hasAnisotropicMipMapFilter() const
Determines if the system has anisotropic mip map filter support.
void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, const Frustum *frustum=0)
See RenderSystem.
void setVertexDeclaration(VertexDeclaration *decl)
See RenderSystem.
size_t mTextureMipmapCount
Used to store the number of mipmaps in the currently bound texture.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:580
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:152
#define OGRE_MUTEX(name)
bool mDepthWrite
Store last depth write state.
vector< GLuint >::type mRenderAttribsBound
Class representing colour.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
GLenum mActiveTextureUnit
These variables are used for caching RenderSystem state.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
void _setTextureBlendMode(size_t stage, const LayerBlendModeEx &bm)
See RenderSystem.
Defines a program which runs on the GPU such as a vertex or fragment program.
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
Shared pointer implementation used to share vertex buffers.
list< GL3PlusContext * >::type GL3PlusContextList
FilterType
Definition: OgreCommon.h:121
vector< GLuint >::type mRenderInstanceAttribsBound
HardwareBufferManager * mHardwareBufferManager
void setNormaliseNormals(bool normalise)
See RenderSystem.
SceneBlendFactor
Blending factors for manually blending objects with the scene.
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:166
This class represents a render target that renders to multiple RenderTextures at once.
This is a abstract class that that provides the interface for the query class for hardware occlusion...
This class declares the usage of a single vertex buffer as a component of a complete VertexDeclaratio...
vector< RenderWindow * >::type RenderWindowList
Render window container.
Definition: OgreCommon.h:794
void _setSurfaceParams(const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking)
See RenderSystem.
vector< Plane >::type PlaneList
Definition: OgrePlane.h:160
#define OGRE_MAX_TEXTURE_LAYERS
Define max number of texture layers allowed per pass on any card.
Definition: OgreConfig.h:72
An abstract class that contains a depth/stencil buffer.
void setVertexDeclaration(VertexDeclaration *decl, VertexBufferBinding *binding)
See RenderSystem.
HashMap< GLenum, GLuint > BindBufferMap
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:144
void setVertexBufferBinding(VertexBufferBinding *binding)
See RenderSystem.
Real getVerticalTexelOffset(void)
Returns the vertical texel offset value required for mapping texel origins to pixel origins in this r...
Texture addressing mode for each texture coordinate.
GLenum mPolygonMode
Cache the polygon mode value.
GLSLShaderFactory * mGLSLShaderFactory
map< String, ConfigOption >::type ConfigOptionMap
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
GL3PlusSupport * mGLSupport
GL support class, used for creating windows etc.
Class that encapsulates an GL context.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
Real getMinimumDepthInputValue(void)
Gets the minimum (closest) depth value to be used when rendering using identity transforms.
Manager/factory for RenderTextures.
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
Definition: OgreCommon.h:87
unsigned short ushort
void setAmbientLight(float r, float g, float b)
See RenderSystem.
#define _OgreGL3PlusExport
GL3PlusContext * _getMainContext()
Returns the main context.
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
'New' rendering operation using vertex buffers.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
GL3PlusContextList mBackgroundContextList
List of background thread contexts.
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:210
void _setTextureMatrix(size_t stage, const Matrix4 &xform)
See RenderSystem.
bool mStopRendering
Rendering loop control.
static const ColourValue Black
SceneBlendOperation
Blending operations controls how objects are blended into the scene.
Real getHorizontalTexelOffset(void)
Returns the horizontal texel offset value required for mapping texel origins to pixel origins in this...
Factory class for GLSL shaders.
singleton class for storing the capabilities of the graphics card.
_StringBase String
Definition: OgreCommon.h:53
void _useLights(const LightList &lights, unsigned short limit)
See RenderSystem.
vector< RenderWindowDescription >::type RenderWindowDescriptionList
Render window creation parameters container.
Definition: OgreCommon.h:791
void setLightingEnabled(bool enabled)
See RenderSystem.
unsigned short uint16
Definition: OgrePlatform.h:421
bool mGLInitialised
Check if the GL system has already been initialised.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:131
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:74
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:221
Implementation of GL 3 as a rendering system.
Class which manages blending of both colour and alpha components.
void setShadingType(ShadeOptions so)
See RenderSystem.
uint32 mStencilWriteMask
Store last stencil mask state.
Specialisation of HighLevelGpuProgram to encapsulate shader objects obtained from compiled shaders wr...
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
GL3PlusRTTManager * mRTTManager
Manager object for creating render textures.