Commit d45675a3 authored by Jan Möbius's avatar Jan Möbius
Browse files

Christopher: Shaderutils uniform setter für float arrays

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12599 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c5898d91
...@@ -326,6 +326,14 @@ namespace GLSL { ...@@ -326,6 +326,14 @@ namespace GLSL {
checkGLError(); checkGLError();
} }
void Program::setUniform(const char *name, GLfloat *values, int count) {
checkGLError();
GLint location = glGetUniformLocation(this->m_programId, name);
checkGLError2(name);
glUniform1fv(location, count, values);
checkGLError();
}
void Program::setUniform(const char *name, int index, bool value) { void Program::setUniform(const char *name, int index, bool value) {
char varName[1024]; char varName[1024];
snprintf(varName, 1024, "%s[%d]", name, index); snprintf(varName, 1024, "%s[%d]", name, index);
......
/*===========================================================================*\ /*===========================================================================*\
* * * *
* OpenFlipper * * OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org * * www.openflipper.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenFlipper. * * This file is part of OpenFlipper. *
* * * *
* OpenFlipper is free software: you can redistribute it and/or modify * * OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
* following exceptions: * * following exceptions: *
* * * *
* If other files instantiate templates or use macros * * If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and * * or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does * * link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the * * not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however * * GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be * * invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. * * covered by the GNU Lesser General Public License. *
* * * *
* OpenFlipper is distributed in the hope that it will be useful, * * OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. * * GNU Lesser General Public License for more details. *
* * * *
* You should have received a copy of the GNU LesserGeneral Public * * You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, * * License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Author$ * * $Author$ *
* $Date$ * * $Date$ *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/******************************************************************************* /*******************************************************************************
* GLSLShader.h * GLSLShader.h
* *
* Utility classes for GLSL shaders. * Utility classes for GLSL shaders.
* *
* (C)2007 * (C)2007
* Lehrstuhl I8 RWTH-Aachen, http://www.graphics.rwth-aachen.de * Lehrstuhl I8 RWTH-Aachen, http://www.graphics.rwth-aachen.de
* Author: Markus Tavenrath <speedygoo@speedygoo.de> * Author: Markus Tavenrath <speedygoo@speedygoo.de>
* *
******************************************************************************/ ******************************************************************************/
#ifndef GLSLSHADER_H #ifndef GLSLSHADER_H
#define GLSLSHADER_H #define GLSLSHADER_H
//============================================================================== //==============================================================================
#include "../Config/ACGDefines.hh" #include "../Config/ACGDefines.hh"
#include <ACG/Math/VectorT.hh> #include <ACG/Math/VectorT.hh>
#include <list> #include <list>
#include <string> #include <string>
//============================================================================== //==============================================================================
/** \brief This namespace contains all the classes and functions for handling /** \brief This namespace contains all the classes and functions for handling
* GLSL shader and program objects. * GLSL shader and program objects.
*/ */
namespace GLSL { namespace GLSL {
#define GLSL_MAX_LOGSIZE 16384 #define GLSL_MAX_LOGSIZE 16384
typedef std::list<std::string> StringList; typedef std::list<std::string> StringList;
/** \brief A generic shader base class /** \brief A generic shader base class
*/ */
class ACGDLLEXPORT Shader { class ACGDLLEXPORT Shader {
public: public:
Shader(GLenum shaderType); Shader(GLenum shaderType);
virtual ~Shader(); virtual ~Shader();
void setSource(StringList source); void setSource(StringList source);
// FIXME implement StringList getSource(); // FIXME implement StringList getSource();
bool compile(); bool compile();
protected: protected:
GLuint m_shaderId; GLuint m_shaderId;
friend class Program; friend class Program;
}; };
typedef Shader* PtrShader; typedef Shader* PtrShader;
typedef const Shader* PtrConstShader; typedef const Shader* PtrConstShader;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** \brief GLSL vertex shader. /** \brief GLSL vertex shader.
*/ */
class ACGDLLEXPORT VertexShader : public Shader { class ACGDLLEXPORT VertexShader : public Shader {
public: public:
VertexShader(); VertexShader();
virtual ~VertexShader(); virtual ~VertexShader();
}; };
typedef VertexShader* PtrVertexShader; typedef VertexShader* PtrVertexShader;
typedef const VertexShader* PtrVertexConstShader; typedef const VertexShader* PtrVertexConstShader;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** \brief GLSL fragment shader. /** \brief GLSL fragment shader.
*/ */
class ACGDLLEXPORT FragmentShader : public Shader { class ACGDLLEXPORT FragmentShader : public Shader {
public: public:
FragmentShader(); FragmentShader();
virtual ~FragmentShader(); virtual ~FragmentShader();
}; };
typedef FragmentShader* PtrFragmentShader; typedef FragmentShader* PtrFragmentShader;
typedef const FragmentShader* PtrConstFragmentShader; typedef const FragmentShader* PtrConstFragmentShader;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** \brief GLSL program class. /** \brief GLSL program class.
* *
* A GLSL program links together the vertex and fragment shaders. * A GLSL program links together the vertex and fragment shaders.
*/ */
class ACGDLLEXPORT Program { class ACGDLLEXPORT Program {
public: public:
Program(); Program();
virtual ~Program(); virtual ~Program();
void attach(PtrConstShader shader); void attach(PtrConstShader shader);
void detach(PtrConstShader shader); void detach(PtrConstShader shader);
void link(); void link();
void setUniform(const char *name, GLint value); void setUniform(const char *name, GLint value);
void setUniform(const char *name, GLfloat value); void setUniform(const char *name, GLfloat value);
void setUniform(const char *name, const ACG::Vec2f &value); void setUniform(const char *name, const ACG::Vec2f &value);
void setUniform(const char *name, const ACG::Vec3f &value); void setUniform(const char *name, const ACG::Vec3f &value);
void setUniform(const char *name, const ACG::Vec4f &value); void setUniform(const char *name, const ACG::Vec4f &value);
void setUniform(const char *name, GLint *value, int count); void setUniform(const char *name, GLint *value, int count);
void setUniform(const char *name, GLfloat *value, int count);
// set element of array
void setUniform(const char *name, int index, bool value); // set element of array
void setUniform(const char *name, int index, int value); void setUniform(const char *name, int index, bool value);
void setUniform(const char *name, int index, float value); void setUniform(const char *name, int index, int value);
void setUniform(const char *name, int index, float value);
void bindAttributeLocation(unsigned int index, const char *name);
int getAttributeLocation(const char *name); void bindAttributeLocation(unsigned int index, const char *name);
int getUniformLocation(const char *name); int getAttributeLocation(const char *name);
int getUniformLocation(const char *name);
void use();
void use();
void disable();
void disable();
bool isActive();
bool isActive();
private:
private:
std::list<PtrConstShader> m_linkedShaders;
GLint m_programId; std::list<PtrConstShader> m_linkedShaders;
}; GLint m_programId;
};
typedef Program* PtrProgram;
typedef const Program* PtrConstProgram; typedef Program* PtrProgram;
typedef const Program* PtrConstProgram;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
GLSL::StringList ACGDLLEXPORT loadShader(const char *filename);
GLSL::StringList ACGDLLEXPORT loadShader(const char *filename);
GLSL::PtrVertexShader ACGDLLEXPORT loadVertexShader(const char *name);
GLSL::PtrFragmentShader ACGDLLEXPORT loadFragmentShader(const char *name); GLSL::PtrVertexShader ACGDLLEXPORT loadVertexShader(const char *name);
GLSL::PtrFragmentShader ACGDLLEXPORT loadFragmentShader(const char *name);
}
}
//==============================================================================
//==============================================================================
// Local Variables:
// mode: C++ // Local Variables:
// c-basic-offset: 2 // mode: C++
// indent-tabs-mode: nil // c-basic-offset: 2
// End: // indent-tabs-mode: nil
// End:
//==============================================================================
//==============================================================================
// GLSLSHADER_H
#endif // GLSLSHADER_H
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment