Show program-glsl.h syntax highlighted
/***************************************************************************
program-glsl.h - GLSL vertex/fragment programs
-------------------
begin : Mon Jan 5 2004
copyright : (C) 2004 by Reality Rift Studios
email : mattias@realityrift.com
last modify date : Mon Sep 20 2004
last modify : GLSL manager
l.m. copyright : (C) 2004 by Arcadia Design s.r.l.
email : Dario Deledda (penguindark@hotmail.com)
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoDevOpenGL, shader-arb.h
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2004
Reality Rift Studios. All Rights Reserved.
Contributors: Dario Deledda (penguindark@hotmail.com)
***************************************************************************/
#ifndef __NEOGLSHADER_PROGRAMGLSL_H
#define __NEOGLSHADER_PROGRAMGLSL_H
#include "device.h"
#include "shader.h"
#include <neoengine/base.h>
#include <neoengine/pointer.h>
#include <neoengine/loadableentity.h>
#include <neoengine/file.h>
#include <vector>
using namespace std;
namespace NeoOGL
{
struct GLSLattrib{
/*! Parameter type */
GLuint m_eType;
/*! Attrib shader alias */
string m_strName;
/*! Attrib index in the vertex buffer */
GLuint m_uiIndex;
};
/**
* \brief GLSL program neoengine implementation
* \author Dario Deledda (penguindark@hotmail.com)
*/
class ProgramGLSL:public Shader
{
protected:
/*! Native shader object */
unsigned int m_uiShader;
/*! Shader type enum (vertexshader or fragmentshader) */
GLenum m_eType;
/*! string for vx/fg shader loading */
string m_strSource;
/*! vector of GLSL shader's vertexbuffer attributes */
vector<GLSLattrib> m_AttribVec;
/*! All attrib parameters */
std::vector< GLSLattrib > m_vAttrib;
/*! delete all space form the string */
void deleteSpace(std::string &inString);
/*! match the uniform strings */
bool match_uniform(const std::string& inString);
/*! match the attrib strings */
bool match_attrib(const string& inString);
/*! Overload LoadNode no compile inside */
bool LoadNode( unsigned int uiFlags );
public:
/*!vertex and fragment shaders handle */
vector<GLhandleARB> m_vhVS,m_vhFS,m_vhGS;
/*! Geometry shader input type */
GLenum m_eGeometryInpType;
/*! Geometry shader output type */
GLenum m_eGeometryOutType;
/*! Geometry shader output vertex max number */
GLint m_iGeometryOutVertex;
/*!GLSL program handle */
GLhandleARB m_hProgram;
/*!bind all the GLSL uniform variables */
bool BindParamGLSL(const std::string& inString);
/*!load all GLSL source file */
bool LoadSource( string fileName );
/**
* \param pkDevice Render device
* \param eType Shader type
* \param rstrName Shader name
* \param pkShaderPool Ptr to shader pool
* \param pkFileManager Filemananger, null if default
*/
ProgramGLSL( Device *pkDevice, SHADERTYPE eType, const std::string &rstrName, NeoEngine::ShaderPool *pkShaderPool, NeoEngine::FileManager *pkFileManager = 0);
/**
* Destruct this instance of the OpenGL vertex shader instance
*/
virtual ~ProgramGLSL();
/**
* Bild the shader
* \param pstrSourceV Pointer to source vertex shader string
* \param pstrSourceF Pointer to source fragment shader string
* \param pstrSourceG Pointer to source geometry shader string
* \return True if succesful, false otherwise.
*/
virtual bool Build( const std::string *pstrSourceV = 0,
const std::string *pstrSourceF = 0,
const std::string *pstrSourceG = 0);
/**
* Compile the pipeline shader, performing OpenGL and target specific operations
* \param pstrSource Source string, null if use already loaded source
* \return True if compiled, or false
*/
virtual bool Compile( const std::string *pstrSource = 0 );
/**
* Compile a Fragment shader, performing OpenGL and target specific operations
* \param pstrSource Source string, null if use already loaded source
* \return True if compiled, or false
*/
virtual bool CompileFrag( const std::string *pstrSource = 0 );
/**
* Compile a Vertex shader, performing OpenGL and target specific operations
* \param pstrSource Source string, null if use already loaded source
* \return True if compiled, or false
*/
virtual bool CompileVert( const std::string *pstrSource = 0 );
/**
* Compile a Geometry shader, performing OpenGL and target specific operations
* \param pstrSource Source string, null if use already loaded source
* \return True if compiled, or false
*/
virtual bool CompileGeometry( const std::string *pstrSource = 0 );
/**
* Set the Geometry shader input type
* \param inType Source enum that specify the input type
* \return Always True
*/
virtual bool SetGeometryInputType( const unsigned int inType )
{ m_eGeometryInpType=inType; return true; }
/**
* Set the Geometry shader output type
* \param inType Source enum that specify the output type
* \return Always True
*/
virtual bool SetGeometryOutputType( const unsigned int inType )
{ m_eGeometryOutType=inType; return true; }
/**
* Set the Geometry shader max number of vertex in output
* \param inType number of output vertex
* \return Always True
*/
virtual bool SetGeometryVertexOutNum( const unsigned int inNum )
{ m_iGeometryOutVertex=inNum; return true; }
/**
* Link the shader with the program, performing OpenGL and target specific operations
* \return True if linked, or false
*/
virtual bool Link(void);
/**
* Clear the shader program, performing OpenGL and target specific operations
* \return True if cleared, or false
*/
virtual bool Clear(void);
/**
* Bind this pipeline shader and parameters, performing OpenGL and target specific operations
* \param pkPrimitive Primitive currently processing
* \return True if bound, or false if error
*/
virtual bool Bind( NeoEngine::RenderPrimitive *pkPrimitive );
/**
* Disable shader
* \return True if successful, false if error
*/
virtual bool Unbind();
/**
* Bind light parameters
* \param pkPrimitive Primitive currently processing
* \return True if bound, or false if error
*/
virtual bool BindLightParams( NeoEngine::RenderPrimitive *pkPrimitive );
/**
* \param inMatrix The matrix to use for th etexture matrix calculus
* \return True if all ok, or false if error
*/
virtual bool SetTextureModeMatrix(NeoEngine::Matrix &inMatrix);
};
#ifdef WIN32
# ifdef _MSC_VER
# pragma warning( disable : 4786 )
# if ( _MSC_VER >= 1300 )
typedef NeoEngine::Pointer< ProgramGLSL > ProgramGLSLPtr;
EXPIMP_TEMPLATE template class NEOENGINE_API NeoEngine::Pointer< ProgramGLSL >;
EXPIMP_TEMPLATE template class NEOENGINE_API std::allocator< NeoEngine::Pointer< ProgramGLSL > >;
EXPIMP_TEMPLATE template class NEOENGINE_API std::vector< NeoEngine::Pointer< ProgramGLSL > >;
# elif defined(_MSC_VER)
typedef NeoEngine::Pointer< ProgramGLSL > ProgramGLSLPtr;
EXPIMP_TEMPLATE template class NEOENGINE_API NeoEngine::Pointer< ProgramGLSL >;
EXPIMP_TEMPLATE template class NEOENGINE_API std::vector< NeoEngine::Pointer< ProgramGLSL > >
# endif
# else if defined __MINGW32__
typedef NeoEngine::Pointer< ProgramGLSL > ProgramGLSLPtr;
# endif
#else
typedef NeoEngine::Pointer< ProgramGLSL > ProgramGLSLPtr;
#endif
};
#endif
See more files for this project here