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

Revision 657, 14.5 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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
84        void setLights();
85
86        // Store last depth write state
87        bool mDepthWrite;
88                // Store last colour write state
89                bool mColourWrite[4];
90
91        GLint convertCompareFunction(CompareFunction func) const;
92        GLint convertStencilOp(StencilOperation op, bool invert = false) const;
93
94                // internal method for anisotrophy validation
95                GLfloat _getCurrentAnisotropy(size_t unit);
96               
97        /// GL support class, used for creating windows etc
98        GLSupport* mGLSupport;
99       
100        /// Internal method to set pos / direction of a light
101        void setGLLightPositionDirection(Light* lt, GLenum lightindex);
102
103        bool mUseAutoTextureMatrix;
104        GLfloat mAutoTextureMatrix[16];
105
106        // check if the GL system has already been initialized
107        bool mGLInitialized;
108        // Initialise GL context
109        void initGL(void);
110
111        HardwareBufferManager* mHardwareBufferManager;
112        GLGpuProgramManager* mGpuProgramManager;
113
114        unsigned short mCurrentLights;
115
116        GLuint getCombinedMinMipFilter(void) const;
117
118        GLGpuProgram* mCurrentVertexProgram;
119        GLGpuProgram* mCurrentFragmentProgram;
120
121        /* The main GL context */
122        GLContext *mMainContext;
123        /* The current GL context */
124        GLContext *mCurrentContext;
125        /* Type that maps render targets to contexts */
126        typedef std::map<RenderTarget*,GLContext*> ContextMap;
127        /* Map of render target -> context mappings. This is used to find the
128         * GL context for a certain render target */
129        ContextMap mContextMap;
130    public:
131        // Default constructor / destructor
132        GLRenderSystem();
133        ~GLRenderSystem();
134
135        // ----------------------------------
136        // Overridden RenderSystem functions
137        // ----------------------------------
138        /** See
139          RenderSystem
140         */
141        const String& getName(void) const;
142        /** See
143          RenderSystem
144         */
145        ConfigOptionMap& getConfigOptions(void);
146        /** See
147          RenderSystem
148         */
149        void setConfigOption(const String &name, const String &value);
150        /** See
151          RenderSystem
152         */
153        String validateConfigOptions(void);
154        /** See
155          RenderSystem
156         */
157        RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
158        /** See
159          RenderSystem
160         */
161        void reinitialise(void); // Used if settings changed mid-rendering
162        /** See
163          RenderSystem
164         */
165        void shutdown(void);
166
167        /** See
168          RenderSystem
169         */
170        void setAmbientLight(float r, float g, float b);
171        /** See
172          RenderSystem
173         */
174        void setShadingType(ShadeOptions so);
175        /** See
176          RenderSystem
177         */
178        void setLightingEnabled(bool enabled);
179       
180                /// @copydoc RenderSystem::createRenderWindow
181                RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
182                        bool fullScreen, const NameValuePairList *miscParams = 0);
183
184                /// @copydoc RenderSystem::createRenderTexture
185                RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
186                        TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
187                        const NameValuePairList *miscParams = 0 );
188               
189        /** See
190          RenderSystem
191         */
192        void destroyRenderWindow(RenderWindow* pWin);
193        /** See
194          RenderSystem
195         */
196        String getErrorDescription(long errorNumber) const;
197
198        /** See
199          RenderSystem
200         */
201        void convertColourValue(const ColourValue& colour, uint32* pDest);
202        /** See
203          RenderSystem
204         */
205        void setNormaliseNormals(bool normalise);
206
207        // -----------------------------
208        // Low-level overridden members
209        // -----------------------------
210        /** See
211          RenderSystem
212         */
213        void _useLights(const LightList& lights, unsigned short limit);
214        /** See
215          RenderSystem
216         */
217        void _setWorldMatrix(const Matrix4 &m);
218        /** See
219          RenderSystem
220         */
221        void _setViewMatrix(const Matrix4 &m);
222        /** See
223          RenderSystem
224         */
225        void _setProjectionMatrix(const Matrix4 &m);
226        /** See
227          RenderSystem
228         */
229        void _setSurfaceParams(const ColourValue &ambient,
230            const ColourValue &diffuse, const ColourValue &specular,
231            const ColourValue &emissive, Real shininess,
232            TrackVertexColourType tracking);
233        /** See
234          RenderSystem
235         */
236        void _setTexture(size_t unit, bool enabled, const String &texname);
237        /** See
238          RenderSystem
239         */
240        void _setTextureCoordSet(size_t stage, size_t index);
241        /** See
242          RenderSystem
243         */
244        void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
245            const Frustum* frustum = 0);
246        /** See
247          RenderSystem
248         */
249        void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
250        /** See
251          RenderSystem
252         */
253        void _setTextureAddressingMode(size_t stage, TextureUnitState::TextureAddressingMode tam);
254        /** See
255          RenderSystem
256         */
257        void _setTextureMatrix(size_t stage, const Matrix4& xform);
258        /** See
259          RenderSystem
260         */
261        void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
262        /** See
263          RenderSystem
264         */
265        void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
266        /** See
267          RenderSystem
268         */
269        void _setViewport(Viewport *vp);
270        /** See
271          RenderSystem
272         */
273        void _beginFrame(void);
274        /** See
275          RenderSystem
276         */
277        void _endFrame(void);
278        /** See
279          RenderSystem
280         */
281        void _setCullingMode(CullingMode mode);
282        /** See
283          RenderSystem
284         */
285        void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
286        /** See
287          RenderSystem
288         */
289        void _setDepthBufferCheckEnabled(bool enabled = true);
290        /** See
291          RenderSystem
292         */
293        void _setDepthBufferWriteEnabled(bool enabled = true);
294        /** See
295          RenderSystem
296         */
297        void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
298        /** See
299          RenderSystem
300         */
301        void _setDepthBias(ushort bias);
302        /** See
303          RenderSystem
304         */
305        void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
306                /** See
307          RenderSystem
308         */
309        void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
310        /** See
311          RenderSystem
312         */
313        void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
314            Matrix4& dest, bool forGpuProgram = false);
315        /** See
316        RenderSystem
317        */
318        void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
319            Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
320        /** See
321          RenderSystem
322         */
323                void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
324            Matrix4& dest, bool forGpuProgram = false);
325        /** See
326        RenderSystem
327        */
328        void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
329            bool forGpuProgram);
330        /** See
331        RenderSystem
332        */
333        void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
334        /** See
335        RenderSystem
336        */
337        void enableClipPlane (ushort index, bool enable);
338        /** See
339          RenderSystem
340         */
341        void _setRasterisationMode(SceneDetailLevel level);
342        /** See
343          RenderSystem
344         */
345        void setStencilCheckEnabled(bool enabled);
346        /** See RenderSystem.
347         */
348        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
349            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
350            StencilOperation stencilFailOp = SOP_KEEP,
351            StencilOperation depthFailOp = SOP_KEEP,
352            StencilOperation passOp = SOP_KEEP,
353            bool twoSidedOperation = false);
354        /** See
355          RenderSystem
356         */
357        void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
358        /** See
359          RenderSystem
360         */
361                void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
362        /** See
363          RenderSystem
364         */
365                void setVertexDeclaration(VertexDeclaration* decl);
366        /** See
367          RenderSystem
368         */
369                void setVertexBufferBinding(VertexBufferBinding* binding);
370        /** See
371          RenderSystem
372         */
373        void _render(const RenderOperation& op);
374        /** See
375          RenderSystem
376         */
377        void bindGpuProgram(GpuProgram* prg);
378        /** See
379          RenderSystem
380         */
381        void unbindGpuProgram(GpuProgramType gptype);
382        /** See
383          RenderSystem
384         */
385        void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
386        /** See
387          RenderSystem
388         */
389        void setClipPlanes(const PlaneList& clipPlanes);
390        /** See
391          RenderSystem
392         */
393        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
394        void clearFrameBuffer(unsigned int buffers,
395            const ColourValue& colour = ColourValue::Black,
396            Real depth = 1.0f, unsigned short stencil = 0);
397        HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
398        Real getHorizontalTexelOffset(void);
399        Real getVerticalTexelOffset(void);
400        Real getMinimumDepthInputValue(void);
401        Real getMaximumDepthInputValue(void);
402
403        // ----------------------------------
404        // GLRenderSystem specific members
405        // ----------------------------------
406        /**
407         * One time initialization for the RenderState of a context. Things that
408         * only need to be set once, like the LightingModel can be defined here.
409         */
410        void _oneTimeContextInitialization();
411        /** Switch GL context, dealing with involved internal cached states too
412        */
413        void _switchContext(GLContext *context);
414        /**
415         * Set current render target to target, enabling its GL context if needed
416         */
417        void _setRenderTarget(RenderTarget *target);
418        /**
419         * Register a render target->context mapping.
420         */
421        void _registerContext(RenderTarget *target, GLContext *context);
422        /**
423         * Unregister a render target->context mapping. If the context of target
424         * is the current context, change the context to the main context so it
425         * can be destroyed safely.
426         */
427        void _unregisterContext(RenderTarget *target);
428        /**
429         * Get the main context. This is generally the context with which
430         * a new context wants to share buffers and textures.
431         */
432        GLContext *_getMainContext();
433    };
434}
435#endif
436
Note: See TracBrowser for help on using the repository browser.