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-2013 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* 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, Light* lt);
122 
124  void setGLLightPositionDirection(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);
389  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
393  virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
394  FilterOptions magFilter, FilterOptions mipFilter);
398  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
402  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
406  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
410  virtual bool hasAnisotropicMipMapFilter() const { return false; }
414  void setVertexDeclaration(VertexDeclaration* decl);
418  void setVertexBufferBinding(VertexBufferBinding* binding);
422  void _render(const RenderOperation& op);
426  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
427 
428  void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
429  unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
430 
431  void clearFrameBuffer(unsigned int buffers,
432  const ColourValue& colour = ColourValue::Black,
433  Real depth = 1.0f, unsigned short stencil = 0);
434  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
435  Real getHorizontalTexelOffset(void);
436  Real getVerticalTexelOffset(void);
437  Real getMinimumDepthInputValue(void);
438  Real getMaximumDepthInputValue(void);
439  void registerThread();
440  void unregisterThread();
441  void preExtraThreadsStarted();
442  void postExtraThreadsStarted();
443  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
444 
445  // ----------------------------------
446  // GLESRenderSystem specific members
447  // ----------------------------------
449  GLESContext* _getMainContext() { return mMainContext; }
457  void _unregisterContext(GLESContext *context);
460  void _switchContext(GLESContext *context);
464  void _oneTimeContextInitialization();
465  void initialiseContext(RenderWindow* primary);
469  void _setRenderTarget(RenderTarget *target);
470 
471  GLint convertCompareFunction(CompareFunction func) const;
472  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
473 
474  void bindGpuProgram(GpuProgram* prg);
475  void unbindGpuProgram(GpuProgramType gptype);
476  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
477  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
478 
480  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
482  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
484  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
486  unsigned int getDisplayMonitorCount() const;
487 
489  GLfloat _getCurrentAnisotropy(size_t unit);
490 
491  void _setSceneBlendingOperation(SceneBlendOperation op);
492  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
493 
494  void _destroyDepthBuffer(RenderWindow* pRenderWnd);
495 
497  virtual void beginProfileEvent( const String &eventName ) {}
498 
500  virtual void endProfileEvent( void ) {}
501 
503  virtual void markProfileEvent( const String &eventName ) {}
504 
505 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
506  void resetRenderer(RenderWindow* pRenderWnd);
507 
508  static AndroidResourceManager* getResourceManager();
509  private:
511 #endif
512  };
513 }
514 
515 #endif
vector< Plane >::type PlaneList
Definition: OgrePlane.h:160
Implementation of GL as a rendering system.
A 'canvas' which can receive the results of a rendering operation.
Class that encapsulates an GL context.
GLESGpuProgramManager * mGpuProgramManager
FogMode
Fog modes.
Definition: OgreCommon.h:121
Matrix4 mViewMatrix
View matrix to set world against.
virtual bool hasAnisotropicMipMapFilter() const
See RenderSystem.
Texture addressing mode for each texture coordinate.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
HashMap< GLenum, const GLfloat * > LightfvMap
Leave the stencil buffer unchanged.
#define _OgreGLESExport
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
An in memory cache of the OpenGL ES state.
Class representing colour.
float Real
Software floating point type.
HashMap< GLenum, const GLfloat * > PointParamfvMap
bool mGLInitialised
Check if the GL system has already been initialised.
static const ColourValue Black
unsigned int getDiscardBuffers(void)
Singleton wrapper for hardware buffer manager.
virtual void beginProfileEvent(const String &eventName)
This marks the beginning of an event for GPU profiling.
GLESStateCacheManager * mStateCacheManager
State cache manager which responsible to reduce redundant state changes.
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:57
unsigned int mDiscardBuffers
Mask of buffers who contents can be discarded if GL_EXT_discard_framebuffer is supported.
GLESSupport * mGLSupport
GL support class, used for creating windows etc.
Defines a plane in 3D space.
Definition: OgrePlane.h:61
static AndroidResourceManager * mResourceManager
virtual void endProfileEvent(void)
Ends the currently active GPU profiling event.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
virtual void markProfileEvent(const String &eventName)
Marks an instantaneous event for graphics profilers.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
#define OGRE_MAX_TEXTURE_LAYERS
Define max number of texture layers allowed per pass on any card.
Definition: OgreConfig.h:72
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:135
HashMap< GLenum, GLfloat > PointParamfMap
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:276
GLESContext * _getMainContext()
Returns the main context.
HardwareBufferManager * mHardwareBufferManager
Class which manages blending of both colour and alpha components.
Defines the functionality of a 3D API.
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
map< String, ConfigOption >::type ConfigOptionMap
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:64
void _setDiscardBuffers(unsigned int flags)
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
HashMap< GLenum, const GLfloat * > MaterialfvMap
_StringBase String
An abstract class that contains a depth/stencil buffer.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
HashMap< GLenum, const GLfloat * > TexEnvfvMap
singleton class for storing the capabilities of the graphics card.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
unsigned int uint32
Definition: OgrePlatform.h:359
Defines a program which runs on the GPU such as a vertex or fragment program.
SceneBlendFactor
Blending factors for manually blending objects with the scene.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:100
Manages the target rendering window.
HashMap< GLenum, GLfloat > LightfMap
This is a abstract class that that provides the interface for the query class for hardware occlusion...
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
HashMap< GLenum, GLint > TexEnviMap
'New' rendering operation using vertex buffers.
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
unsigned short ushort
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:113
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:179
SceneBlendOperation
Blending operations controls how objects are blended into the scene.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:85
This class represents a render target that renders to multiple RenderTextures at once.
#define MAX_LIGHTS
Array of up to 8 lights, indexed as per API Note that a null value indicates a free slot...
unsigned short uint16
Definition: OgrePlatform.h:360
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
GLESRTTManager * mRTTManager
Manager object for creating render textures.
HashMap< GLenum, GLfloat > TexEnvfMap
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:47
Manager/factory for RenderTextures.
FilterType
Definition: OgreCommon.h:90

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Tue Mar 18 2014 19:15:25