OGLplus (0.52.0) a C++ wrapper for OpenGL

limited_value.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_LIMITED_VALUE_1107121519_HPP
14 #define OGLPLUS_LIMITED_VALUE_1107121519_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/error/limit.hpp>
18 #include <cassert>
19 
20 namespace oglplus {
21 
22 template <GLenum Query>
24 
25 template <GLenum Query>
26 GLuint LimitedCountMax(const LimitedCount<Query>& lim_count);
27 
29 
38 template <GLenum Query>
39 class LimitedCount
40 {
41 private:
42  GLuint _value;
43 
44  static GLuint _query_limit(void)
45  {
46  GLint limit = 0;
47  OGLPLUS_GLFUNC(GetIntegerv)(Query, &limit);
48  OGLPLUS_VERIFY_SIMPLE(GetIntegerv);
49  return GLuint(limit);
50  }
51 
52  static GLuint _limit(void)
53  {
54  static GLuint limit = _query_limit();
55  return limit;
56  }
57 protected:
62  LimitedCount(GLuint value, const char* query_name)
63  : _value(value)
64  {
65  OGLPLUS_HANDLE_ERROR_IF(
66  _value >= _limit(),
67  GL_INVALID_VALUE,
68  LimitError::Message(),
69  LimitError,
70  Value(_value).
71  Limit(_limit()).
72  EnumParam(Query, query_name)
73  );
74  }
75 public:
76 
77  LimitedCount& operator = (const LimitedCount& other)
78  {
79  _value = other._value;
80  assert(_value < _limit());
81  return *this;
82  }
83 
84 #if OGLPLUS_DOCUMENTATION_ONLY
85  template <typename Type>
87  explicit operator Type(void) const;
88 #endif
89 
90  template <typename Type>
91 #if !OGLPLUS_NO_EXPLICIT_CONVERSION_OPERATORS
92  explicit operator Type(void) const
93 #else
94  operator Type(void) const
95 #endif
96  {
97  return Type(_value);
98  }
99 
100  friend GLuint LimitedCountMax<Query>(const LimitedCount&);
101 
102  friend bool operator == (LimitedCount a, LimitedCount b)
103  {
104  return a._value == b._value;
105  }
106 
107  friend bool operator != (LimitedCount a, LimitedCount b)
108  {
109  return a._value != b._value;
110  }
111 
112  friend bool operator <= (LimitedCount a, LimitedCount b)
113  {
114  return a._value <= b._value;
115  }
116 
117  friend bool operator < (LimitedCount a, LimitedCount b)
118  {
119  return a._value < b._value;
120  }
121 
122  friend bool operator >= (LimitedCount a, LimitedCount b)
123  {
124  return a._value >= b._value;
125  }
126 
127  friend bool operator > (LimitedCount a, LimitedCount b)
128  {
129  return a._value > b._value;
130  }
131 };
132 
133 template <GLenum Query>
134 inline GLuint LimitedCountMax(const LimitedCount<Query>& lim_count)
135 {
136  return lim_count._limit();
137 }
138 
139 inline GLuint LimitedCountMax(GLuint lim_count)
140 {
141  return lim_count;
142 }
143 
144 #define OGLPLUS_DECLARE_LIMITED_COUNT_TYPE(NAME, QUERY) \
145 class NAME \
146  : public LimitedCount<GL_ ## QUERY> \
147 { \
148 public: \
149  typedef GLuint _value_type; \
150  NAME(GLuint value = 0) \
151  : LimitedCount<GL_ ## QUERY>(value, #QUERY) \
152  { } \
153 };
154 
155 } // namespace oglplus
156 
157 #endif // include guard
Exception indicating exceeded implementation-defined limits.
Definition: limit.hpp:30
Base class for limited implementation-dependent numeric values.
Definition: limited_value.hpp:23
Helper macro for optional checking of availability of GL function.
Object< QueryOps > Query
An oglplus_object encapsulating the asynchronous query functionality.
Definition: query.hpp:537
LimitedCount(GLuint value, const char *query_name)
Definition: limited_value.hpp:62
Limited value error.

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