public static Shader GetShader(string shaderName, TackShaderType shaderType) { if (shaderName == "shaders.default_world_shader") { return(ActiveInstance.m_defaultWorldShader); } if (shaderName == "shaders.default_gui_shader") { return(ActiveInstance.m_defaultGUIShader); } for (int i = 0; i < ActiveInstance.m_loadedShaders.Count; i++) { if (ActiveInstance.m_loadedShaders[i].Name == shaderName && ActiveInstance.m_loadedShaders[i].Type == shaderType) { return(ActiveInstance.m_loadedShaders[i]); } } if (shaderType == TackShaderType.GUI) { return(ActiveInstance.m_defaultGUIShader); } else { return(ActiveInstance.m_defaultWorldShader); } }
public Shader(string shaderName, TackShaderType type, string vertexSoure, string fragmentSource) { Name = shaderName; Type = type; TackConsole.EngineLog(Engine.EngineLogType.Message, "Starting compilation and linking of shader with name: " + Name); // Create shader program int shaderProgram = GL.CreateProgram(); // Generate subshader ids int vertShaderId = CompileSubShader(vertexSoure, ShaderType.VertexShader); int fragShaderId = CompileSubShader(fragmentSource, ShaderType.FragmentShader); if (vertShaderId == -1 || fragShaderId == -1) { CompiledAndLinked = false; Id = -1; return; } // Link shaders to the shader program GL.AttachShader(shaderProgram, vertShaderId); GL.AttachShader(shaderProgram, fragShaderId); GL.LinkProgram(shaderProgram); GL.GetProgramInfoLog(shaderProgram, out string progLogStr); if (progLogStr != "") { TackConsole.EngineLog(Engine.EngineLogType.Error, progLogStr); Id = -1; CompiledAndLinked = false; return; } Uniforms = GetShaderUniformVars(); TackConsole.EngineLog(Engine.EngineLogType.Message, "Successfully created shader program with Id: {0}. Name: \"{1}\". SupportsBatchRendering: {2}", Id, Name, SupportsBatchRendering); GL.DeleteShader(vertShaderId); GL.DeleteShader(fragShaderId); Id = shaderProgram; CompiledAndLinked = true; }