source: OGRE/trunk/ogrenew/RenderSystems/GL/include/OgreGLRenderSystem.h @ 692

Revision 692, 15.1 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __GLRenderSystem_H__
26#define __GLRenderSystem_H__
27
28#include "OgreGLPrerequisites.h"
29#include "OgrePlatform.h"
30#include "OgreRenderSystem.h"
31#include "OgreGLHardwareBufferManager.h"
32#include "OgreGLGpuProgramManager.h"
33#include "OgreVector4.h"
34
35
36namespace Ogre {
37    /**
38      Implementation of GL as a rendering system.
39     */
40    class GLRenderSystem : public RenderSystem
41    {
42    private:
43        // Rendering loop control
44        bool mStopRendering;
45
46        // Array of up to 8 lights, indexed as per API
47        // Note that a null value indicates a free slot
48        #define MAX_LIGHTS 8
49        Light* mLights[MAX_LIGHTS];
50
51        // clip planes
52        typedef std::vector<Vector4> PlaneList2;
53        PlaneList2 mClipPlanes;
54        void setGLClipPlanes() const;
55
56
57        // view matrix to set world against
58        Matrix4 mViewMatrix;
59        Matrix4 mWorldMatrix;
60        Matrix4 mTextureMatrix;
61
62        // Last min & mip filtering options, so we can combine them
63        FilterOptions mMinFilter;
64        FilterOptions mMipFilter;
65
66        // XXX 8 max texture units?
67        size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_COORD_SETS];
68
69        /// holds texture type settings for every stage
70        GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
71
72                /// Number of fixed-function texture units
73                unsigned short mFixedFunctionTextureUnits;
74
75        void initConfigOptions(void);
76        void initInputDevices(void);
77        void processInputDevices(void);
78
79        void setGLLight(size_t index, Light* lt);
80        void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
81 
82        GLint getBlendMode(SceneBlendFactor ogreBlend) const;
83                GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
84
85        void setLights();
86
87        // Store last depth write state
88        bool mDepthWrite;
89                // Store last stencil mask state
90                uint32 mStencilMask;
91                // Store last colour write state
92                bool mColourWrite[4];
93
94        GLint convertCompareFunction(CompareFunction func) const;
95        GLint convertStencilOp(StencilOperation op, bool invert = false) const;
96
97                // internal method for anisotrophy validation
98                GLfloat _getCurrentAnisotropy(size_t unit);
99               
100        /// GL support class, used for creating windows etc
101        GLSupport* mGLSupport;
102       
103        /// Internal method to set pos / direction of a light
104        void setGLLightPositionDirection(Light* lt, GLenum lightindex);
105
106        bool mUseAutoTextureMatrix;
107        GLfloat mAutoTextureMatrix[16];
108
109        // check if the GL system has already been initialized
110        bool mGLInitialized;
111        // Initialise GL system and capabilities
112        void initGL(RenderTarget *primary);
113
114        HardwareBufferManager* mHardwareBufferManager;
115        GLGpuProgramManager* mGpuProgramManager;
116
117        unsigned short mCurrentLights;
118
119        GLuint getCombinedMinMipFilter(void) const;
120
121        GLGpuProgram* mCurrentVertexProgram;
122        GLGpuProgram* mCurrentFragmentProgram;
123
124                /* The main GL context */
125        GLContext *mMainContext;
126        /* The current GL context */
127        GLContext *mCurrentContext;
128
129        /** Manager object for creating render textures.
130            Direct render to texture via GL_EXT_framebuffer_object is preferable
131                        to pbuffers, which depend on the GL support used and are generally
132                        unwieldy and slow. However, FBO support for stencil buffers is poor.
133        */
134        GLRTTManager *mRTTManager;
135    public:
136        // Default constructor / destructor
137        GLRenderSystem();
138        ~GLRenderSystem();
139
140        // ----------------------------------
141        // Overridden RenderSystem functions
142        // ----------------------------------
143        /** See
144          RenderSystem
145         */
146        const String& getName(void) const;
147        /** See
148          RenderSystem
149         */
150        ConfigOptionMap& getConfigOptions(void);
151        /** See
152          RenderSystem
153         */
154        void setConfigOption(const String &name, const String &value);
155        /** See
156          RenderSystem
157         */
158        String validateConfigOptions(void);
159        /** See
160          RenderSystem
161         */
162        RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
163        /** See
164          RenderSystem
165         */
166        void reinitialise(void); // Used if settings changed mid-rendering
167        /** See
168          RenderSystem
169         */
170        void shutdown(void);
171
172        /** See
173          RenderSystem
174         */
175        void setAmbientLight(float r, float g, float b);
176        /** See
177          RenderSystem
178         */
179        void setShadingType(ShadeOptions so);
180        /** See
181          RenderSystem
182         */
183        void setLightingEnabled(bool enabled);
184       
185                /// @copydoc RenderSystem::createRenderWindow
186                RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
187                        bool fullScreen, const NameValuePairList *miscParams = 0);
188
189                /// @copydoc RenderSystem::createMultiRenderTarget
190                virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
191               
192        /** See
193          RenderSystem
194         */
195        void destroyRenderWindow(RenderWindow* pWin);
196        /** See
197          RenderSystem
198         */
199        String getErrorDescription(long errorNumber) const;
200
201        /** See
202          RenderSystem
203         */
204        VertexElementType getColourVertexElementType(void) const;
205        /** See
206          RenderSystem
207         */
208        void setNormaliseNormals(bool normalise);
209
210        // -----------------------------
211        // Low-level overridden members
212        // -----------------------------
213        /** See
214          RenderSystem
215         */
216        void _useLights(const LightList& lights, unsigned short limit);
217        /** See
218          RenderSystem
219         */
220        void _setWorldMatrix(const Matrix4 &m);
221        /** See
222          RenderSystem
223         */
224        void _setViewMatrix(const Matrix4 &m);
225        /** See
226          RenderSystem
227         */
228        void _setProjectionMatrix(const Matrix4 &m);
229        /** See
230          RenderSystem
231         */
232        void _setSurfaceParams(const ColourValue &ambient,
233            const ColourValue &diffuse, const ColourValue &specular,
234            const ColourValue &emissive, Real shininess,
235            TrackVertexColourType tracking);
236        /** See
237          RenderSystem
238         */
239                void _setPointParameters(Real size, bool attenuationEnabled,
240                        Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
241        /** See
242          RenderSystem
243         */
244                void _setPointSpritesEnabled(bool enabled);
245        /** See
246          RenderSystem
247         */
248        void _setTexture(size_t unit, bool enabled, const String &texname);
249        /** See
250          RenderSystem
251         */
252        void _setTextureCoordSet(size_t stage, size_t index);
253        /** See
254          RenderSystem
255         */
256        void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
257            const Frustum* frustum = 0);
258        /** See
259          RenderSystem
260         */
261        void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
262        /** See
263          RenderSystem
264         */
265        void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
266        /** See
267          RenderSystem
268         */
269        void _setTextureBorderColour(size_t stage, const ColourValue& colour);
270        /** See
271          RenderSystem
272         */
273        void _setTextureMatrix(size_t stage, const Matrix4& xform);
274        /** See
275          RenderSystem
276         */
277        void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
278        /** See
279          RenderSystem
280         */
281        void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
282        /** See
283          RenderSystem
284         */
285        void _setViewport(Viewport *vp);
286        /** See
287          RenderSystem
288         */
289        void _beginFrame(void);
290        /** See
291          RenderSystem
292         */
293        void _endFrame(void);
294        /** See
295          RenderSystem
296         */
297        void _setCullingMode(CullingMode mode);
298        /** See
299          RenderSystem
300         */
301        void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
302        /** See
303          RenderSystem
304         */
305        void _setDepthBufferCheckEnabled(bool enabled = true);
306        /** See
307          RenderSystem
308         */
309        void _setDepthBufferWriteEnabled(bool enabled = true);
310        /** See
311          RenderSystem
312         */
313        void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
314        /** See
315          RenderSystem
316         */
317        void _setDepthBias(ushort bias);
318        /** See
319          RenderSystem
320         */
321        void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
322                /** See
323          RenderSystem
324         */
325        void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
326        /** See
327          RenderSystem
328         */
329        void _convertProjectionMatrix(const Matrix4& matrix,
330            Matrix4& dest, bool forGpuProgram = false);
331        /** See
332          RenderSystem
333         */
334        void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
335            Matrix4& dest, bool forGpuProgram = false);
336        /** See
337        RenderSystem
338        */
339        void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
340            Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
341        /** See
342          RenderSystem
343         */
344                void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
345            Matrix4& dest, bool forGpuProgram = false);
346        /** See
347        RenderSystem
348        */
349        void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
350            bool forGpuProgram);
351        /** See
352        RenderSystem
353        */
354        void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
355        /** See
356        RenderSystem
357        */
358        void enableClipPlane (ushort index, bool enable);
359        /** See
360          RenderSystem
361         */
362        void _setPolygonMode(PolygonMode level);
363        /** See
364          RenderSystem
365         */
366        void setStencilCheckEnabled(bool enabled);
367        /** See RenderSystem.
368         */
369        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
370            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
371            StencilOperation stencilFailOp = SOP_KEEP,
372            StencilOperation depthFailOp = SOP_KEEP,
373            StencilOperation passOp = SOP_KEEP,
374            bool twoSidedOperation = false);
375        /** See
376          RenderSystem
377         */
378        void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
379        /** See
380          RenderSystem
381         */
382                void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
383        /** See
384          RenderSystem
385         */
386                void setVertexDeclaration(VertexDeclaration* decl);
387        /** See
388          RenderSystem
389         */
390                void setVertexBufferBinding(VertexBufferBinding* binding);
391        /** See
392          RenderSystem
393         */
394        void _render(const RenderOperation& op);
395        /** See
396          RenderSystem
397         */
398        void bindGpuProgram(GpuProgram* prg);
399        /** See
400          RenderSystem
401         */
402        void unbindGpuProgram(GpuProgramType gptype);
403        /** See
404          RenderSystem
405         */
406        void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
407                /** See
408                RenderSystem
409                */
410                void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
411        /** See
412          RenderSystem
413         */
414        void setClipPlanes(const PlaneList& clipPlanes);
415        /** See
416          RenderSystem
417         */
418        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
419        void clearFrameBuffer(unsigned int buffers,
420            const ColourValue& colour = ColourValue::Black,
421            Real depth = 1.0f, unsigned short stencil = 0);
422        HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
423        Real getHorizontalTexelOffset(void);
424        Real getVerticalTexelOffset(void);
425        Real getMinimumDepthInputValue(void);
426        Real getMaximumDepthInputValue(void);
427
428        // ----------------------------------
429        // GLRenderSystem specific members
430        // ----------------------------------
431        /** One time initialization for the RenderState of a context. Things that
432            only need to be set once, like the LightingModel can be defined here.
433         */
434        void _oneTimeContextInitialization();
435        /** Switch GL context, dealing with involved internal cached states too
436        */
437        void _switchContext(GLContext *context);
438        /**
439         * Set current render target to target, enabling its GL context if needed
440         */
441        void _setRenderTarget(RenderTarget *target);
442        /** Unregister a render target->context mapping. If the context of target
443            is the current context, change the context to the main context so it
444            can be destroyed safely.
445           
446            @note This is automatically called by the destructor of
447            GLContext.
448         */
449        void _unregisterContext(GLContext *context);
450        /** Get the main context. This is generally the context with which
451            a new context wants to share buffers and textures.
452         */
453        GLContext *_getMainContext();
454    };
455}
456#endif
457
Note: See TracBrowser for help on using the repository browser.