JeVoisBase  1.5
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
GPUprogram.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
19 
20 // ####################################################################################################
21 GPUprogram::GPUprogram(char const * vertex_shader, char const * fragment_shader)
22 {
23  itsVertexShader.load(vertex_shader, GL_VERTEX_SHADER);
24  itsFragmentShader.load(fragment_shader, GL_FRAGMENT_SHADER);
25  itsId = glCreateProgram();
26  GL_CHECK(glAttachShader(itsId, itsVertexShader.id()));
27  GL_CHECK(glAttachShader(itsId, itsFragmentShader.id()));
28  GL_CHECK(glLinkProgram(itsId));
29 
30  LINFO("GPU program created using vshader=" << vertex_shader << " and fshader=" << fragment_shader);
31 
32  /*
33  // Prints the information log for a program object
34  char log[1024];
35  glGetProgramInfoLog(Id,sizeof log,NULL,log);
36  printf("%d:program:\n%s\n", Id, log);
37  */
38 }
39 
40 // ####################################################################################################
42 {
43  // Disable the program:
44  glUseProgram(0);
45 
46  // Nuke it:
47  glDetachShader(itsId, itsVertexShader.id());
48  glDetachShader(itsId, itsFragmentShader.id());
49  glDeleteProgram(itsId);
50 }
51 
52 // ####################################################################################################
53 GLuint GPUprogram::id() const
54 { return itsId; }
~GPUprogram()
Destructor, deletes the program from OpenGL and frees up the ID.
Definition: GPUprogram.C:41
GLuint id() const
Get the shader&#39;s ID.
Definition: GPUshader.C:33
GLuint id() const
Get the program ID so we can tell OpenGL to use this program.
Definition: GPUprogram.C:53
void load(char const *filename, GLuint type)
Load a shader from file.
Definition: GPUshader.C:37
#define LINFO(msg)
GPUprogram(char const *vertex_shader, char const *fragment_shader)
Constructor, loads and compiles the program, assigns it a program ID.
Definition: GPUprogram.C:21
#define GL_CHECK(stmt)
Simple macro to check for OpenGL errors.
Definition: OpenGL.H:49