OGRE  1.9
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 "OgreGL3PlusGpuProgram.h"
37 
38 namespace Ogre {
39  class GL3PlusContext;
40  class GL3PlusSupport;
41  class GL3PlusRTTManager;
42  class GL3PlusGpuProgramManager;
43  class GLSLProgramFactory;
44  class GLSLGpuProgram;
45  class GLSLLinkProgram;
46  class HardwareBufferManager;
47 
52  {
53  private:
56 
57  typedef HashMap<GLenum, GLuint> BindBufferMap;
58 
63 
67 
69 
74 
76  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
77 
79  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
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 _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
302  void _setTextureCoordSet(size_t stage, size_t index);
307  const Frustum* frustum = 0) { }; // Not supported
311  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { }; // Not supported
315  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
319  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
323  void _setTextureMipmapBias(size_t unit, float bias);
327  void _setTextureMatrix(size_t stage, const Matrix4& xform) { }; // Not supported
331  void _setViewport(Viewport *vp);
335  void _beginFrame(void);
339  void _endFrame(void);
343  void _setCullingMode(CullingMode mode);
347  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
351  void _setDepthBufferCheckEnabled(bool enabled = true);
355  void _setDepthBufferWriteEnabled(bool enabled = true);
359  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
363  void _setDepthBias(float constantBias, float slopeScaleBias);
367  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
371  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
375  void _convertProjectionMatrix(const Matrix4& matrix,
376  Matrix4& dest, bool forGpuProgram = false);
380  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
381  Matrix4& dest, bool forGpuProgram = false);
385  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
386  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
390  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
391  Matrix4& dest, bool forGpuProgram = false);
395  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
396  bool forGpuProgram);
400  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
404  void enableClipPlane (ushort index, bool enable);
408  void _setPolygonMode(PolygonMode level);
412  void setStencilCheckEnabled(bool enabled);
416  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
417  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
418  StencilOperation stencilFailOp = SOP_KEEP,
419  StencilOperation depthFailOp = SOP_KEEP,
420  StencilOperation passOp = SOP_KEEP,
421  bool twoSidedOperation = false);
425  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
429  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
433  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
437  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
453  void _render(const RenderOperation& op);
457  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
458 
459  void clearFrameBuffer(unsigned int buffers,
460  const ColourValue& colour = ColourValue::Black,
461  Real depth = 1.0f, unsigned short stencil = 0);
462  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
463  Real getHorizontalTexelOffset(void) { return 0.0; } // No offset in GL
464  Real getVerticalTexelOffset(void) { return 0.0; } // No offset in GL
465  Real getMinimumDepthInputValue(void) { return -1.0f; } // Range [-1.0f, 1.0f]
466  Real getMaximumDepthInputValue(void) { return 1.0f; } // Range [-1.0f, 1.0f]
467  OGRE_MUTEX(mThreadInitMutex);
468  void registerThread();
469  void unregisterThread();
470  void preExtraThreadsStarted();
471  void postExtraThreadsStarted();
472  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
473 
474  // ----------------------------------
475  // GL3PlusRenderSystem specific members
476  // ----------------------------------
478  GL3PlusContext* _getMainContext() { return mMainContext; }
486  void _unregisterContext(GL3PlusContext *context);
489  void _switchContext(GL3PlusContext *context);
493  void _oneTimeContextInitialization();
494  void initialiseContext(RenderWindow* primary);
498  void _setRenderTarget(RenderTarget *target);
499 
500  GLint convertCompareFunction(CompareFunction func) const;
501  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
502 
503  void bindGpuProgram(GpuProgram* prg);
504  void unbindGpuProgram(GpuProgramType gptype);
505  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
506  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
507 
509  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
511  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
513  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
515  unsigned int getDisplayMonitorCount() const;
516 
518  GLfloat _getCurrentAnisotropy(size_t unit);
519 
520  GLenum _getPolygonMode(void) { return mPolygonMode; }
521 
522  void _setSceneBlendingOperation(SceneBlendOperation op);
523  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
525  virtual bool hasAnisotropicMipMapFilter() const { return false; }
526 
528  virtual void beginProfileEvent( const String &eventName );
529 
531  virtual void endProfileEvent( void );
532 
534  virtual void markProfileEvent( const String &eventName );
535  };
536 }
537 
538 #endif
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.
GL3PlusGpuProgram * mCurrentFragmentProgram
A 'canvas' which can receive the results of a rendering operation.
GLSLProgramFactory * mGLSLProgramFactory
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
GL3PlusGpuProgramManager * mGpuProgramManager
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:344
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:550
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:121
Leave the stencil buffer unchanged.
#define OGRE_MUTEX(name)
GL3PlusGpuProgram * mCurrentComputeProgram
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:85
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.
GL3PlusGpuProgram * mCurrentDomainProgram
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:90
GL3PlusGpuProgram * mCurrentGeometryProgram
vector< GLuint >::type mRenderInstanceAttribsBound
HardwareBufferManager * mHardwareBufferManager
void setNormaliseNormals(bool normalise)
See RenderSystem.
SceneBlendFactor
Blending factors for manually blending objects with the scene.
GL3PlusGpuProgram * mCurrentHullProgram
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:135
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:764
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:113
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.
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.
GL3PlusGpuProgram * mCurrentVertexProgram
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.
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:57
'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:47
GL3PlusContextList mBackgroundContextList
List of background thread contexts.
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:179
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...
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
singleton class for storing the capabilities of the graphics card.
_StringBase String
void _useLights(const LightList &lights, unsigned short limit)
See RenderSystem.
vector< RenderWindowDescription >::type RenderWindowDescriptionList
Render window creation parameters container.
Definition: OgreCommon.h:761
void setLightingEnabled(bool enabled)
See RenderSystem.
unsigned short uint16
Definition: OgrePlatform.h:345
bool mGLInitialised
Check if the GL system has already been initialised.
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:100
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:64
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:276
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.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
GL3PlusRTTManager * mRTTManager
Manager object for creating render textures.