CSCI441 OpenGL Library 6.1.0.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
ShaderProgramPipeline.hpp
Go to the documentation of this file.
1
11#ifndef CSCI441_SHADER_PROGRAM_PIPELINE_HPP
12#define CSCI441_SHADER_PROGRAM_PIPELINE_HPP
13
14#include "LogUtils.hpp"
15#include "ShaderProgram.hpp"
16
17#include <cstdio>
18
20
21namespace CSCI441 {
22
27 class [[maybe_unused]] ShaderProgramPipeline final {
28 public:
33 [[maybe_unused]] static void enableDebugMessages();
38 [[maybe_unused]] static void disableDebugMessages();
39
50
59
68 ShaderProgramPipeline& operator=(ShaderProgramPipeline&&) noexcept;
69
76 [[maybe_unused]] void useProgramStages( GLbitfield programStages, const ShaderProgram *shaderProgram ) const;
77
83 [[maybe_unused]] void useProgramStages( const ShaderProgram *shaderProgram ) const;
84
89 [[maybe_unused]] void bindPipeline() const;
90
94 [[maybe_unused]] void printPipelineInfo() const;
95
100 [[maybe_unused]] [[nodiscard]] bool validatePipeline() const;
101
102 private:
103 static bool sDEBUG;
104
105 GLuint _pipelineHandle;
106 };
107}
108
110
111inline bool CSCI441::ShaderProgramPipeline::sDEBUG = true;
112
113[[maybe_unused]]
114inline void CSCI441::ShaderProgramPipeline::enableDebugMessages() {
115 sDEBUG = true;
116}
117
118[[maybe_unused]]
120 sDEBUG = false;
121}
122
124 glGenProgramPipelines(1,& _pipelineHandle);
125}
126
128 glDeleteProgramPipelines(1, &_pipelineHandle);
129}
130
132 _pipelineHandle = src._pipelineHandle;
133 src._pipelineHandle = 0;
134}
135
137 // guard against self movement
138 if (this != &src) {
139 // delete our existing pipeline
140 glDeleteProgramPipelines(1, &_pipelineHandle);
141 // move the source pipeline
142 _pipelineHandle = src._pipelineHandle;
143 src._pipelineHandle = 0;
144 }
145 // return ourselves
146 return *this;
147}
148
149
150[[maybe_unused]]
151inline void CSCI441::ShaderProgramPipeline::useProgramStages( const GLbitfield programStages, const ShaderProgram * const shaderProgram ) const {
152 glUseProgramStages( _pipelineHandle, programStages, shaderProgram->getShaderProgramHandle() );
153}
154
155[[maybe_unused]]
156inline void CSCI441::ShaderProgramPipeline::useProgramStages( const ShaderProgram * const shaderProgram ) const {
157 glUseProgramStages( _pipelineHandle, shaderProgram->getProgramStages(), shaderProgram->getShaderProgramHandle() );
158}
159
160[[maybe_unused]]
162 glUseProgram(0); // un-use any existing program that may have previously been used. programs override pipelines
163 glBindProgramPipeline( _pipelineHandle );
164}
165
166[[maybe_unused]]
168 if( sDEBUG ) {
169 CSCI441::LogUtils::log("\n[INFO]: /--------------------------------------------------------\\\n");
170 CSCI441::LogUtils::log("[INFO]: | Program Pipeline: |\n");
171 CSCI441::LogUtils::log("[INFO]: | Pipeline Handle: %4u %32c\n", _pipelineHandle, '|' );
172
173 CSCI441_INTERNAL::ShaderUtils::printProgramPipelineLog(_pipelineHandle);
174
175 CSCI441::LogUtils::log("[INFO]: >--------------------------------------------------------<\n");
176
177 GLint vs, tcs, tes, gs, fs, cs;
178 glGetProgramPipelineiv( _pipelineHandle, GL_VERTEX_SHADER, &vs );
179 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_CONTROL_SHADER, &tcs );
180 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_EVALUATION_SHADER, &tes );
181 glGetProgramPipelineiv( _pipelineHandle, GL_GEOMETRY_SHADER, &gs );
182 glGetProgramPipelineiv( _pipelineHandle, GL_FRAGMENT_SHADER, &fs );
183
184 GLint major, minor;
185 glGetIntegerv(GL_MAJOR_VERSION, &major);
186 glGetIntegerv(GL_MINOR_VERSION, &minor);
187
188 if(major > 4 || (major == 4 && minor >= 3)) {
189 glGetProgramPipelineiv( _pipelineHandle, GL_COMPUTE_SHADER, &cs );
190 }
191
192 if( vs != 0 ) CSCI441::LogUtils::log("[INFO]: | Vertex Shader Program Handle: %2d |\n", vs );
193 if( tcs != 0 ) CSCI441::LogUtils::log("[INFO]: | Tess Ctrl Shader Program Handle: %2d |\n", tcs );
194 if( tes != 0 ) CSCI441::LogUtils::log("[INFO]: | Tess Eval Shader Program Handle: %2d |\n", tes );
195 if( gs != 0 ) CSCI441::LogUtils::log("[INFO]: | Geometry Shader Program Handle: %2d |\n", gs );
196 if( fs != 0 ) CSCI441::LogUtils::log("[INFO]: | Fragment Shader Program Handle: %2d |\n", fs );
197 if(major < 4 || (major == 4 && minor >= 3)) {
198 if( cs != 0 ) CSCI441::LogUtils::log("[INFO]: | Compute Shader Program Handle: %2d |\n", cs );
199 }
200
201 CSCI441::LogUtils::log("[INFO]: \\--------------------------------------------------------/\n");
203 }
204}
205
206[[maybe_unused]]
208 glValidateProgramPipeline(_pipelineHandle);
209 GLint validateStatus;
210 glGetProgramPipelineiv(_pipelineHandle, GL_VALIDATE_STATUS, &validateStatus);
211 return (validateStatus == GL_TRUE);
212}
213
214#endif// CSCI441_SHADER_PROGRAM_PIPELINE_HPP
Class to work with OpenGL 4.0+ Shaders.
Handles registration and compilation of Shaders.
Definition: ShaderProgram.hpp:37
virtual GLbitfield getProgramStages() const
returns a single value corresponding to which shader stages are present in this shader program
Definition: ShaderProgram.hpp:2127
virtual GLuint getShaderProgramHandle() const final
Returns the handle for this shader program.
Definition: ShaderProgram.hpp:1529
Handles registration and compilation of Shader Program Pipelines.
Definition: ShaderProgramPipeline.hpp:27
ShaderProgramPipeline(const ShaderProgramPipeline &)=delete
do not allow shader program pipelines to be copied
void useProgramStages(GLbitfield programStages, const ShaderProgram *shaderProgram) const
adds shader program stages to pipeline
Definition: ShaderProgramPipeline.hpp:151
ShaderProgramPipeline()
creates a shader program pipeline by generating a shader program pipeline handle
Definition: ShaderProgramPipeline.hpp:123
bool validatePipeline() const
Definition: ShaderProgramPipeline.hpp:207
void bindPipeline() const
bind shader program pipeline
Definition: ShaderProgramPipeline.hpp:161
ShaderProgramPipeline & operator=(const ShaderProgramPipeline &)=delete
do not allow shader program pipelines to be copied
~ShaderProgramPipeline()
deletes a shader program pipeline by deleting the shader program pipeline handle
Definition: ShaderProgramPipeline.hpp:127
static void disableDebugMessages()
Disables debug messages from Shader Program functions.
Definition: ShaderProgramPipeline.hpp:119
void printPipelineInfo() const
prints shader program pipeline information to console
Definition: ShaderProgramPipeline.hpp:167
void log(const char *MSG,...)
log a message to both the standard output stream and file
Definition: LogUtils.hpp:116
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17