OGLplus (0.52.0) a C++ wrapper for OpenGL

program_pipeline.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_PROGRAM_PIPELINE_1107121519_HPP
14 #define OGLPLUS_PROGRAM_PIPELINE_1107121519_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/shader_type.hpp>
21 #include <oglplus/detail/prog_pl_stages.hpp>
22 
23 #include <cassert>
24 
25 namespace oglplus {
26 
27 // if program-pipeline is available
28 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_4_1 || GL_ARB_separate_shader_objects
29 
31 
39 template <>
40 class ObjGenDelOps<tag::ProgramPipeline>
41 {
42 protected:
43  static void Gen(tag::Generate, GLsizei count, GLuint* names)
44  {
45  assert(names != nullptr);
46  OGLPLUS_GLFUNC(GenProgramPipelines)(count, names);
47  OGLPLUS_CHECK_SIMPLE(GenProgramPipelines);
48  }
49 
50 #if GL_VERSION_4_5 || GL_ARB_direct_state_access
51  static void Gen(tag::Create, GLsizei count, GLuint* names)
52  {
53  assert(names != nullptr);
54  OGLPLUS_GLFUNC(CreateProgramPipelines)(count, names);
55  OGLPLUS_CHECK_SIMPLE(CreateProgramPipelines);
56  }
57 #endif
58 
59  static void Delete(GLsizei count, GLuint* names)
60  {
61  assert(names != nullptr);
62  OGLPLUS_GLFUNC(DeleteProgramPipelines)(count, names);
63  OGLPLUS_VERIFY_SIMPLE(DeleteProgramPipelines);
64  }
65 
66  static GLboolean IsA(GLuint name)
67  {
68  assert(name != 0);
69  GLboolean result = OGLPLUS_GLFUNC(IsProgramPipeline)(name);
70  OGLPLUS_VERIFY_SIMPLE(IsProgramPipeline);
71  return result;
72  }
73 };
74 
76 template <>
77 class ObjBindingOps<tag::ProgramPipeline>
78 {
79 protected:
80  static GLuint _binding(void)
81  {
82  GLint name = 0;
83  OGLPLUS_GLFUNC(GetIntegerv)(GL_PROGRAM_PIPELINE_BINDING, &name);
84  OGLPLUS_VERIFY(
85  GetIntegerv,
86  Error,
87  EnumParam(GLenum(GL_PROGRAM_PIPELINE_BINDING))
88  );
89  return name;
90  }
91 public:
93 
98  {
99  return ProgramPipelineName(_binding());
100  }
101 
103 
107  static void Bind(ProgramPipelineName pipeline)
108  {
109  OGLPLUS_GLFUNC(BindProgramPipeline)(GetGLName(pipeline));
110  OGLPLUS_VERIFY(
111  BindProgramPipeline,
112  ObjectError,
113  Object(pipeline)
114  );
115  }
116 };
117 
119 
122 template <>
124  : public ProgramPipelineName
125  , public ObjBindingOps<tag::ProgramPipeline>
126 {
127 protected:
128  ObjCommonOps(void){ }
129 public:
131 
133 
137  void Bind(void) const
138  {
139  Bind(*this);
140  }
141 };
142 
144 
146 template <>
147 class ObjectOps<tag::DirectState, tag::ProgramPipeline>
148  : public ObjZeroOps<tag::DirectState, tag::ProgramPipeline>
149 {
150 protected:
151  ObjectOps(void){ }
152 public:
154  struct Properties
155  {
158  };
159 
160  GLint GetIntParam(GLenum query) const
161  {
162  GLint result;
163  OGLPLUS_GLFUNC(GetProgramPipelineiv)(_name, query, &result);
164  OGLPLUS_VERIFY(
165  GetProgramPipelineiv,
166  ObjectError,
167  Object(*this).
168  EnumParam(query)
169  );
170  return result;
171  }
172 
174 
197  ProgPLUseStages UseStages(ProgramName program) const
198  {
199  assert(_name != 0);
200  return ProgPLUseStages(
201  _name,
202  GetGLName(program),
203  0
204  );
205  }
206 
208 
212  void UseStages(
214  ProgramName program
215  ) const
216  {
217  assert(_name != 0);
218  OGLPLUS_GLFUNC(UseProgramStages)(
219  _name,
220  GLbitfield(stages),
221  GetGLName(program)
222  );
223  OGLPLUS_CHECK(
224  UseProgramStages,
225  ObjectError,
226  Object(*this)
227  );
228  }
229 
230 #if defined GL_ALL_SHADER_BITS
231 
236  void UseAllStages(ProgramName program) const
237  {
238  assert(_name != 0);
239  OGLPLUS_GLFUNC(UseProgramStages)(
240  _name,
241  GL_ALL_SHADER_BITS,
242  GetGLName(program)
243  );
244  OGLPLUS_VERIFY(
245  UseProgramStages,
246  ObjectError,
247  Object(*this)
248  );
249  }
250 #endif
251 
253 
258  String GetInfoLog(void) const;
259 
261 
267  bool IsValid(void) const
268  {
269  return GetIntParam(GL_VALIDATE_STATUS) == GL_TRUE;
270  }
271 
273 
280  void Validate(void) const;
281 
283 
287  void ActiveShaderProgram(ProgramName program) const
288  {
289  assert(_name != 0);
290  OGLPLUS_GLFUNC(ActiveShaderProgram)(
291  _name,
292  GetGLName(program)
293  );
294  OGLPLUS_CHECK(
295  ActiveShaderProgram,
296  ObjectError,
297  Object(*this)
298  );
299  }
300 
302 
308  {
309  return ProgramName(GetIntParam(GL_ACTIVE_PROGRAM));
310  }
311 
313 
317  bool HasShader(ShaderType shader_type) const
318  {
319  return GetIntParam(GLenum(shader_type)) != 0;
320  }
321 
323 
328  {
329  return ProgramName(GetIntParam(GLenum(shader_type)));
330  }
331 };
332 
334 typedef ObjectOps<tag::DirectState, tag::ProgramPipeline>
336 
338 
341 typedef ObjectZero<ObjZeroOps<tag::DirectState, tag::ProgramPipeline>>
343 
345 
348 typedef Object<ProgramPipelineOps> ProgramPipeline;
349 
350 #endif // program pipeline
351 
352 } // namespace oglplus
353 
354 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
355 #include <oglplus/program_pipeline.ipp>
356 #endif // OGLPLUS_LINK_LIBRARY
357 
358 #endif // include guard
ProgramPipelineStage Stage
The stage of a ProgramPipeline.
Definition: program_pipeline.hpp:157
ShaderType
The type of a Shader.
Definition: shader_type.hpp:26
ProgramName ActiveShaderProgram(void) const
Returns the current active shader program.
Definition: program_pipeline.hpp:307
ProgramPipelineStage enumeration.
Shader type enumeration.
Program errors.
Generic OpenGL object wrapper.
This template serves as a wrapper for OpenGL bitfields.
Definition: bitfield.hpp:56
::std::basic_string< ALchar > String
static ProgramPipelineName Binding(void)
Returns the currently bound ProgramPipeline.
Definition: program_pipeline.hpp:97
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
static void Bind(ProgramPipelineName pipeline)
Binds the specified vertex_array object.
Definition: program_pipeline.hpp:107
ProgPLUseStages UseStages(ProgramName program) const
Specifies program stages by calling functions of the returned object.
Definition: program_pipeline.hpp:197
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
Object< ProgramPipelineOps > ProgramPipeline
An oglplus_object encapsulating the OpenGL program pipeline functionality.
Definition: program_pipeline.hpp:348
ObjectZero< ObjZeroOps< tag::DirectState, tag::ProgramPipeline > > NoProgramPipeline
Class that can be used to unbind the currently bound program pipeline.
Definition: program_pipeline.hpp:342
Helper macro for optional checking of availability of GL function.
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
bool HasShader(ShaderType shader_type) const
Returns true if this pipeline contains a shader of a particular type.
Definition: program_pipeline.hpp:317
bool IsValid(void) const
Returns true if the pipeline is validated, false otherwise.
Definition: program_pipeline.hpp:267
ProgramPipelineStage
Program pipeline stage enumeration.
Definition: program_pipeline_stage.hpp:29
ObjectOps< tag::DirectState, tag::ProgramPipeline > ProgramPipelineOps
Program pipeline operations with direct state access.
Definition: program_pipeline.hpp:335
ProgramName ShaderProgram(ShaderType shader_type) const
Returns the program from which the shader_type is used.
Definition: program_pipeline.hpp:327
Exception class for general OpenGL errors.
Definition: basic.hpp:43
Exception class for GL object-related errors.
Definition: object.hpp:24
void UseStages(Bitfield< ProgramPipelineStage > stages, ProgramName program) const
Use the specified stages of the program.
Definition: program_pipeline.hpp:212
void Bind(void) const
Binds this program pipeline object.
Definition: program_pipeline.hpp:137
Implements operations applicable to any object and any operation kind.
Definition: fwd.hpp:151
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
void ActiveShaderProgram(ProgramName program) const
Make the program active for this program pipeline.
Definition: program_pipeline.hpp:287

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).