ShaderManager.hpp   ShaderManager.hpp 
skipping to change at line 23 skipping to change at line 23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _SHADERMANAGER_HPP_ #ifndef _SHADERMANAGER_HPP_
#define _SHADERMANAGER_HPP_ #define _SHADERMANAGER_HPP_
#include "OBJ.hpp" #include "S3DScene.hpp"
#include "StelOpenGL.hpp" #include "StelTexture.hpp"
#include "S3DEnum.hpp" #include "S3DEnum.hpp"
#include <QMap> #include <QMap>
class QOpenGLShaderProgram; class QOpenGLShaderProgram;
Q_DECLARE_LOGGING_CATEGORY(shaderMgr)
//! A structure for global shader parameters //! A structure for global shader parameters
struct GlobalShaderParameters struct GlobalShaderParameters
{ {
bool openglES; //true if we work with an OGL ES2 context, may have t o adapt shaders bool openglES; //true if we work with an OGL ES2 context, may have t o adapt shaders
bool shadowTransform; bool shadowTransform;
bool pixelLighting; bool pixelLighting;
bool bump; bool bump;
bool shadows; bool shadows;
S3DEnum::ShadowFilterQuality shadowFilterQuality; S3DEnum::ShadowFilterQuality shadowFilterQuality;
bool pcss; bool pcss;
skipping to change at line 56 skipping to change at line 58
}; };
//! A simple shader cache class that gives us the correct shader depending on desired configuration. //! A simple shader cache class that gives us the correct shader depending on desired configuration.
//! It also contains a uniform cache to avoid unnecessary glUniformLocation calls //! It also contains a uniform cache to avoid unnecessary glUniformLocation calls
class ShaderMgr class ShaderMgr
{ {
public: public:
ShaderMgr(); ShaderMgr();
~ShaderMgr(); ~ShaderMgr();
//! Enum for OpenGL shader attribute locations
enum ATTLOC
{
//! This is the OpenGL attribute location where vertex posit
ions are mapped to
ATTLOC_VERTEX,
//! This is the OpenGL attribute location where vertex norma
ls are mapped to
ATTLOC_NORMAL,
//! This is the OpenGL attribute location where vertex textu
re coordinates are mapped to
ATTLOC_TEXCOORD,
//! This is the OpenGL attribute location where vertex tange
nts are mapped to
ATTLOC_TANGENT,
//! This is the OpenGL attribute location where vertex bitan
gents are mapped to
ATTLOC_BITANGENT
};
//! Enum for OpenGL shader uniform locations (faster than accessing by string each time) //! Enum for OpenGL shader uniform locations (faster than accessing by string each time)
enum UNIFORM enum UNIFORM
{ {
//! Defines the ModelView matrix //! Defines the ModelView matrix
UNIFORM_MAT_MODELVIEW, UNIFORM_MAT_MODELVIEW,
//! Defines the Projection matrix //! Defines the Projection matrix
UNIFORM_MAT_PROJECTION, UNIFORM_MAT_PROJECTION,
//! Defines the combined ModelViewProjection matrix, used if shader needs no separation of the 2 for a bit of a speedup //! Defines the combined ModelViewProjection matrix, used if shader needs no separation of the 2 for a bit of a speedup
UNIFORM_MAT_MVP, UNIFORM_MAT_MVP,
//! Defines the 3x3 Normal matrix (transpose of the inverse MV matrix) //! Defines the 3x3 Normal matrix (transpose of the inverse MV matrix)
skipping to change at line 136 skipping to change at line 123
UNIFORM_VEC_COLOR, UNIFORM_VEC_COLOR,
//! Squared frustum splits (vec4) //! Squared frustum splits (vec4)
UNIFORM_VEC_SPLITDATA, UNIFORM_VEC_SPLITDATA,
//! Scaling of each frustum's light ortho projection (4xvec2 ) //! Scaling of each frustum's light ortho projection (4xvec2 )
UNIFORM_VEC_LIGHTORTHOSCALE, UNIFORM_VEC_LIGHTORTHOSCALE,
//! Alpha test threshold //! Alpha test threshold
UNIFORM_FLOAT_ALPHA_THRESH, UNIFORM_FLOAT_ALPHA_THRESH,
}; };
//! Returns a shader that supports the specified operations. Must be called within a GL context. //! Returns a shader that supports the specified operations. Must be called within a GL context.
inline QOpenGLShaderProgram* getShader(const GlobalShaderParameters &globals, const OBJ::Material *mat = NULL); inline QOpenGLShaderProgram* getShader(const GlobalShaderParameters &globals, const S3DScene::Material *mat = Q_NULLPTR);
//! Returns the Frustum/Boundingbox Debug shader //! Returns the Frustum/Boundingbox Debug shader
inline QOpenGLShaderProgram* getDebugShader(); inline QOpenGLShaderProgram* getDebugShader();
//! Returns the cubemapping shader //! Returns the cubemapping shader
inline QOpenGLShaderProgram* getCubeShader(); inline QOpenGLShaderProgram* getCubeShader();
//! Returns the basic texturing shader //! Returns the basic texturing shader
inline QOpenGLShaderProgram* getTextureShader(); inline QOpenGLShaderProgram* getTextureShader();
skipping to change at line 231 skipping to change at line 218
t_ShaderCache m_shaderCache; t_ShaderCache m_shaderCache;
typedef QHash<QByteArray,QOpenGLShaderProgram*> t_ShaderContentCache ; typedef QHash<QByteArray,QOpenGLShaderProgram*> t_ShaderContentCache ;
t_ShaderContentCache m_shaderContentCache; t_ShaderContentCache m_shaderContentCache;
typedef QHash<UNIFORM,GLuint> t_UniformCacheEntry; typedef QHash<UNIFORM,GLuint> t_UniformCacheEntry;
typedef QHash<const QOpenGLShaderProgram*, t_UniformCacheEntry> t_Un iformCache; typedef QHash<const QOpenGLShaderProgram*, t_UniformCacheEntry> t_Un iformCache;
t_UniformCache m_uniformCache; t_UniformCache m_uniformCache;
}; };
QOpenGLShaderProgram* ShaderMgr::getShader(const GlobalShaderParameters& gl obals,const OBJ::Material* mat) QOpenGLShaderProgram* ShaderMgr::getShader(const GlobalShaderParameters& gl obals,const S3DScene::Material* mat)
{ {
//Build bitflags from bools. Some stuff requires pixelLighting to be enabled, so check it too. //Build bitflags from bools. Some stuff requires pixelLighting to be enabled, so check it too.
uint flags = INVALID; uint flags = INVALID;
if(globals.openglES) flags|=OGL_ES2; if(globals.openglES) flags|=OGL_ES2;
if(!globals.shadowTransform) if(!globals.shadowTransform)
{ {
flags |= SHADING; flags |= SHADING;
if(globals.pixelLighting) flags|= PIXEL_LIGHTING; if(globals.pixelLighting) flags|= PIXEL_LIGHTING;
if(globals.pixelLighting && globals.shadows) flags|= SHADOWS ; if(globals.pixelLighting && globals.shadows) flags|= SHADOWS ;
skipping to change at line 257 skipping to change at line 244
if(globals.torchLight) flags|= TORCH; if(globals.torchLight) flags|= TORCH;
if(globals.frustumSplits == 1) flags|= SINGLE_SHADOW_FRUSTUM ; if(globals.frustumSplits == 1) flags|= SINGLE_SHADOW_FRUSTUM ;
} }
else else
{ {
flags |= TRANSFORM; flags |= TRANSFORM;
} }
if(mat) if(mat)
{ {
if(mat->alphatest && mat->texture && mat->texture->hasAlphaC hannel()) //alpha test needs diffuse texture, otherwise it would not make s ense if(mat->bAlphatest && mat->tex_Kd && mat->tex_Kd->hasAlphaCh annel()) //alpha test needs diffuse texture, otherwise it would not make se nse
flags|= ALPHATEST; flags|= ALPHATEST;
if(mat->hasSpecularity) if(mat->traits.hasSpecularity)
flags|= MAT_SPECULAR; flags|= MAT_SPECULAR;
if(mat->hasTransparency) if(mat->traits.hasTransparency || mat->traits.isFading)
flags|= BLENDING; flags|= BLENDING;
if(mat->texture) if(mat->traits.hasDiffuseTexture)
flags|= MAT_DIFFUSETEX; flags|= MAT_DIFFUSETEX;
if(mat->emissive_texture) if(mat->traits.hasEmissiveTexture)
flags|= MAT_EMISSIVETEX; flags|= MAT_EMISSIVETEX;
if(mat->bump_texture && globals.bump && globals.pixelLightin g) if(mat->traits.hasBumpTexture && globals.bump && globals.pix elLighting)
flags|= BUMP; flags|= BUMP;
if(mat->height_texture && globals.bump && globals.pixelLight ing) if(mat->traits.hasHeightTexture && globals.bump && globals.p ixelLighting)
flags|= HEIGHT; flags|= HEIGHT;
} }
return findOrLoadShader(flags); return findOrLoadShader(flags);
} }
QOpenGLShaderProgram* ShaderMgr::getDebugShader() QOpenGLShaderProgram* ShaderMgr::getDebugShader()
{ {
return findOrLoadShader(DEBUG); return findOrLoadShader(DEBUG);
} }
 End of changes. 12 change blocks. 
31 lines changed or deleted 13 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/