// ============================================================== // This file is part of Glest Shared Library (www.glest.org) // // Copyright (C) 2001-2008 MartiƱo Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published // by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version // ============================================================== #include "shader_gl.h" #include #include "opengl.h" #include "leak_dumper.h" using namespace std; namespace Shared{ namespace Graphics{ namespace Gl{ // ===================================================== // class ShaderProgramGl // ===================================================== ShaderProgramGl::ShaderProgramGl(){ inited= false; vertexShader=0; fragmentShader=0; handle=0; } void ShaderProgramGl::init(){ if(!inited){ assertGl(); handle= glCreateProgramObjectARB(); assertGl(); inited= true; } } void ShaderProgramGl::end(){ if(inited){ assertGl(); glDeleteObjectARB(handle); assertGl(); inited= false; } } void ShaderProgramGl::attach(VertexShader *vertexShader, FragmentShader *fragmentShader){ this->vertexShader= vertexShader; this->fragmentShader= fragmentShader; } bool ShaderProgramGl::link(string &messages){ assertGl(); VertexShaderGl *vertexShaderGl= static_cast(vertexShader); FragmentShaderGl *fragmentShaderGl= static_cast(fragmentShader); const ShaderSource *vss= vertexShaderGl->getSource(); const ShaderSource *fss= fragmentShaderGl->getSource(); messages= "Linking program: " + vss->getPathInfo() + ", " + fss->getPathInfo() + "\n"; //attach glAttachObjectARB(handle, vertexShaderGl->getHandle()); glAttachObjectARB(handle, fragmentShaderGl->getHandle()); assertGl(); //bind attributes for(unsigned int i=0; i