Sfoglia il codice sorgente

geom shader support

Former-commit-id: a41b0ccee16252c0601714bd780543a76a3d45b8
Alec Jacobson 10 anni fa
parent
commit
85054318e4

+ 35 - 0
include/igl/create_shader_program.cpp

@@ -14,6 +14,7 @@
 #include <cstdio>
 
 IGL_INLINE bool igl::create_shader_program(
+  const std::string & geom_source,
   const std::string & vert_source,
   const std::string & frag_source,
   const std::map<std::string,GLuint> & attrib,
@@ -36,6 +37,18 @@ IGL_INLINE bool igl::create_shader_program(
     return false;
   }
 
+  if(geom_source != "")
+  {
+    // load vertex shader
+    GLuint g = igl::load_shader(geom_source.c_str(),GL_GEOMETRY_SHADER_EXT);
+    if(g == 0)
+    {
+      cerr<<"geometry shader failed to compile."<<endl;
+      return false;
+    }
+    glAttachShader(id,g);
+  }
+
   if(vert_source != "")
   {
     // load vertex shader
@@ -80,6 +93,27 @@ IGL_INLINE bool igl::create_shader_program(
   return true;
 }
 
+IGL_INLINE bool igl::create_shader_program(
+  const std::string & vert_source,
+  const std::string & frag_source,
+  const std::map<std::string,GLuint> & attrib,
+  GLuint & prog_id)
+{
+  return create_shader_program("",vert_source,frag_source,attrib,prog_id);
+}
+
+
+IGL_INLINE GLuint igl::create_shader_program(
+  const std::string & geom_source,
+  const std::string & vert_source,
+  const std::string & frag_source,
+  const std::map<std::string,GLuint> & attrib)
+{
+  GLuint prog_id = 0;
+  create_shader_program(geom_source,vert_source,frag_source,attrib,prog_id);
+  return prog_id;
+}
+
 IGL_INLINE GLuint igl::create_shader_program(
   const std::string & vert_source,
   const std::string & frag_source,
@@ -89,4 +123,5 @@ IGL_INLINE GLuint igl::create_shader_program(
   create_shader_program(vert_source,frag_source,attrib,prog_id);
   return prog_id;
 }
+
 #endif

+ 13 - 0
include/igl/create_shader_program.h

@@ -21,6 +21,8 @@ namespace igl
   // source strings and vertex attributes assigned from a map before linking the
   // shaders to the program, making it ready to use with glUseProgram(id)
   // Inputs:
+  //   geom_source  string containing source code of geometry shader (can be
+  //     "" to mean use default pass-through)
   //   vert_source  string containing source code of vertex shader
   //   frag_source  string containing source code of fragment shader
   //   attrib  map containing table of vertex attribute strings add their
@@ -34,10 +36,21 @@ namespace igl
   //
   // See also: destroy_shader_program
   IGL_INLINE bool create_shader_program(
+    const std::string &geom_source,
     const std::string &vert_source,
     const std::string &frag_source,
     const std::map<std::string,GLuint> &attrib,
     GLuint & id);
+  IGL_INLINE bool create_shader_program(
+    const std::string &vert_source,
+    const std::string &frag_source,
+    const std::map<std::string,GLuint> &attrib,
+    GLuint & id);
+  IGL_INLINE GLuint create_shader_program(
+    const std::string & geom_source,
+    const std::string & vert_source,
+    const std::string & frag_source,
+    const std::map<std::string,GLuint> &attrib);
   IGL_INLINE GLuint create_shader_program(
     const std::string & vert_source,
     const std::string & frag_source,