JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
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// ####################################################################################################
21jevois::GPUprogram::GPUprogram(char const * vertex_shader, char const * fragment_shader)
22{
23 if (vertex_shader[0] == '#') itsVertexShader.set("vertex", vertex_shader, GL_VERTEX_SHADER);
24 else itsVertexShader.load(vertex_shader, GL_VERTEX_SHADER);
25
26 if (fragment_shader[0] == '#') itsFragmentShader.set("fragment", fragment_shader, GL_FRAGMENT_SHADER);
27 else itsFragmentShader.load(fragment_shader, GL_FRAGMENT_SHADER);
28
29 itsId = glCreateProgram();
30 GL_CHECK(glAttachShader(itsId, itsVertexShader.id()));
31 GL_CHECK(glAttachShader(itsId, itsFragmentShader.id()));
32 GL_CHECK(glLinkProgram(itsId));
33
34 LDEBUG("GPU program " << itsId <<" created.");
35
36 /*
37 // Prints the information log for a program object
38 char log[1024];
39 glGetProgramInfoLog(Id,sizeof log,NULL,log);
40 printf("%d:program:\n%s\n", Id, log);
41 */
42}
43
44// ####################################################################################################
46{
47 // Disable the program:
48 glUseProgram(0);
49
50 // Nuke it:
51 glDetachShader(itsId, itsVertexShader.id());
52 glDetachShader(itsId, itsFragmentShader.id());
53 glDeleteProgram(itsId);
54}
55
56// ####################################################################################################
58{ return itsId; }
#define GL_CHECK(stmt)
Simple macro to check for OpenGL errors.
Definition OpenGL.H:77
GPUprogram(char const *vertex_shader, char const *fragment_shader)
Constructor, loads and compiles the program, assigns it a program ID.
Definition GPUprogram.C:21
GLuint id() const
Get the program ID so we can tell OpenGL to use this program.
Definition GPUprogram.C:57
~GPUprogram()
Destructor, deletes the program from OpenGL and frees up the ID.
Definition GPUprogram.C:45
void load(char const *filename, GLuint type)
Load a shader from file.
Definition GPUshader.C:36
void set(char const *name, char const *str, GLuint type)
Load a shader from inlined code in a C-string.
Definition GPUshader.C:57
GLuint id() const
Get the shader's ID.
Definition GPUshader.C:32
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level.
Definition Log.H:173