Loading common/CMakeLists.txt +15 −0 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,20 @@ include_directories( ) ) if(KICAD_GAL) if(KICAD_GAL) # Generate files containing shader programs add_custom_command ( OUTPUT gal/opengl/shader_src.h DEPENDS gal/opengl/make_shader_src_h.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/common/gal/opengl COMMAND ${SHELL} ARGS ${PROJECT_SOURCE_DIR}/common/gal/opengl/make_shader_src_h.sh ) add_custom_target ( ShaderHeader ALL DEPENDS gal/opengl/shader_src.h ) set(GAL_SRCS set(GAL_SRCS drawpanel_gal.cpp drawpanel_gal.cpp painter.cpp painter.cpp Loading @@ -27,6 +41,7 @@ set(GAL_SRCS ) ) add_library(gal STATIC ${GAL_SRCS}) add_library(gal STATIC ${GAL_SRCS}) add_dependencies(gal ShaderHeader) if(WIN32) if(WIN32) add_definitions(-DGLEW_STATIC) add_definitions(-DGLEW_STATIC) Loading common/drawpanel_gal.cpp +0 −7 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ #include <wx/window.h> #include <wx/window.h> #include <wx/event.h> #include <wx/event.h> #include <wx/colour.h> #include <wx/colour.h> #include <wx/stdpaths.h> #include <wx/filename.h> #include <wx/filename.h> #include <class_drawpanel_gal.h> #include <class_drawpanel_gal.h> Loading Loading @@ -56,11 +55,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view = NULL; m_view = NULL; m_painter = NULL; m_painter = NULL; wxStandardPaths paths; wxFileName executableFile( paths.GetExecutablePath() ); m_galShaderPath = std::string( ( executableFile.GetPath() + wxT( "/../../common/gal/opengl" ) ).mb_str() ); SwitchBackend( aGalType, true ); SwitchBackend( aGalType, true ); SetBackgroundStyle( wxBG_STYLE_CUSTOM ); SetBackgroundStyle( wxBG_STYLE_CUSTOM ); Loading Loading @@ -170,7 +164,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) { { case GAL_TYPE_OPENGL: case GAL_TYPE_OPENGL: m_gal = new KiGfx::OPENGL_GAL( this, this, this, aUseShaders ); m_gal = new KiGfx::OPENGL_GAL( this, this, this, aUseShaders ); static_cast<KiGfx::OPENGL_GAL*> (m_gal)->SetShaderPath( m_galShaderPath ); break; break; case GAL_TYPE_CAIRO: case GAL_TYPE_CAIRO: Loading common/gal/opengl/make_shader_src_h.sh 0 → 100755 +39 −0 Original line number Original line Diff line number Diff line #!/bin/bash # Make a header file containing GLSL source code echo "Generating headers containing GLSL source code.." # Source files to be included SHADER_SRC=( "shader.vert" "shader.frag" ) # Number of shaders SHADERS_NUMBER=${#SHADER_SRC[@]} OUTPUT="shader_src.h" # Prepare GLSL source to be included in C array function processSrc { # 1st part: remove /* */ comments # 2nd part: remove // comments # 3rd part: remove blank lines (or containing only whitespaces) # 4th & 5th part: wrap every line in quotation marks sed '/\/\*/,/\*\//d; s/[ \t]*\/\/.*$//; /^[ \t]*$/d; s/^[ \t]*/"/; s/[ \t]*$/\\n"/' $1 >> $OUTPUT echo "," >> $OUTPUT } # Header echo "#ifndef SHADER_SRC_H #define SHADER_SRC_H const unsigned int shaders_number = $SHADERS_NUMBER; const char *shaders_src[] = {" > $OUTPUT # Main contents for filename in "${SHADER_SRC[@]}" do processSrc $filename done # Footer echo "}; #endif /* SHADER_SRC_H */" >> $OUTPUT echo "Done." common/gal/opengl/opengl_gal.cpp +2 −3 Original line number Original line Diff line number Diff line Loading @@ -74,7 +74,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, isUseShader = isUseShaders; isUseShader = isUseShaders; isShaderInitialized = false; isShaderInitialized = false; isGrouping = false; isGrouping = false; shaderPath = "../../common/gal/opengl"; wxSize parentSize = aParent->GetSize(); wxSize parentSize = aParent->GetSize(); isVboInitialized = false; isVboInitialized = false; Loading Loading @@ -359,12 +358,12 @@ void OPENGL_GAL::BeginDrawing() // Compile the shaders // Compile the shaders if( !isShaderInitialized && isUseShader ) if( !isShaderInitialized && isUseShader ) { { if( !shader.AddSource( shaderPath + std::string( "/shader.vert" ), SHADER_TYPE_VERTEX ) ) if( !shader.LoadBuiltinShader( 0, SHADER_TYPE_VERTEX ) ) { { wxLogFatalError( wxT( "Cannot compile vertex shader!" ) ); wxLogFatalError( wxT( "Cannot compile vertex shader!" ) ); } } if( !shader.AddSource( shaderPath + std::string( "/shader.frag" ), SHADER_TYPE_FRAGMENT ) ) if( !shader.LoadBuiltinShader( 1, SHADER_TYPE_FRAGMENT ) ) { { wxLogFatalError( wxT( "Cannot compile fragment shader!" ) ); wxLogFatalError( wxT( "Cannot compile fragment shader!" ) ); } } Loading common/gal/opengl/shader.cpp +91 −74 Original line number Original line Diff line number Diff line Loading @@ -32,14 +32,15 @@ #include <wx/log.h> #include <wx/log.h> #include <gal/opengl/shader.h> #include <gal/opengl/shader.h> #include "shader_src.h" using namespace KiGfx; using namespace KiGfx; SHADER::SHADER() : SHADER::SHADER() : isProgramCreated( false ), isProgramCreated( false ), isShaderLinked( false ), isShaderLinked( false ), maximumVertices( 4 ), active( false ), active( false ), maximumVertices( 4 ), geomInputType( GL_LINES ), geomInputType( GL_LINES ), geomOutputType( GL_LINES ) geomOutputType( GL_LINES ) { { Loading @@ -62,7 +63,84 @@ SHADER::~SHADER() } } void SHADER::ProgramInfo( GLuint aProgram ) bool SHADER::LoadBuiltinShader( unsigned int aShaderNumber, ShaderType aShaderType ) { if( aShaderNumber >= shaders_number ) return false; return addSource( std::string( shaders_src[aShaderNumber] ), aShaderType ); } bool SHADER::LoadShaderFromFile( const std::string& aShaderSourceName, ShaderType aShaderType ) { // Load shader sources const std::string shaderSource = readSource( aShaderSourceName ); return addSource( shaderSource, aShaderType ); } void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType ) { maximumVertices = maxVertices; geomInputType = geometryInputType; geomOutputType = geometryOutputType; } bool SHADER::Link() { // Shader linking glLinkProgram( programNumber ); programInfo( programNumber ); // Check the Link state glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked ); #ifdef __WXDEBUG__ if( !isShaderLinked ) { int maxLength; glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength ); maxLength = maxLength + 1; char *linkInfoLog = new char[maxLength]; glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog ); std::cerr << "Shader linking error:" << std::endl; std::cerr << linkInfoLog; delete[] linkInfoLog; } #endif /* __WXDEBUG__ */ return isShaderLinked; } void SHADER::AddParameter( const std::string& aParameterName ) { GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() ); if( location != -1 ) { parameterLocation.push_back( location ); } } void SHADER::SetParameter( int parameterNumber, float value ) { glUniform1f( parameterLocation[parameterNumber], value ); } int SHADER::GetAttribute( std::string aAttributeName ) const { return glGetAttribLocation( programNumber, aAttributeName.c_str() ); } void SHADER::programInfo( GLuint aProgram ) { { GLint glInfoLogLength = 0; GLint glInfoLogLength = 0; GLint writtenChars = 0; GLint writtenChars = 0; Loading @@ -83,7 +161,7 @@ void SHADER::ProgramInfo( GLuint aProgram ) } } void SHADER::ShaderInfo( GLuint aShader ) void SHADER::shaderInfo( GLuint aShader ) { { GLint glInfoLogLength = 0; GLint glInfoLogLength = 0; GLint writtenChars = 0; GLint writtenChars = 0; Loading @@ -104,7 +182,7 @@ void SHADER::ShaderInfo( GLuint aShader ) } } std::string SHADER::ReadSource( std::string aShaderSourceName ) std::string SHADER::readSource( std::string aShaderSourceName ) { { // Open the shader source for reading // Open the shader source for reading std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in ); std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in ); Loading @@ -130,7 +208,7 @@ std::string SHADER::ReadSource( std::string aShaderSourceName ) } } bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShaderType ) bool SHADER::addSource( const std::string& aShaderSource, ShaderType aShaderType ) { { if( isShaderLinked ) if( isShaderLinked ) { { Loading @@ -144,24 +222,21 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader isProgramCreated = true; isProgramCreated = true; } } // Load shader sources std::string shaderSource = ReadSource( aShaderSourceName ); // Create a shader // Create a shader GLuint shaderNumber = glCreateShader( aShaderType ); GLuint shaderNumber = glCreateShader( aShaderType ); shaderNumbers.push_back( shaderNumber ); shaderNumbers.push_back( shaderNumber ); // Get the program info // Get the program info ProgramInfo( programNumber ); programInfo( programNumber ); // Copy to char array // Copy to char array char* source = new char[shaderSource.size() + 1]; char* source = new char[aShaderSource.size() + 1]; strcpy( source, shaderSource.c_str() ); strcpy( source, aShaderSource.c_str() ); const char** source_ = (const char**) ( &source ); const char** source_ = (const char**) ( &source ); // Attach the source // Attach the source glShaderSource( shaderNumber, 1, source_, NULL ); glShaderSource( shaderNumber, 1, source_, NULL ); ProgramInfo( programNumber ); programInfo( programNumber ); // Compile and attach shader to the program // Compile and attach shader to the program glCompileShader( shaderNumber ); glCompileShader( shaderNumber ); Loading @@ -171,13 +246,13 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader { { wxLogError( wxT( "Shader compilation error" ) ); wxLogError( wxT( "Shader compilation error" ) ); ShaderInfo( shaderNumber ); shaderInfo( shaderNumber ); return false; return false; } } glAttachShader( programNumber, shaderNumber ); glAttachShader( programNumber, shaderNumber ); ProgramInfo( programNumber ); programInfo( programNumber ); // Special handling for the geometry shader // Special handling for the geometry shader if( aShaderType == SHADER_TYPE_GEOMETRY ) if( aShaderType == SHADER_TYPE_GEOMETRY ) Loading @@ -193,61 +268,3 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader return true; return true; } } void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType ) { maximumVertices = maxVertices; geomInputType = geometryInputType; geomOutputType = geometryOutputType; } bool SHADER::Link() { // Shader linking glLinkProgram( programNumber ); ProgramInfo( programNumber ); // Check the Link state glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked ); #ifdef __WXDEBUG__ if( !isShaderLinked ) { int maxLength; glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength ); maxLength = maxLength + 1; char *linkInfoLog = new char[maxLength]; glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog ); std::cerr << "Shader linking error:" << std::endl; std::cerr << linkInfoLog; delete[] linkInfoLog; } #endif /* __WXDEBUG__ */ return isShaderLinked; } void SHADER::AddParameter( const std::string& aParameterName ) { GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() ); if( location != -1 ) { parameterLocation.push_back( location ); } } void SHADER::SetParameter( int parameterNumber, float value ) { glUniform1f( parameterLocation[parameterNumber], value ); } int SHADER::GetAttribute( std::string aAttributeName ) const { return glGetAttribLocation( programNumber, aAttributeName.c_str() ); } Loading
common/CMakeLists.txt +15 −0 Original line number Original line Diff line number Diff line Loading @@ -12,6 +12,20 @@ include_directories( ) ) if(KICAD_GAL) if(KICAD_GAL) # Generate files containing shader programs add_custom_command ( OUTPUT gal/opengl/shader_src.h DEPENDS gal/opengl/make_shader_src_h.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/common/gal/opengl COMMAND ${SHELL} ARGS ${PROJECT_SOURCE_DIR}/common/gal/opengl/make_shader_src_h.sh ) add_custom_target ( ShaderHeader ALL DEPENDS gal/opengl/shader_src.h ) set(GAL_SRCS set(GAL_SRCS drawpanel_gal.cpp drawpanel_gal.cpp painter.cpp painter.cpp Loading @@ -27,6 +41,7 @@ set(GAL_SRCS ) ) add_library(gal STATIC ${GAL_SRCS}) add_library(gal STATIC ${GAL_SRCS}) add_dependencies(gal ShaderHeader) if(WIN32) if(WIN32) add_definitions(-DGLEW_STATIC) add_definitions(-DGLEW_STATIC) Loading
common/drawpanel_gal.cpp +0 −7 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ #include <wx/window.h> #include <wx/window.h> #include <wx/event.h> #include <wx/event.h> #include <wx/colour.h> #include <wx/colour.h> #include <wx/stdpaths.h> #include <wx/filename.h> #include <wx/filename.h> #include <class_drawpanel_gal.h> #include <class_drawpanel_gal.h> Loading Loading @@ -56,11 +55,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view = NULL; m_view = NULL; m_painter = NULL; m_painter = NULL; wxStandardPaths paths; wxFileName executableFile( paths.GetExecutablePath() ); m_galShaderPath = std::string( ( executableFile.GetPath() + wxT( "/../../common/gal/opengl" ) ).mb_str() ); SwitchBackend( aGalType, true ); SwitchBackend( aGalType, true ); SetBackgroundStyle( wxBG_STYLE_CUSTOM ); SetBackgroundStyle( wxBG_STYLE_CUSTOM ); Loading Loading @@ -170,7 +164,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) { { case GAL_TYPE_OPENGL: case GAL_TYPE_OPENGL: m_gal = new KiGfx::OPENGL_GAL( this, this, this, aUseShaders ); m_gal = new KiGfx::OPENGL_GAL( this, this, this, aUseShaders ); static_cast<KiGfx::OPENGL_GAL*> (m_gal)->SetShaderPath( m_galShaderPath ); break; break; case GAL_TYPE_CAIRO: case GAL_TYPE_CAIRO: Loading
common/gal/opengl/make_shader_src_h.sh 0 → 100755 +39 −0 Original line number Original line Diff line number Diff line #!/bin/bash # Make a header file containing GLSL source code echo "Generating headers containing GLSL source code.." # Source files to be included SHADER_SRC=( "shader.vert" "shader.frag" ) # Number of shaders SHADERS_NUMBER=${#SHADER_SRC[@]} OUTPUT="shader_src.h" # Prepare GLSL source to be included in C array function processSrc { # 1st part: remove /* */ comments # 2nd part: remove // comments # 3rd part: remove blank lines (or containing only whitespaces) # 4th & 5th part: wrap every line in quotation marks sed '/\/\*/,/\*\//d; s/[ \t]*\/\/.*$//; /^[ \t]*$/d; s/^[ \t]*/"/; s/[ \t]*$/\\n"/' $1 >> $OUTPUT echo "," >> $OUTPUT } # Header echo "#ifndef SHADER_SRC_H #define SHADER_SRC_H const unsigned int shaders_number = $SHADERS_NUMBER; const char *shaders_src[] = {" > $OUTPUT # Main contents for filename in "${SHADER_SRC[@]}" do processSrc $filename done # Footer echo "}; #endif /* SHADER_SRC_H */" >> $OUTPUT echo "Done."
common/gal/opengl/opengl_gal.cpp +2 −3 Original line number Original line Diff line number Diff line Loading @@ -74,7 +74,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, isUseShader = isUseShaders; isUseShader = isUseShaders; isShaderInitialized = false; isShaderInitialized = false; isGrouping = false; isGrouping = false; shaderPath = "../../common/gal/opengl"; wxSize parentSize = aParent->GetSize(); wxSize parentSize = aParent->GetSize(); isVboInitialized = false; isVboInitialized = false; Loading Loading @@ -359,12 +358,12 @@ void OPENGL_GAL::BeginDrawing() // Compile the shaders // Compile the shaders if( !isShaderInitialized && isUseShader ) if( !isShaderInitialized && isUseShader ) { { if( !shader.AddSource( shaderPath + std::string( "/shader.vert" ), SHADER_TYPE_VERTEX ) ) if( !shader.LoadBuiltinShader( 0, SHADER_TYPE_VERTEX ) ) { { wxLogFatalError( wxT( "Cannot compile vertex shader!" ) ); wxLogFatalError( wxT( "Cannot compile vertex shader!" ) ); } } if( !shader.AddSource( shaderPath + std::string( "/shader.frag" ), SHADER_TYPE_FRAGMENT ) ) if( !shader.LoadBuiltinShader( 1, SHADER_TYPE_FRAGMENT ) ) { { wxLogFatalError( wxT( "Cannot compile fragment shader!" ) ); wxLogFatalError( wxT( "Cannot compile fragment shader!" ) ); } } Loading
common/gal/opengl/shader.cpp +91 −74 Original line number Original line Diff line number Diff line Loading @@ -32,14 +32,15 @@ #include <wx/log.h> #include <wx/log.h> #include <gal/opengl/shader.h> #include <gal/opengl/shader.h> #include "shader_src.h" using namespace KiGfx; using namespace KiGfx; SHADER::SHADER() : SHADER::SHADER() : isProgramCreated( false ), isProgramCreated( false ), isShaderLinked( false ), isShaderLinked( false ), maximumVertices( 4 ), active( false ), active( false ), maximumVertices( 4 ), geomInputType( GL_LINES ), geomInputType( GL_LINES ), geomOutputType( GL_LINES ) geomOutputType( GL_LINES ) { { Loading @@ -62,7 +63,84 @@ SHADER::~SHADER() } } void SHADER::ProgramInfo( GLuint aProgram ) bool SHADER::LoadBuiltinShader( unsigned int aShaderNumber, ShaderType aShaderType ) { if( aShaderNumber >= shaders_number ) return false; return addSource( std::string( shaders_src[aShaderNumber] ), aShaderType ); } bool SHADER::LoadShaderFromFile( const std::string& aShaderSourceName, ShaderType aShaderType ) { // Load shader sources const std::string shaderSource = readSource( aShaderSourceName ); return addSource( shaderSource, aShaderType ); } void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType ) { maximumVertices = maxVertices; geomInputType = geometryInputType; geomOutputType = geometryOutputType; } bool SHADER::Link() { // Shader linking glLinkProgram( programNumber ); programInfo( programNumber ); // Check the Link state glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked ); #ifdef __WXDEBUG__ if( !isShaderLinked ) { int maxLength; glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength ); maxLength = maxLength + 1; char *linkInfoLog = new char[maxLength]; glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog ); std::cerr << "Shader linking error:" << std::endl; std::cerr << linkInfoLog; delete[] linkInfoLog; } #endif /* __WXDEBUG__ */ return isShaderLinked; } void SHADER::AddParameter( const std::string& aParameterName ) { GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() ); if( location != -1 ) { parameterLocation.push_back( location ); } } void SHADER::SetParameter( int parameterNumber, float value ) { glUniform1f( parameterLocation[parameterNumber], value ); } int SHADER::GetAttribute( std::string aAttributeName ) const { return glGetAttribLocation( programNumber, aAttributeName.c_str() ); } void SHADER::programInfo( GLuint aProgram ) { { GLint glInfoLogLength = 0; GLint glInfoLogLength = 0; GLint writtenChars = 0; GLint writtenChars = 0; Loading @@ -83,7 +161,7 @@ void SHADER::ProgramInfo( GLuint aProgram ) } } void SHADER::ShaderInfo( GLuint aShader ) void SHADER::shaderInfo( GLuint aShader ) { { GLint glInfoLogLength = 0; GLint glInfoLogLength = 0; GLint writtenChars = 0; GLint writtenChars = 0; Loading @@ -104,7 +182,7 @@ void SHADER::ShaderInfo( GLuint aShader ) } } std::string SHADER::ReadSource( std::string aShaderSourceName ) std::string SHADER::readSource( std::string aShaderSourceName ) { { // Open the shader source for reading // Open the shader source for reading std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in ); std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in ); Loading @@ -130,7 +208,7 @@ std::string SHADER::ReadSource( std::string aShaderSourceName ) } } bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShaderType ) bool SHADER::addSource( const std::string& aShaderSource, ShaderType aShaderType ) { { if( isShaderLinked ) if( isShaderLinked ) { { Loading @@ -144,24 +222,21 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader isProgramCreated = true; isProgramCreated = true; } } // Load shader sources std::string shaderSource = ReadSource( aShaderSourceName ); // Create a shader // Create a shader GLuint shaderNumber = glCreateShader( aShaderType ); GLuint shaderNumber = glCreateShader( aShaderType ); shaderNumbers.push_back( shaderNumber ); shaderNumbers.push_back( shaderNumber ); // Get the program info // Get the program info ProgramInfo( programNumber ); programInfo( programNumber ); // Copy to char array // Copy to char array char* source = new char[shaderSource.size() + 1]; char* source = new char[aShaderSource.size() + 1]; strcpy( source, shaderSource.c_str() ); strcpy( source, aShaderSource.c_str() ); const char** source_ = (const char**) ( &source ); const char** source_ = (const char**) ( &source ); // Attach the source // Attach the source glShaderSource( shaderNumber, 1, source_, NULL ); glShaderSource( shaderNumber, 1, source_, NULL ); ProgramInfo( programNumber ); programInfo( programNumber ); // Compile and attach shader to the program // Compile and attach shader to the program glCompileShader( shaderNumber ); glCompileShader( shaderNumber ); Loading @@ -171,13 +246,13 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader { { wxLogError( wxT( "Shader compilation error" ) ); wxLogError( wxT( "Shader compilation error" ) ); ShaderInfo( shaderNumber ); shaderInfo( shaderNumber ); return false; return false; } } glAttachShader( programNumber, shaderNumber ); glAttachShader( programNumber, shaderNumber ); ProgramInfo( programNumber ); programInfo( programNumber ); // Special handling for the geometry shader // Special handling for the geometry shader if( aShaderType == SHADER_TYPE_GEOMETRY ) if( aShaderType == SHADER_TYPE_GEOMETRY ) Loading @@ -193,61 +268,3 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader return true; return true; } } void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType ) { maximumVertices = maxVertices; geomInputType = geometryInputType; geomOutputType = geometryOutputType; } bool SHADER::Link() { // Shader linking glLinkProgram( programNumber ); ProgramInfo( programNumber ); // Check the Link state glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked ); #ifdef __WXDEBUG__ if( !isShaderLinked ) { int maxLength; glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength ); maxLength = maxLength + 1; char *linkInfoLog = new char[maxLength]; glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog ); std::cerr << "Shader linking error:" << std::endl; std::cerr << linkInfoLog; delete[] linkInfoLog; } #endif /* __WXDEBUG__ */ return isShaderLinked; } void SHADER::AddParameter( const std::string& aParameterName ) { GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() ); if( location != -1 ) { parameterLocation.push_back( location ); } } void SHADER::SetParameter( int parameterNumber, float value ) { glUniform1f( parameterLocation[parameterNumber], value ); } int SHADER::GetAttribute( std::string aAttributeName ) const { return glGetAttribLocation( programNumber, aAttributeName.c_str() ); }