CSCI441 OpenGL Library 5.9.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 <cstdlib>
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
65 [[maybe_unused]] void useProgramStages( GLbitfield programStages, const ShaderProgram *shaderProgram ) const;
66
72 [[maybe_unused]] void useProgramStages( const ShaderProgram *shaderProgram ) const;
73
78 [[maybe_unused]] void bindPipeline() const;
79
83 [[maybe_unused]] void printPipelineInfo() const;
84
89 [[maybe_unused]] [[nodiscard]] bool validatePipeline() const;
90
91 private:
92 static bool sDEBUG;
93
94 GLuint _pipelineHandle;
95 };
96}
97
99
100inline bool CSCI441::ShaderProgramPipeline::sDEBUG = true;
101
102[[maybe_unused]]
104 sDEBUG = true;
105}
106
107[[maybe_unused]]
109 sDEBUG = false;
110}
111
113 glGenProgramPipelines(1,& _pipelineHandle);
114}
115
117 glDeleteProgramPipelines(1, &_pipelineHandle);
118}
119
120[[maybe_unused]]
121inline void CSCI441::ShaderProgramPipeline::useProgramStages( const GLbitfield programStages, const ShaderProgram * const shaderProgram ) const {
122 glUseProgramStages( _pipelineHandle, programStages, shaderProgram->getShaderProgramHandle() );
123}
124
125[[maybe_unused]]
126inline void CSCI441::ShaderProgramPipeline::useProgramStages( const ShaderProgram * const shaderProgram ) const {
127 glUseProgramStages( _pipelineHandle, shaderProgram->getProgramStages(), shaderProgram->getShaderProgramHandle() );
128}
129
130[[maybe_unused]]
132 glUseProgram(0); // un-use any existing program that may have previously been used. programs override pipelines
133 glBindProgramPipeline( _pipelineHandle );
134}
135
136[[maybe_unused]]
138 if( sDEBUG ) {
139 printf( "\n[INFO]: /--------------------------------------------------------\\\n");
140 printf( "[INFO]: | Program Pipeline: |\n");
141 printf( "[INFO]: | Pipeline Handle: %4u %32c\n", _pipelineHandle, '|' );
142
143 CSCI441_INTERNAL::ShaderUtils::printProgramPipelineLog(_pipelineHandle);
144
145 printf( "[INFO]: >--------------------------------------------------------<\n");
146
147 GLint vs, tcs, tes, gs, fs;
148 glGetProgramPipelineiv( _pipelineHandle, GL_VERTEX_SHADER, &vs );
149 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_CONTROL_SHADER, &tcs );
150 glGetProgramPipelineiv( _pipelineHandle, GL_TESS_EVALUATION_SHADER, &tes );
151 glGetProgramPipelineiv( _pipelineHandle, GL_GEOMETRY_SHADER, &gs );
152 glGetProgramPipelineiv( _pipelineHandle, GL_FRAGMENT_SHADER, &fs );
153
154 if( vs != 0 ) printf( "[INFO]: | Vertex Shader Program Handle: %2d |\n", vs );
155 if( tcs != 0 ) printf( "[INFO]: | Tess Ctrl Shader Program Handle: %2d |\n", tcs );
156 if( tes != 0 ) printf( "[INFO]: | Tess Eval Shader Program Handle: %2d |\n", tes );
157 if( gs != 0 ) printf( "[INFO]: | Geometry Shader Program Handle: %2d |\n", gs );
158 if( fs != 0 ) printf( "[INFO]: | Fragment Shader Program Handle: %2d |\n", fs );
159
160 printf( "[INFO]: \\--------------------------------------------------------/\n");
161 printf( "\n");
162 }
163}
164
165[[maybe_unused]]
167 glValidateProgramPipeline(_pipelineHandle);
168 GLint validateStatus;
169 glGetProgramPipelineiv(_pipelineHandle, GL_VALIDATE_STATUS, &validateStatus);
170 return (validateStatus == GL_TRUE);
171}
172
173#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:1999
virtual GLuint getShaderProgramHandle() const final
Returns the handle for this shader program.
Definition: ShaderProgram.hpp:1417
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:121
ShaderProgramPipeline()
creates a shader program pipeline by generating a shader program pipeline handle
Definition: ShaderProgramPipeline.hpp:112
static void enableDebugMessages()
Enables debug messages from Shader Program functions.
Definition: ShaderProgramPipeline.hpp:103
bool validatePipeline() const
Definition: ShaderProgramPipeline.hpp:166
void bindPipeline() const
bind shader program pipeline
Definition: ShaderProgramPipeline.hpp:131
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:116
static void disableDebugMessages()
Disables debug messages from Shader Program functions.
Definition: ShaderProgramPipeline.hpp:108
void printPipelineInfo() const
prints shader program pipeline information to console
Definition: ShaderProgramPipeline.hpp:137
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17