1 /******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
5 * Copyright (C) 2009 Jon Ring
6 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
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.
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.
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 *****************************************************************************/
23 #include "FogManager.h"
24 #include "ExtensionChecker.h"
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 *);
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);
48 #define GL_FOG_COORDINATE_SOURCE_EXT 0x8450
49 #define GL_FOG_COORDINATE_EXT 0x8451
50 #define GL_FOG_COORDINATE_ARRAY_EXT 0x8457
53 PFNGLFOGCOORDFEXTPROC glFogCoordfEXT;
54 PFNGLFOGCOORDFVEXTPROC glFogCoordfvEXT;
55 PFNGLFOGCOORDDEXTPROC glFogCoorddEXT;
56 PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT;
57 PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT;
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
67 bool FogManager::m_fogExtensionsSupported = false;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
72 FogManager::FogManager()
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 FogManager::~FogManager()
86 //-----------------------------------------------------------------------------
88 //! Initializes fog extensions
89 //-----------------------------------------------------------------------------
90 void FogManager::initialize()
95 //Initialize extensions
96 static bool fogExtensionInitialized = false;
97 if ( !fogExtensionInitialized )
100 m_fogExtensionsSupported = isExtensionSupported("GL_EXT_fog_coord");
101 if ( m_fogExtensionsSupported )
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" );
110 fogExtensionInitialized = true;
116 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 void FogManager::dispose()
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 //-----------------------------------------------------------------------------
135 void FogManager::setFogCoordPointer(unsigned int type, int stride, const void* pointer)
137 if ( m_fogExtensionsSupported )
139 glFogCoordPointerEXT(type, stride, pointer);
143 //-----------------------------------------------------------------------------
144 //* Enable Fog Coord Array
145 //! Function used to enable vertex based fog
146 //! @see disableFogCoordArray()
147 //-----------------------------------------------------------------------------
148 void FogManager::enableFogCoordArray()
150 if ( m_fogExtensionsSupported )
152 glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
156 //-----------------------------------------------------------------------------
157 //* Disable Fog Coord Array
158 //! Function used to disable vertex based fog
159 //! @see enableFogCoordArray()
160 //-----------------------------------------------------------------------------
161 void FogManager::disableFogCoordArray()
163 if ( m_fogExtensionsSupported )
165 glDisableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
169 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
181 void FogManager::setLinearFog(float start, float end)
183 glFogi(GL_FOG_MODE, GL_LINEAR);
184 glFogf(GL_FOG_START, start);
185 glFogf(GL_FOG_END, end);
188 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
195 void FogManager::setFogColor(float r, float g, float b, float a)
197 float fogColor[4] = { r,g,b,a };
198 glFogfv(GL_FOG_COLOR, fogColor );