OGRE  1.8
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-2013 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 #if !OGRE_NO_GLES2_CG_SUPPORT
45  class GLSLESCgProgramFactory;
46 #endif
47  class GLSLESGpuProgram;
48  class HardwareBufferManager;
49 
54  {
55  private:
56  typedef HashMap<GLenum, GLuint> BindBufferMap;
57 
62 
66 
68  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
69 
71  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
72 
75 
77  bool mColourWrite[4];
78 
81 
84 
85  GLfloat mAutoTextureMatrix[16];
86 
88 
91 
92  /* The main GL context - main thread only */
94 
95  /* The current GL context - main thread only */
99 #if !OGRE_NO_GLES2_CG_SUPPORT
101 #endif
103 
110 
117 
120 
122  unsigned int mDiscardBuffers;
123 
127  GLenum mPolygonMode;
128 
129  // local data member of _render that were moved here to improve performance
130  // (save allocations)
132 
133  GLint getCombinedMinMipFilter(void) const;
134 
137 
138  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
139  GLenum getBlendMode(SceneBlendFactor ogreBlend) const;
140 
141  bool activateGLTextureUnit(size_t unit);
142 
143  public:
144  // Default constructor / destructor
146  virtual ~GLES2RenderSystem();
147 
148  friend class ShaderGeneratorTechniqueResolverListener;
149 
150  // ----------------------------------
151  // Overridden RenderSystem functions
152  // ----------------------------------
156  const String& getName(void) const;
160  ConfigOptionMap& getConfigOptions(void);
164  void setConfigOption(const String &name, const String &value);
168  String validateConfigOptions(void);
172  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
176  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
180  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
184  void reinitialise(void); // Used if settings changed mid-rendering
188  void shutdown(void);
192  void setAmbientLight(float r, float g, float b) { }; // Not supported
196  void setShadingType(ShadeOptions so) { }; // Not supported
200  void setLightingEnabled(bool enabled) { }; // Not supported
201 
203  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
204  bool fullScreen, const NameValuePairList *miscParams = 0);
205 
207  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
208 
210  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
211  GLenum *stencilFormat );
212 
214  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
215 
219  void destroyRenderWindow(RenderWindow* pWin);
223  String getErrorDescription(long errorNumber) const;
227  VertexElementType getColourVertexElementType(void) const;
231  void setNormaliseNormals(bool normalise) { }; // Not supported
232 
233  // -----------------------------
234  // Low-level overridden members
235  // -----------------------------
239  void _useLights(const LightList& lights, unsigned short limit) { }; // Not supported
243  bool areFixedFunctionLightsInViewSpace() const { return true; }
247  void _setWorldMatrix(const Matrix4 &m);
251  void _setViewMatrix(const Matrix4 &m);
255  void _setProjectionMatrix(const Matrix4 &m);
259  void _setSurfaceParams(const ColourValue &ambient,
260  const ColourValue &diffuse, const ColourValue &specular,
261  const ColourValue &emissive, Real shininess,
262  TrackVertexColourType tracking) {}
266  void _setPointParameters(Real size, bool attenuationEnabled,
267  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) {}
271  void _setPointSpritesEnabled(bool enabled) {}
275  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
279  void _setTextureCoordSet(size_t stage, size_t index);
284  const Frustum* frustum = 0) { }; // Not supported
288  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { }; // Not supported
292  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
296  void _setTextureBorderColour(size_t stage, const ColourValue& colour) { }; // Not supported
300  void _setTextureMipmapBias(size_t unit, float bias) { }; // Not supported
304  void _setTextureMatrix(size_t stage, const Matrix4& xform) { }; // Not supported
308  void _setViewport(Viewport *vp);
312  void _beginFrame(void);
316  void _endFrame(void);
320  void _setCullingMode(CullingMode mode);
324  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
328  void _setDepthBufferCheckEnabled(bool enabled = true);
332  void _setDepthBufferWriteEnabled(bool enabled = true);
336  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
340  void _setDepthBias(float constantBias, float slopeScaleBias);
344  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
348  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
352  void _convertProjectionMatrix(const Matrix4& matrix,
353  Matrix4& dest, bool forGpuProgram = false);
357  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
358  Matrix4& dest, bool forGpuProgram = false);
362  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
363  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
367  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
368  Matrix4& dest, bool forGpuProgram = false);
372  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
373  bool forGpuProgram);
377  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
381  void enableClipPlane (ushort index, bool enable);
385  void _setPolygonMode(PolygonMode level);
389  void setStencilCheckEnabled(bool enabled);
393  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
394  uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
395  StencilOperation stencilFailOp = SOP_KEEP,
396  StencilOperation depthFailOp = SOP_KEEP,
397  StencilOperation passOp = SOP_KEEP,
398  bool twoSidedOperation = false);
402  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
406  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
418  void _render(const RenderOperation& op);
422  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
423 
424  void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
425  unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
426 
427  void clearFrameBuffer(unsigned int buffers,
428  const ColourValue& colour = ColourValue::Black,
429  Real depth = 1.0f, unsigned short stencil = 0);
430  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
431  Real getHorizontalTexelOffset(void) { return 0.0; } // No offset in GL
432  Real getVerticalTexelOffset(void) { return 0.0; } // No offset in GL
433  Real getMinimumDepthInputValue(void) { return -1.0f; } // Range [-1.0f, 1.0f]
434  Real getMaximumDepthInputValue(void) { return 1.0f; } // Range [-1.0f, 1.0f]
435  void registerThread() {}
439  void setClipPlanesImpl(const Ogre::PlaneList& planeList) {}
440 
441  // ----------------------------------
442  // GLES2RenderSystem specific members
443  // ----------------------------------
445  GLES2Context* _getMainContext() { return mMainContext; }
453  void _unregisterContext(GLES2Context *context);
456  void _switchContext(GLES2Context *context);
460  void _oneTimeContextInitialization();
461  void initialiseContext(RenderWindow* primary);
465  void _setRenderTarget(RenderTarget *target);
466 
467  GLES2Support* getGLES2Support() { return mGLSupport; }
468  GLint convertCompareFunction(CompareFunction func) const;
469  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
470 
471  void bindGpuProgram(GpuProgram* prg);
472  void unbindGpuProgram(GpuProgramType gptype);
473  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
474  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
475 
477  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
479  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
481  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
483  unsigned int getDisplayMonitorCount() const;
484 
486  GLfloat _getCurrentAnisotropy(size_t unit);
487 
488  GLenum _getPolygonMode(void) { return mPolygonMode; }
489 
490  void _setSceneBlendingOperation(SceneBlendOperation op);
491  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
492 
493  void _bindGLBuffer(GLenum target, GLuint buffer);
494  void _deleteGLBuffer(GLenum target, GLuint buffer);
495 
497  virtual void beginProfileEvent( const String &eventName );
498 
500  virtual void endProfileEvent( void );
501 
503  virtual void markProfileEvent( const String &eventName );
504  };
505 }
506 
507 #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
GLenum mPolygonMode
OpenGL ES doesn't support setting the PolygonMode like desktop GL So we will cache the value and set ...
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:270
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:553
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:124
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
Leave the stencil buffer unchanged.
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.
bool mDepthWrite
Store last depth write state.
Defines a program which runs on the GPU such as a vertex or fragment program.
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
FilterType
Definition: OgreCommon.h:93
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.
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:138
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...
unsigned int getDiscardBuffers(void)
Class that encapsulates an GL context.
Implementation of GL ES 2.x as a rendering system.
vector< Plane >::type PlaneList
Definition: OgrePlane.h:160
HashMap< GLenum, GLuint > BindBufferMap
#define OGRE_MAX_TEXTURE_LAYERS
Define max number of texture layers allowed per pass on any card.
Definition: OgreConfig.h:70
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:116
GLenum mActiveTextureUnit
These variables are used for caching RenderSystem state.
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...
uint32 mStencilMask
Store last stencil mask state.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:443
GLES2GpuProgram * mCurrentVertexProgram
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
void _useLights(const LightList &lights, unsigned short limit)
See RenderSystem.
void registerThread()
Register the an additional thread which may make calls to rendersystem-related objects.
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: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...
void _setTextureMipmapBias(size_t unit, float bias)
See RenderSystem.
void preExtraThreadsStarted()
Tell the rendersystem to perform any prep tasks it needs to directly before other threads which might...
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:46
void setVertexDeclaration(VertexDeclaration *decl)
See RenderSystem.
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:182
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.
unsigned int mDiscardBuffers
Mask of buffers who contents can be discarded if GL_EXT_discard_framebuffer is supported.
singleton class for storing the capabilities of the graphics card.
void unregisterThread()
Unregister an additional thread which may make calls to rendersystem-related objects.
_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:271
StencilOperation
Enum describing the various actions which can be taken onthe stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:103
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:67
Factory class for GLSL ES programs.
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:279
void _setDiscardBuffers(unsigned int flags)
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.