OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLES2RenderSystem.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 __GLES2RenderSystem_H__
30 #define __GLES2RenderSystem_H__
31 
32 #include "OgreGLES2Prerequisites.h"
33 
34 #include "OgreMaterialManager.h"
35 #include "OgreRenderSystem.h"
36 #include "OgreGLES2GpuProgram.h"
37 
38 namespace Ogre {
39  class GLES2Context;
40  class GLES2Support;
41  class GLES2RTTManager;
42  class GLES2GpuProgramManager;
43  class GLSLESProgramFactory;
44  class GLES2StateCacheManager;
45 #if !OGRE_NO_GLES2_CG_SUPPORT
46  class GLSLESCgProgramFactory;
47 #endif
48  class GLSLESGpuProgram;
49  class HardwareBufferManager;
50 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
51  class AndroidResourceManager;
52 #endif
53 
58  {
59  private:
64 
68 
70  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
71 
73  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
74 
77 
78  GLfloat mAutoTextureMatrix[16];
79 
81 
84 
87 
88  /* The main GL context - main thread only */
90 
91  /* The current GL context - main thread only */
93 
97 
100 #if !OGRE_NO_GLES2_CG_SUPPORT
102 #endif
104 
111 
114 
115  // local data member of _render that were moved here to improve performance
116  // (save allocations)
119 
120  GLint getCombinedMinMipFilter(void) const;
121 
124 
125  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
126  GLenum getBlendMode(SceneBlendFactor ogreBlend) const;
127  void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer,
128  const size_t vertexStart,
129  vector<GLuint>::type &attribsBound,
130  vector<GLuint>::type &instanceAttribsBound,
131  bool updateVAO);
132 
133  // Mipmap count of the actual bounded texture
135  GLint mViewport[4];
136  GLint mScissor[4];
137 
138  public:
139  // Default constructor / destructor
141  virtual ~GLES2RenderSystem();
142 
143  friend class ShaderGeneratorTechniqueResolverListener;
144 
145  // ----------------------------------
146  // Overridden RenderSystem functions
147  // ----------------------------------
151  const String& getName(void) const;
155  ConfigOptionMap& getConfigOptions(void);
159  void setConfigOption(const String &name, const String &value);
163  String validateConfigOptions(void);
167  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
171  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
175  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
179  void reinitialise(void); // Used if settings changed mid-rendering
183  void shutdown(void);
187  void setAmbientLight(float r, float g, float b) { }; // Not supported
191  void setShadingType(ShadeOptions so) { }; // Not supported
195  void setLightingEnabled(bool enabled) { }; // Not supported
196 
198  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
199  bool fullScreen, const NameValuePairList *miscParams = 0);
200 
202  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
203 
205  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
206  GLenum *stencilFormat );
207 
209  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
210 
214  void destroyRenderWindow(RenderWindow* pWin);
218  String getErrorDescription(long errorNumber) const;
222  VertexElementType getColourVertexElementType(void) const;
226  void setNormaliseNormals(bool normalise) { }; // Not supported
227 
228  // -----------------------------
229  // Low-level overridden members
230  // -----------------------------
234  void _useLights(const LightList& lights, unsigned short limit) { }; // Not supported
238  bool areFixedFunctionLightsInViewSpace() const { return true; }
242  void _setWorldMatrix(const Matrix4 &m);
246  void _setViewMatrix(const Matrix4 &m);
250  void _setProjectionMatrix(const Matrix4 &m);
254  void _setSurfaceParams(const ColourValue &ambient,
255  const ColourValue &diffuse, const ColourValue &specular,
256  const ColourValue &emissive, Real shininess,
257  TrackVertexColourType tracking) {}
261  void _setPointParameters(Real size, bool attenuationEnabled,
262  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) {}
266  void _setPointSpritesEnabled(bool enabled) {}
270  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
274  void _setTextureCoordSet(size_t stage, size_t index);
279  const Frustum* frustum = 0) { }; // Not supported
283  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { }; // Not supported
287  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
291  void _setTextureBorderColour(size_t stage, const ColourValue& colour) { }; // Not supported
295  void _setTextureMipmapBias(size_t unit, float bias) { }; // Not supported
299  void _setTextureMatrix(size_t stage, const Matrix4& xform) { }; // Not supported
303  void _setViewport(Viewport *vp);
307  void _beginFrame(void);
311  void _endFrame(void);
315  void _setCullingMode(CullingMode mode);
319  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
323  void _setDepthBufferCheckEnabled(bool enabled = true);
327  void _setDepthBufferWriteEnabled(bool enabled = true);
331  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
335  void _setDepthBias(float constantBias, float slopeScaleBias);
339  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
343  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
347  void _convertProjectionMatrix(const Matrix4& matrix,
348  Matrix4& dest, bool forGpuProgram = false);
352  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
353  Matrix4& dest, bool forGpuProgram = false);
357  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
358  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
362  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
363  Matrix4& dest, bool forGpuProgram = false);
367  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
368  bool forGpuProgram);
372  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
376  void enableClipPlane (ushort index, bool enable);
380  void _setPolygonMode(PolygonMode level);
384  void setStencilCheckEnabled(bool enabled);
388  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
389  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
390  StencilOperation stencilFailOp = SOP_KEEP,
391  StencilOperation depthFailOp = SOP_KEEP,
392  StencilOperation passOp = SOP_KEEP,
393  bool twoSidedOperation = false);
397  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
401  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
405  virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
406  FilterOptions magFilter, FilterOptions mipFilter);
410  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
414  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
418  virtual bool hasAnisotropicMipMapFilter() const { return false; }
422  void setVertexDeclaration(VertexDeclaration* decl);
426  void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding);
434  void _render(const RenderOperation& op);
438  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
439 
440  void clearFrameBuffer(unsigned int buffers,
441  const ColourValue& colour = ColourValue::Black,
442  Real depth = 1.0f, unsigned short stencil = 0);
443  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
444  Real getHorizontalTexelOffset(void) { return 0.0; } // No offset in GL
445  Real getVerticalTexelOffset(void) { return 0.0; } // No offset in GL
446  Real getMinimumDepthInputValue(void) { return -1.0f; } // Range [-1.0f, 1.0f]
447  Real getMaximumDepthInputValue(void) { return 1.0f; } // Range [-1.0f, 1.0f]
448  OGRE_MUTEX(mThreadInitMutex);
449  void registerThread();
450  void unregisterThread();
451  void preExtraThreadsStarted();
452  void postExtraThreadsStarted();
453  void setClipPlanesImpl(const Ogre::PlaneList& planeList) {}
454  GLES2Support* getGLSupportRef() { return mGLSupport; }
455 
456  // ----------------------------------
457  // GLES2RenderSystem specific members
458  // ----------------------------------
460  GLES2Context* _getMainContext() { return mMainContext; }
468  void _unregisterContext(GLES2Context *context);
471  void _switchContext(GLES2Context *context);
475  void _oneTimeContextInitialization();
476  void initialiseContext(RenderWindow* primary);
480  void _setRenderTarget(RenderTarget *target);
481 
482  GLES2Support* getGLES2Support() { return mGLSupport; }
483  GLint convertCompareFunction(CompareFunction func) const;
484  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
485 
486  void bindGpuProgram(GpuProgram* prg);
487  void unbindGpuProgram(GpuProgramType gptype);
488  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
489  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
490 
492  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
494  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
496  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
498  unsigned int getDisplayMonitorCount() const;
499 
501  GLfloat _getCurrentAnisotropy(size_t unit);
502 
503  void _setSceneBlendingOperation(SceneBlendOperation op);
504  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
505 
506  unsigned int getDiscardBuffers(void);
507 
508  void _destroyDepthBuffer(RenderWindow* pRenderWnd);
509 
511  virtual void beginProfileEvent( const String &eventName );
512 
514  virtual void endProfileEvent( void );
515 
517  virtual void markProfileEvent( const String &eventName );
518 
519 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
520  void resetRenderer(RenderWindow* pRenderWnd);
521 
522  static AndroidResourceManager* getResourceManager();
523  private:
525 #endif
526  };
527 }
528 
529 #endif
Manages the target rendering window.
A 'canvas' which can receive the results of a rendering operation.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
void _setTextureBorderColour(size_t stage, const ColourValue &colour)
See RenderSystem.
float Real
Software floating point type.
void setNormaliseNormals(bool normalise)
See RenderSystem.
unsigned int uint32
Definition: OgrePlatform.h:344
vector< GLuint >::type mRenderInstanceAttribsBound
Singleton wrapper for hardware buffer manager.
vector< GLuint >::type mRenderAttribsBound
GLES2GpuProgram * mCurrentFragmentProgram
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
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
Leave the stencil buffer unchanged.
#define OGRE_MUTEX(name)
void setVertexBufferBinding(VertexBufferBinding *binding)
See RenderSystem.
#define _OgreGLES2Export
Class representing colour.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
GLSLESProgramFactory * mGLSLESProgramFactory
GLES2Support * mGLSupport
GL support class, used for creating windows etc.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:85
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
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.
FilterType
Definition: OgreCommon.h:90
void _setTextureBlendMode(size_t stage, const LayerBlendModeEx &bm)
See RenderSystem.
void _setPointParameters(Real size, bool attenuationEnabled, Real constant, Real linear, Real quadratic, Real minSize, Real maxSize)
See RenderSystem.
SceneBlendFactor
Blending factors for manually blending objects with the scene.
An in memory cache of the OpenGL ES state.
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...
Class that encapsulates an GL context.
Implementation of GL ES 2.x as a rendering system.
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
GLSLESCgProgramFactory * mGLSLESCgProgramFactory
An abstract class that contains a depth/stencil buffer.
GLES2RTTManager * mRTTManager
Manager object for creating render textures.
HardwareBufferManager * mHardwareBufferManager
Factory class for GLSL ES programs.
Real getMinimumDepthInputValue(void)
Gets the minimum (closest) depth value to be used when rendering using identity transforms.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
GLES2GpuProgramManager * mGpuProgramManager
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:113
Real getHorizontalTexelOffset(void)
Returns the horizontal texel offset value required for mapping texel origins to pixel origins in this...
GLES2Context * _getMainContext()
Returns the main context.
Texture addressing mode for each texture coordinate.
map< String, ConfigOption >::type ConfigOptionMap
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
Real getVerticalTexelOffset(void)
Returns the vertical texel offset value required for mapping texel origins to pixel origins in this r...
GLES2GpuProgram * mCurrentVertexProgram
list< GLES2Context * >::type GLES2ContextList
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
void _useLights(const LightList &lights, unsigned short limit)
See RenderSystem.
unsigned short ushort
void _setPointSpritesEnabled(bool enabled)
See RenderSystem.
bool mGLInitialised
Check if the GL system has already been initialised.
void _setTextureMatrix(size_t stage, const Matrix4 &xform)
See RenderSystem.
void setLightingEnabled(bool enabled)
See RenderSystem.
Matrix4 mViewMatrix
View matrix to set world against.
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:57
'New' rendering operation using vertex buffers.
GLES2ContextList mBackgroundContextList
List of background thread contexts.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
void _setTextureMipmapBias(size_t unit, float bias)
See RenderSystem.
virtual bool hasAnisotropicMipMapFilter() const
See RenderSystem.
GLES2StateCacheManager * mStateCacheManager
State cache manager which responsible to reduce redundant state changes.
void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, const Frustum *frustum=0)
See RenderSystem.
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:47
static AndroidResourceManager * mResourceManager
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:179
void setClipPlanesImpl(const Ogre::PlaneList &planeList)
Internal method used to set the underlying clip planes when needed.
static const ColourValue Black
SceneBlendOperation
Blending operations controls how objects are blended into the scene.
singleton class for storing the capabilities of the graphics card.
_StringBase String
void _setSurfaceParams(const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking)
See RenderSystem.
unsigned short uint16
Definition: OgrePlatform.h:345
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:100
void setShadingType(ShadeOptions so)
See RenderSystem.
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:64
Factory class for GLSL ES programs.
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:276
Class which manages blending of both colour and alpha components.
Real getMaximumDepthInputValue(void)
Gets the maximum (farthest) depth value to be used when rendering using identity transforms.
void setAmbientLight(float r, float g, float b)
See RenderSystem.
Manager/factory for RenderTextures.