Added missing launcher
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / FogManager.cpp
... / ...
CommitLineData
1/******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
4 *
5 * Copyright (C) 2009 Jon Ring
6 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 *****************************************************************************/
22
23#include "FogManager.h"
24#include "ExtensionChecker.h"
25#include "m64p.h"
26#include "OpenGL.h"
27
28#ifndef GL_GLEXT_VERSION
29 //-----------------------------------------------------------------------------
30 // EXT_fog_coord functions
31 //-----------------------------------------------------------------------------
32 #ifndef GL_EXT_fog_coord
33 #define GL_EXT_fog_coord 1
34 #if defined(GL_GLEXT_PROTOTYPES) && !defined(HAVE_GLES)
35 extern void APIENTRY glFogCoordfEXT (GLfloat);
36 extern void APIENTRY glFogCoordfvEXT (const GLfloat *);
37 extern void APIENTRY glFogCoorddEXT (GLdouble);
38 extern void APIENTRY glFogCoorddvEXT (const GLdouble *);
39 extern void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, const GLvoid *);
40 #endif
41
42 typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord);
43 typedef void (APIENTRY * PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord);
44 typedef void (APIENTRY * PFNGLFOGCOORDDEXTPROC) (GLdouble coord);
45 typedef void (APIENTRY * PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord);
46 typedef void (APIENTRY * PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
47
48 #define GL_FOG_COORDINATE_SOURCE_EXT 0x8450
49 #define GL_FOG_COORDINATE_EXT 0x8451
50 #define GL_FOG_COORDINATE_ARRAY_EXT 0x8457
51 #endif
52
53 PFNGLFOGCOORDFEXTPROC glFogCoordfEXT;
54 PFNGLFOGCOORDFVEXTPROC glFogCoordfvEXT;
55 PFNGLFOGCOORDDEXTPROC glFogCoorddEXT;
56 PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT;
57 PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT;
58#endif
59
60#ifdef HAVE_GLES
61#define glFogi glFogf
62#endif
63
64//-----------------------------------------------------------------------------
65//! Static Variables
66//-----------------------------------------------------------------------------
67bool FogManager::m_fogExtensionsSupported = false;
68
69//-----------------------------------------------------------------------------
70//! Constructor
71//-----------------------------------------------------------------------------
72FogManager::FogManager()
73{
74 m_multiplier = 0;
75 m_offset = 0;
76}
77
78//-----------------------------------------------------------------------------
79//! Destructor
80//-----------------------------------------------------------------------------
81FogManager::~FogManager()
82{
83 dispose();
84}
85
86//-----------------------------------------------------------------------------
87//* Initialize
88//! Initializes fog extensions
89//-----------------------------------------------------------------------------
90void FogManager::initialize()
91{
92 m_multiplier = 0;
93 m_offset = 0;
94
95 //Initialize extensions
96 static bool fogExtensionInitialized = false;
97 if ( !fogExtensionInitialized )
98 {
99#ifndef HAVE_GLES
100 m_fogExtensionsSupported = isExtensionSupported("GL_EXT_fog_coord");
101 if ( m_fogExtensionsSupported )
102 {
103#ifndef GL_GLEXT_VERSION
104 glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)wglGetProcAddress( "glFogCoordfEXT" );
105 glFogCoordfvEXT = (PFNGLFOGCOORDFVEXTPROC)wglGetProcAddress( "glFogCoordfvEXT" );
106 glFogCoorddEXT = (PFNGLFOGCOORDDEXTPROC)wglGetProcAddress( "glFogCoorddEXT" );
107 glFogCoorddvEXT = (PFNGLFOGCOORDDVEXTPROC)wglGetProcAddress( "glFogCoorddvEXT" );
108 glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)wglGetProcAddress( "glFogCoordPointerEXT" );
109#endif
110 fogExtensionInitialized = true;
111 }
112#endif
113 }
114
115#ifndef HAVE_GLES
116 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
117#endif
118}
119
120//-----------------------------------------------------------------------------
121//! Dispose
122//-----------------------------------------------------------------------------
123void FogManager::dispose()
124{
125}
126
127//-----------------------------------------------------------------------------
128//* SetFogCoordPointer
129//! Function used to set vertex based fog
130//! @param[in] type Specifies the datatype of each fog coordinate in the array.
131//! @param[in] stride Specifies the byte offset between consecutive fog coordinates
132//! @param[in] pointer Specifies a pointer to the first component of the first fog coordinate in the array
133//! http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.opengl/doc/openglrf/glFogCoordPointerEXT.htm
134//-----------------------------------------------------------------------------
135void FogManager::setFogCoordPointer(unsigned int type, int stride, const void* pointer)
136{
137 if ( m_fogExtensionsSupported )
138 {
139 glFogCoordPointerEXT(type, stride, pointer);
140 }
141}
142
143//-----------------------------------------------------------------------------
144//* Enable Fog Coord Array
145//! Function used to enable vertex based fog
146//! @see disableFogCoordArray()
147//-----------------------------------------------------------------------------
148void FogManager::enableFogCoordArray()
149{
150 if ( m_fogExtensionsSupported )
151 {
152 glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
153 }
154}
155
156//-----------------------------------------------------------------------------
157//* Disable Fog Coord Array
158//! Function used to disable vertex based fog
159//! @see enableFogCoordArray()
160//-----------------------------------------------------------------------------
161void FogManager::disableFogCoordArray()
162{
163 if ( m_fogExtensionsSupported )
164 {
165 glDisableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
166 }
167}
168
169//-----------------------------------------------------------------------------
170//* Set Linear Fog
171//! Function used to set linear fog using a linear fog equation
172//! Equation for linear fog is:
173//! <KBD> fog = (end - z) / (end - start) </KBD>
174//! where z is the distance in eye coordinates from the origin to the fragment being fogged
175//! @param start Specifies start (near) distance used in the linear fog equation.
176//! The initial near distance is 0.
177//! @param end Specifies end (the far) distance used in the linear fog equation.
178//! The initial far distance is 1.
179//! http://www.hmug.org/man/3/glFogi.php
180//-----------------------------------------------------------------------------
181void FogManager::setLinearFog(float start, float end)
182{
183 glFogi(GL_FOG_MODE, GL_LINEAR);
184 glFogf(GL_FOG_START, start);
185 glFogf(GL_FOG_END, end);
186}
187
188//-----------------------------------------------------------------------------
189//* Set Fog Color
190//! @param r The red component of the fog color
191//! @param g The green component of the fog color
192//! @param b The blue component of the fog color
193//! @param a The alpha component of the fog color
194//-----------------------------------------------------------------------------
195void FogManager::setFogColor(float r, float g, float b, float a)
196{
197 float fogColor[4] = { r,g,b,a };
198 glFogfv(GL_FOG_COLOR, fogColor );
199}