Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 25th, 2013  |  syntax: C++  |  size: 1.36 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //HEADER FILE
  2. #ifndef CS5400_PROGRAM
  3. #define CS5400_PROGRAM
  4.  
  5. #include <memory>
  6.  
  7. #include "Shader.hpp"
  8.  
  9. namespace cs5400
  10. {
  11.   class Program
  12.   {
  13.   public:
  14.     Program(
  15.       std::shared_ptr<VertexShader> vertex_
  16.      ,std::shared_ptr<FragmentShader> fragment_)
  17.     :handle(glCreateProgram())
  18.     ,vertex(vertex_)
  19.     ,fragment(fragment_)
  20.     {}
  21.     GLuint getHandle(){return handle;}
  22.     ~Program()
  23.     {
  24.       //glDeleteProgram(handle);
  25.     }
  26.   private:
  27.     GLuint handle;
  28.     std::shared_ptr<VertexShader> vertex;
  29.     std::shared_ptr<FragmentShader> fragment;
  30.   };
  31.  
  32.   std::shared_ptr<Program> make_program(std::shared_ptr<VertexShader> vertex,std::shared_ptr<FragmentShader> fragment);
  33. }
  34.  
  35. #endif
  36.  
  37.  
  38. //SOURCE FILE
  39.  
  40. #include "Program.hpp"
  41.  
  42.  
  43. std::shared_ptr<cs5400::Program> cs5400::make_program
  44. (
  45.   std::shared_ptr<cs5400::VertexShader> vertex
  46.  ,std::shared_ptr<cs5400::FragmentShader> fragment  
  47. )
  48. {
  49.   GLint link_ok = GL_FALSE;
  50.   auto program = std::make_shared<Program>(vertex,fragment);
  51.   glAttachShader(program->getHandle(), vertex->getHandle());
  52.   glAttachShader(program->getHandle(), fragment->getHandle());
  53.   glLinkProgram(program->getHandle());
  54.   glGetProgramiv(program->getHandle(), GL_LINK_STATUS, &link_ok);
  55.   if (!link_ok)
  56.   {
  57.     throw std::runtime_error("Could not link shader program.");
  58.   }
  59.   return program;
  60. }
clone this paste RAW Paste Data