CSCI441 OpenGL Library 5.13.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 "ShaderProgram.hpp"
15
16#include <cstdio>
17
19
20namespace CSCI441 {
21
26 class [[maybe_unused]] ShaderProgramPipeline final {
27 public:
32 [[maybe_unused]] static void enableDebugMessages();
37 [[maybe_unused]] static void disableDebugMessages();
38
49
58
67 ShaderProgramPipeline& operator=(ShaderProgramPipeline&&) noexcept;
68
75 [[maybe_unused]] void useProgramStages( GLbitfield programStages, const ShaderProgram *shaderProgram ) const;
76
82 [[maybe_unused]] void useProgramStages( const ShaderProgram *shaderProgram ) const;
83
88 [[maybe_unused]] void bindPipeline() const;
89
93 [[maybe_unused]] void printPipelineInfo() const;
94
99 [[maybe_unused]] [[nodiscard]] bool validatePipeline() const;
100
101 private:
102 static bool sDEBUG;
103
104 GLuint _pipelineHandle;
105 };
106}
107
109
110inline bool CSCI441::ShaderProgramPipeline::sDEBUG = true;
111
112[[maybe_unused]]
113inline void CSCI441::ShaderProgramPipeline::enableDebugMessages() {
114 sDEBUG = true;
115}
116
117[[maybe_unused]]
119 sDEBUG = false;
120}
121
123 glGenProgramPipelines(1,& _pipelineHandle);
124}
125
127 glDeleteProgramPipelines(1, &_pipelineHandle);
128}
129
131 _pipelineHandle = src._pipelineHandle;
132 src._pipelineHandle = 0;
133}
134
136 // guard against self movement
137 if (this != &src) {
138 // delete our existing pipeline
139 glDeleteProgramPipelines(1, &_pipelineHandle);
140 // move the source pipeline
141 _pipelineHandle = src._pipelineHandle;
142 src._pipelineHandle = 0;
143 }
144 // return ourselves
145 return *this;
146}
147
148
149[[maybe_unused]]
150inline void CSCI441::ShaderProgramPipeline::useProgramStages( const GLbitfield programStages, const ShaderProgram * const shaderProgram ) const {
151 glUseProgramStages( _pipelineHandle, programStages, shaderProgram->getShaderProgramHandle() );
152}
153
154[[maybe_unused]]
155inline void CSCI441::ShaderProgramPipeline::useProgramStages( const ShaderProgram * const shaderProgram ) const {
156 glUseProgramStages( _pipelineHandle, shaderProgram->getProgramStages(), shaderProgram->getShaderProgramHandle() );
157}
158
159[[maybe_unused]]
161 glUseProgram(0); // un-use any existing program that may have previously been used. programs override pipelines
162 glBindProgramPipeline( _pipelineHandle );
163}
164
165[[maybe_unused]]
167 if( sDEBUG ) {
168 printf( "\n[INFO]: /--------------------------------------------------------\\\n");
169 printf( "[INFO]: | Program Pipeline: |\n");
170 printf( "[INFO]: | Pipeline Handle: %4u %32c\n", _pipelineHandle, '|' );
171
172 CSCI441_INTERNAL::ShaderUtils::printProgramPipelineLog(_pipelineHandle);
173
174 printf( "[INFO]: >--------------------------------------------------------<\n");
175
176 GLint vs, tcs, tes, gs, fs;
177 glGetProgramPipelineiv( _pipelineHandle, GL_VERTEX_SHADER, &vs );
178 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_CONTROL_SHADER, &tcs );
179 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_EVALUATION_SHADER, &tes );
180 glGetProgramPipelineiv( _pipelineHandle, GL_GEOMETRY_SHADER, &gs );
181 glGetProgramPipelineiv( _pipelineHandle, GL_FRAGMENT_SHADER, &fs );
182
183 if( vs != 0 ) printf( "[INFO]: | Vertex Shader Program Handle: %2d |\n", vs );
184 if( tcs != 0 ) printf( "[INFO]: | Tess Ctrl Shader Program Handle: %2d |\n", tcs );
185 if( tes != 0 ) printf( "[INFO]: | Tess Eval Shader Program Handle: %2d |\n", tes );
186 if( gs != 0 ) printf( "[INFO]: | Geometry Shader Program Handle: %2d |\n", gs );
187 if( fs != 0 ) printf( "[INFO]: | Fragment Shader Program Handle: %2d |\n", fs );
188
189 printf( "[INFO]: \\--------------------------------------------------------/\n");
190 printf( "\n");
191 }
192}
193
194[[maybe_unused]]
196 glValidateProgramPipeline(_pipelineHandle);
197 GLint validateStatus;
198 glGetProgramPipelineiv(_pipelineHandle, GL_VALIDATE_STATUS, &validateStatus);
199 return (validateStatus == GL_TRUE);
200}
201
202#endif// CSCI441_SHADER_PROGRAM_PIPELINE_HPP
Class to work with OpenGL 4.0+ Shaders.
Handles registration and compilation of Shaders.
Definition: ShaderProgram.hpp:35
virtual GLbitfield getProgramStages() const final
returns a single value corresponding to which shader stages are present in this shader program
Definition: ShaderProgram.hpp:2077
virtual GLuint getShaderProgramHandle() const final
Returns the handle for this shader program.
Definition: ShaderProgram.hpp:1495
Handles registration and compilation of Shader Program Pipelines.
Definition: ShaderProgramPipeline.hpp:26
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:150
ShaderProgramPipeline()
creates a shader program pipeline by generating a shader program pipeline handle
Definition: ShaderProgramPipeline.hpp:122
bool validatePipeline() const
Definition: ShaderProgramPipeline.hpp:195
void bindPipeline() const
bind shader program pipeline
Definition: ShaderProgramPipeline.hpp:160
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:126
static void disableDebugMessages()
Disables debug messages from Shader Program functions.
Definition: ShaderProgramPipeline.hpp:118
void printPipelineInfo() const
prints shader program pipeline information to console
Definition: ShaderProgramPipeline.hpp:166
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17