OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLESRenderSystem.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) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com>
8 Copyright (c) 2000-2014 Torus Knot Software Ltd
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 -----------------------------------------------------------------------------
28 */
29 
30 #ifndef __GLESRenderSystem_H__
31 #define __GLESRenderSystem_H__
32 
33 #include "OgreGLESPrerequisites.h"
34 #include "OgreRenderSystem.h"
35 
36 namespace Ogre {
37  class GLESContext;
38  class GLESSupport;
39  class GLESRTTManager;
40  class GLESGpuProgramManager;
41  class HardwareBufferManager;
42  class GLESStateCacheManager;
43 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
44  class AndroidResourceManager;
45 #endif
46 
50  {
51  private:
52  typedef HashMap<GLenum, GLint> TexEnviMap;
53  typedef HashMap<GLenum, GLfloat> TexEnvfMap;
54  typedef HashMap<GLenum, const GLfloat *> TexEnvfvMap;
55  typedef HashMap<GLenum, GLfloat> PointParamfMap;
56  typedef HashMap<GLenum, const GLfloat *> PointParamfvMap;
57  typedef HashMap<GLenum, const GLfloat *> MaterialfvMap;
58  typedef HashMap<GLenum, GLfloat> LightfMap;
59  typedef HashMap<GLenum, const GLfloat *> LightfvMap;
60 
64  #define MAX_LIGHTS 8
65  Light const * mLights[MAX_LIGHTS];
66  unsigned short mCurrentLights;
67 
72 
76 
78  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
79 
82 
83  GLfloat mAutoTextureMatrix[16];
84 
86  size_t mTextureCount;
88 
91 
94 
95  /* The main GL context - main thread only */
97 
98  /* The current GL context - main thread only */
102 
109 
111  unsigned int mDiscardBuffers;
112 
115 
116  GLuint getCombinedMinMipFilter(void) const;
117 
118  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
119  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
120  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
121  void setGLLight(size_t index, const Light* lt);
122 
124  void setGLLightPositionDirection(const Light* lt, GLenum lightindex);
125  void setLights();
126 
127  bool activateGLTextureUnit(size_t unit);
128  bool activateGLClientTextureUnit(size_t unit);
129 
130  // Mipmap count of the actual bounded texture
132  public:
133  // Default constructor / destructor
135  virtual ~GLESRenderSystem();
136 
137  // ----------------------------------
138  // Overridden RenderSystem functions
139  // ----------------------------------
143  const String& getName(void) const;
147  ConfigOptionMap& getConfigOptions(void);
151  void setConfigOption(const String &name, const String &value);
155  String validateConfigOptions(void);
159  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
163  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
167  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
171  void reinitialise(void); // Used if settings changed mid-rendering
175  void shutdown(void);
179  void setAmbientLight(float r, float g, float b);
183  void setShadingType(ShadeOptions so);
187  void setLightingEnabled(bool enabled);
188 
190  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
191  bool fullScreen, const NameValuePairList *miscParams = 0);
192 
194  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
195 
197  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
198  GLenum *stencilFormat );
199 
201  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
202 
206  void destroyRenderWindow(RenderWindow* pWin);
210  String getErrorDescription(long errorNumber) const;
214  VertexElementType getColourVertexElementType(void) const;
218  void setNormaliseNormals(bool normalise);
219 
220  // -----------------------------
221  // Low-level overridden members
222  // -----------------------------
226  void _useLights(const LightList& lights, unsigned short limit);
230  bool areFixedFunctionLightsInViewSpace() const { return true; }
234  void _setWorldMatrix(const Matrix4 &m);
238  void _setViewMatrix(const Matrix4 &m);
242  void _setProjectionMatrix(const Matrix4 &m);
246  void _setSurfaceParams(const ColourValue &ambient,
247  const ColourValue &diffuse, const ColourValue &specular,
248  const ColourValue &emissive, Real shininess,
249  TrackVertexColourType tracking);
253  void _setPointParameters(Real size, bool attenuationEnabled,
254  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
258  void _setPointSpritesEnabled(bool enabled);
262  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
266  void _setTextureCoordSet(size_t stage, size_t index);
270  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
271  const Frustum* frustum = 0);
275  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
279  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
283  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
287  void _setTextureMipmapBias(size_t unit, float bias);
291  void _setTextureMatrix(size_t stage, const Matrix4& xform);
295  void _setViewport(Viewport *vp);
299  void _beginFrame(void);
303  void _endFrame(void);
307  void _setCullingMode(CullingMode mode);
311  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
315  void _setDepthBufferCheckEnabled(bool enabled = true);
319  void _setDepthBufferWriteEnabled(bool enabled = true);
323  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
327  void _setDepthBias(float constantBias, float slopeScaleBias);
331  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
335  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
339  void _convertProjectionMatrix(const Matrix4& matrix,
340  Matrix4& dest, bool forGpuProgram = false);
344  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
345  Matrix4& dest, bool forGpuProgram = false);
349  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
350  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
354  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
355  Matrix4& dest, bool forGpuProgram = false);
359  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
360  bool forGpuProgram);
364  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
368  void enableClipPlane (ushort index, bool enable);
372  void _setPolygonMode(PolygonMode level);
376  void setStencilCheckEnabled(bool enabled);
380  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
381  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
382  StencilOperation stencilFailOp = SOP_KEEP,
383  StencilOperation depthFailOp = SOP_KEEP,
384  StencilOperation passOp = SOP_KEEP,
385  bool twoSidedOperation = false,
386  bool readBackAsTexture = false);
390  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
394  virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
395  FilterOptions magFilter, FilterOptions mipFilter);
399  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
403  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
407  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
411  virtual bool hasAnisotropicMipMapFilter() const { return false; }
415  void setVertexDeclaration(VertexDeclaration* decl);
419  void setVertexBufferBinding(VertexBufferBinding* binding);
423  void _render(const RenderOperation& op);
427  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
428 
429  void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
430  unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
431 
432  void clearFrameBuffer(unsigned int buffers,
433  const ColourValue& colour = ColourValue::Black,
434  Real depth = 1.0f, unsigned short stencil = 0);
435  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
436  Real getHorizontalTexelOffset(void);
437  Real getVerticalTexelOffset(void);
438  Real getMinimumDepthInputValue(void);
439  Real getMaximumDepthInputValue(void);
440  void registerThread();
441  void unregisterThread();
442  void preExtraThreadsStarted();
443  void postExtraThreadsStarted();
444  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
445 
446  // ----------------------------------
447  // GLESRenderSystem specific members
448  // ----------------------------------
450  GLESContext* _getMainContext() { return mMainContext; }
458  void _unregisterContext(GLESContext *context);
461  void _switchContext(GLESContext *context);
465  void _oneTimeContextInitialization();
466  void initialiseContext(RenderWindow* primary);
470  void _setRenderTarget(RenderTarget *target);
471 
472  GLint convertCompareFunction(CompareFunction func) const;
473  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
474 
475  void bindGpuProgram(GpuProgram* prg);
476  void unbindGpuProgram(GpuProgramType gptype);
477  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
478  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
479 
481  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
483  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
485  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
487  unsigned int getDisplayMonitorCount() const;
488 
490  GLfloat _getCurrentAnisotropy(size_t unit);
491 
492  void _setSceneBlendingOperation(SceneBlendOperation op);
493  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
494 
495  void _destroyDepthBuffer(RenderWindow* pRenderWnd);
496 
498  virtual void beginProfileEvent( const String &eventName ) {}
499 
501  virtual void endProfileEvent( void ) {}
502 
504  virtual void markProfileEvent( const String &eventName ) {}
505 
506 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
507  void resetRenderer(RenderWindow* pRenderWnd);
508 
509  static AndroidResourceManager* getResourceManager();
510  private:
512 #endif
513  };
514 }
515 
516 #endif
Leave the stencil buffer unchanged.
Definition: OgreCommon.h:90
virtual void markProfileEvent(const String &eventName)
Marks an instantaneous event for graphics profilers.
Manages the target rendering window.
A 'canvas' which can receive the results of a rendering operation.
virtual void beginProfileEvent(const String &eventName)
This marks the beginning of an event for GPU profiling.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
HashMap< GLenum, const GLfloat * > MaterialfvMap
float Real
Software floating point type.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
HashMap< GLenum, GLint > TexEnviMap
unsigned int uint32
Definition: OgrePlatform.h:420
An in memory cache of the OpenGL ES state.
Singleton wrapper for hardware buffer manager.
GLESRTTManager * mRTTManager
Manager object for creating render textures.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
unsigned int getDiscardBuffers(void)
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
GLESContext * _getMainContext()
Returns the main context.
HashMap< GLenum, const GLfloat * > PointParamfvMap
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
Class representing colour.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Defines a program which runs on the GPU such as a vertex or fragment program.
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
bool mGLInitialised
Check if the GL system has already been initialised.
FilterType
Definition: OgreCommon.h:121
GLESGpuProgramManager * mGpuProgramManager
#define _OgreGLESExport
SceneBlendFactor
Blending factors for manually blending objects with the scene.
HashMap< GLenum, GLfloat > PointParamfMap
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...
Matrix4 mViewMatrix
View matrix to set world against.
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:70
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
Manager/factory for RenderTextures.
An abstract class that contains a depth/stencil buffer.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:144
Class that encapsulates an GL context.
void _setDiscardBuffers(unsigned int flags)
Texture addressing mode for each texture coordinate.
map< String, ConfigOption >::type ConfigOptionMap
GLESStateCacheManager * mStateCacheManager
State cache manager which responsible to reduce redundant state changes.
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
unsigned int mDiscardBuffers
Mask of buffers who contents can be discarded if GL_EXT_discard_framebuffer is supported.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
HashMap< GLenum, const GLfloat * > LightfvMap
GLESSupport * mGLSupport
GL support class, used for creating windows etc.
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
Definition: OgreCommon.h:87
unsigned short ushort
virtual bool hasAnisotropicMipMapFilter() const
See RenderSystem.
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...
Implementation of GL as a rendering system.
#define MAX_LIGHTS
Array of up to 8 lights, indexed as per API Note that a null value indicates a free slot...
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:210
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.
static AndroidResourceManager * mResourceManager
_StringBase String
Definition: OgreCommon.h:53
virtual void endProfileEvent(void)
Ends the currently active GPU profiling event.
unsigned short uint16
Definition: OgrePlatform.h:421
HardwareBufferManager * mHardwareBufferManager
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
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:221
Class which manages blending of both colour and alpha components.
HashMap< GLenum, GLfloat > TexEnvfMap
HashMap< GLenum, const GLfloat * > TexEnvfvMap
HashMap< GLenum, GLfloat > LightfMap