OGLplus (0.52.0) a C++ wrapper for OpenGL

uniform_block.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_UNIFORM_BLOCK_1107121519_HPP
14 #define OGLPLUS_UNIFORM_BLOCK_1107121519_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/string/ref.hpp>
20 #include <oglplus/prog_var/varpara_fns.hpp>
21 #include <oglplus/prog_var/set_ops.hpp>
23 #include <oglplus/shader_type.hpp>
25 
26 #include <cassert>
27 
28 namespace oglplus {
29 
30 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_1 || GL_ARB_uniform_buffer_object
31 
32 template <>
33 class ProgVarLocOps<tag::UniformBlock>
34 {
35 private:
36  static const char* MsgGettingInactive(void);
37 protected:
38  static const char* MsgUsingInactive(void);
39 public:
41 
48  static GLint GetLocation(
49  ProgramName program,
50  StrCRef identifier,
51  bool active_only
52  )
53  {
54  GLint result = OGLPLUS_GLFUNC(GetUniformBlockIndex)(
55  GetGLName(program),
56  identifier.c_str()
57  );
58  OGLPLUS_CHECK(
59  GetUniformBlockIndex,
60  ProgVarError,
61  Program(program).
62  Identifier(identifier)
63  );
64  OGLPLUS_HANDLE_ERROR_IF(
65  active_only && (result < 0),
66  GL_INVALID_OPERATION,
67  MsgGettingInactive(),
68  ProgVarError,
69  Program(program).
70  Identifier(identifier)
71  );
72  return result;
73  }
74 };
75 
76 template <>
77 class ProgVarCommonOps<tag::UniformBlock>
78  : public ProgVarLoc<tag::UniformBlock>
79 {
80 private:
81  static GLenum _translate_ref(ShaderType shader_type);
82  static GLenum _translate_max(ShaderType shader_type);
83 protected:
84  ProgVarCommonOps(UniformBlockLoc ubloc)
85  : ProgVarLoc<tag::UniformBlock>(ubloc)
86  { }
87 public:
89  static GLuint MaxIn(ShaderType shader_type)
90  {
91  GLint result;
92  OGLPLUS_GLFUNC(GetIntegerv)(
93  _translate_max(shader_type),
94  &result
95  );
96  OGLPLUS_VERIFY(
97  GetIntegerv,
98  Error,
99  EnumParam(_translate_max(shader_type))
100  );
101  assert(result >= 0);
102  return GLuint(result);
103  }
104 
106 
110  bool ReferencedBy(ShaderType shader_type) const
111  {
112  GLint result;
113  OGLPLUS_GLFUNC(GetActiveUniformBlockiv)(
114  this->_program,
115  this->_location,
116  _translate_ref(shader_type),
117  &result
118  );
119  OGLPLUS_VERIFY(
120  GetActiveUniformBlockiv,
121  Error,
122  EnumParam(_translate_ref(shader_type))
123  );
124  return result == GL_TRUE;
125  }
126 
128 
132  GLuint DataSize(void) const
133  {
134  GLint result;
135  OGLPLUS_GLFUNC(GetActiveUniformBlockiv)(
136  this->_program,
137  this->_location,
138  GL_UNIFORM_BLOCK_DATA_SIZE,
139  &result
140  );
141  OGLPLUS_VERIFY(
142  GetActiveUniformBlockiv,
143  Error,
144  EnumParam(GLenum(GL_UNIFORM_BLOCK_DATA_SIZE))
145  );
146  assert(result >= 0);
147  return GLuint(result);
148  }
149 
151 
155  void Binding(UniformBufferBindingPoint binding)
156  {
157  OGLPLUS_GLFUNC(UniformBlockBinding)(
158  this->_program,
159  this->_location,
160  GLuint(binding)
161  );
162  OGLPLUS_VERIFY(
163  UniformBlockBinding,
164  ProgVarError,
165  Program(ProgramName(this->_program)).
166  Index(GLuint(binding))
167  );
168  }
169 };
170 
172 
179 typedef ProgVar<
180  tag::ImplicitSel,
182  tag::NoTypecheck,
183  void
185 
186 #endif // uniform buffer object
187 
188 } // namespace oglplus
189 
190 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
191 #include <oglplus/uniform_block.ipp>
192 #endif
193 
194 #endif // include guard
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
ShaderType
The type of a Shader.
Definition: shader_type.hpp:26
Program variable wrapper.
Program variable location wrapper.
ProgVar< tag::ImplicitSel, tag::UniformBlock, tag::NoTypecheck, void > UniformBlock
Encapsulates uniform block operations.
Definition: uniform_block.hpp:184
Shader type enumeration.
ProgVarLoc(void)
Default construction.
Definition: location.hpp:55
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
String reference.
String const reference wrapper template.
Definition: ref_tpl.hpp:72
Helper macro for optional checking of availability of GL function.
Declaration of OGLplus program-variable-related error.
Buffer binding point indices.

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).