Implemented shader and program object classes.
--HG-- branch : gsoc2013-dfighterhg/feature/gsoc2013-dfighter
parent
ed5741addd
commit
b3ea9ee787
@ -0,0 +1,64 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "driver_glsl_shader_base.h"
|
||||
#include "stdopengl.h"
|
||||
#include "driver_opengl_extension.h"
|
||||
|
||||
#define MAX_SHADER_COMPILE_INFOLOG 1024
|
||||
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
|
||||
void CGLSLShaderBase::shaderSource( const char *source )
|
||||
{
|
||||
nlassert( shaderId != 0 );
|
||||
|
||||
const GLchar *p[1];
|
||||
p[ 0 ] = source;
|
||||
GLint lengths[ 1 ];
|
||||
lengths[ 0 ] = strlen( source );
|
||||
|
||||
nglShaderSource( shaderId, 1, p, lengths );
|
||||
}
|
||||
|
||||
bool CGLSLShaderBase::compile( std::string &log )
|
||||
{
|
||||
nglCompileShader( shaderId );
|
||||
|
||||
GLint ok;
|
||||
nglGetShaderiv( shaderId, GL_COMPILE_STATUS, &ok );
|
||||
|
||||
if( ok != 0 )
|
||||
{
|
||||
char infoLog[ MAX_SHADER_COMPILE_INFOLOG ];
|
||||
nglGetShaderInfoLog( shaderId, MAX_SHADER_COMPILE_INFOLOG, NULL, infoLog );
|
||||
log.assign( infoLog );
|
||||
return false;
|
||||
}
|
||||
|
||||
compiled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef GLSL_SHADER_BASE_H
|
||||
#define GLSL_SHADER_BASE_H
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
/// Base class for OpenGL shader objects
|
||||
class CGLSLShaderBase
|
||||
{
|
||||
public:
|
||||
CGLSLShaderBase(){
|
||||
shaderId = 0;
|
||||
compiled = false;
|
||||
}
|
||||
|
||||
virtual ~CGLSLShaderBase(){}
|
||||
|
||||
void shaderSource( const char *source );
|
||||
bool compile( std::string &log );
|
||||
|
||||
unsigned int getShaderId() const{ return shaderId; }
|
||||
bool isCompiled() const{ return compiled; }
|
||||
|
||||
protected:
|
||||
unsigned int shaderId;
|
||||
|
||||
private:
|
||||
bool compiled;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
#include "driver_opengl.h"
|
||||
#include "driver_glsl_program.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
bool CDriverGL3::activeGLSLProgram( CGLSLProgram *program )
|
||||
{
|
||||
if( !program )
|
||||
{
|
||||
_VertexProgramEnabled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( program->isLinked() )
|
||||
return false;
|
||||
|
||||
nglValidateProgram( program->getProgramId() );
|
||||
|
||||
GLint ok;
|
||||
nglGetProgramiv( program->getProgramId(), GL_VALIDATE_STATUS, &ok );
|
||||
if( ok != GL_TRUE )
|
||||
return false;
|
||||
|
||||
nglUseProgram( program->getProgramId() );
|
||||
|
||||
GLenum error = glGetError();
|
||||
if( error != GL_NO_ERROR )
|
||||
return false;
|
||||
|
||||
_VertexProgramEnabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue