~thumper/glint/simple-app

« back to all changes in this revision

Viewing changes to src/internal/AttributeVariableImpl.cpp

  • Committer: Michi Henning
  • Date: 2012-12-17 03:42:57 UTC
  • Revision ID: michi.henning@canonical.com-20121217034257-m1icr5l6tk5082th
Improved coverage

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
{
49
49
}
50
50
 
 
51
// No check_gl() calls in any of this code because the only failure condition is that the
 
52
// location is wrong, which is impossible.
 
53
 
51
54
AttributeVariable::ArrayState
52
55
AttributeVariableImpl::
53
56
array_state() const
54
57
{
55
58
    GLint v;
56
59
    glGetVertexAttribiv(location(), GL_VERTEX_ATTRIB_ARRAY_ENABLED, &v);
57
 
    // No check_gl() call here because the only failure conditions are an invalid location or illegal enum.
58
60
    return v ? AttributeVariable::ArrayState::enabled : AttributeVariable::ArrayState::disabled;
59
61
}
60
62
 
70
72
    {
71
73
        glDisableVertexAttribArray(location());
72
74
    }
73
 
    // No check_gl() call here because the only failure condition is an invalid location.
74
 
}
75
 
 
76
 
void
77
 
AttributeVariableImpl::
78
 
check(const char* verb) const
79
 
{
80
 
    GLenum err = clear_gl_error();
81
 
    if (err != GL_NO_ERROR)
82
 
    {
83
 
        ostringstream msg;
84
 
        msg << "cannot " << verb << " attribute variable \"" << name() << "\" at location " << to_string(location())
85
 
            << "; size = " << to_string(size()) << ", program id = " << to_string(program_id());
86
 
        throw OpenGLException(msg.str(), err);
87
 
    }
88
 
}
89
 
 
90
 
void
91
 
AttributeVariableImpl::
92
 
check_get() const
93
 
{
94
 
    check("get");
95
 
}
96
 
 
97
 
void
98
 
AttributeVariableImpl::
99
 
check_set() const
100
 
{
101
 
    check("set");
102
75
}
103
76
 
104
77
// Float
120
93
{
121
94
    FloatVec4 v;
122
95
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, &v[0]);
123
 
    check_get();
124
96
    return v[0];
125
97
}
126
98
 
129
101
set(GLfloat v)
130
102
{
131
103
    glVertexAttrib1f(location(), v);
132
 
    check_set();
133
104
}
134
105
 
135
106
// FloatVec2
151
122
{
152
123
    FloatVec4 v;
153
124
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, &v[0]);
154
 
    check_get();
155
125
    return FloatVec2({ { v[0], v[1] } });
156
126
}
157
127
 
160
130
set(const FloatVec2& v)
161
131
{
162
132
    glVertexAttrib2fv(location(), &v[0]);
163
 
    check_set();
164
133
}
165
134
 
166
135
// FloatVec3
182
151
{
183
152
    FloatVec4 v;
184
153
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, &v[0]);
185
 
    check_get();
186
154
    return FloatVec3({ { v[0], v[1], v[2] } });
187
155
}
188
156
 
191
159
set(const FloatVec3& v)
192
160
{
193
161
    glVertexAttrib3fv(location(), &v[0]);
194
 
    check_set();
195
162
}
196
163
 
197
164
// FloatVec4
213
180
{
214
181
    FloatVec4 v;
215
182
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, &v[0]);
216
 
    check_get();
217
183
    return v;
218
184
}
219
185
 
222
188
set(const FloatVec4& v)
223
189
{
224
190
    glVertexAttrib4fv(location(), &v[0]);
225
 
    check_set();
226
191
}
227
192
 
228
193
// FloatMat2
245
210
    FloatMat4 v;
246
211
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, v[0].begin());
247
212
    glGetVertexAttribfv(location() + 1, GL_CURRENT_VERTEX_ATTRIB, v[1].begin());
248
 
    check_get();
249
213
    return FloatMat2({ {
250
214
                        { { v[0][0], v[0][1] } },
251
215
                        { { v[1][0], v[1][1] } }
258
222
{
259
223
    glVertexAttrib2fv(location(), v[0].begin());
260
224
    glVertexAttrib2fv(location() + 1, v[1].begin());
261
 
    check_set();
262
225
}
263
226
 
264
227
// FloatMat3
282
245
    glGetVertexAttribfv(location(), GL_CURRENT_VERTEX_ATTRIB, v[0].begin());
283
246
    glGetVertexAttribfv(location() + 1, GL_CURRENT_VERTEX_ATTRIB, v[1].begin());
284
247
    glGetVertexAttribfv(location() + 2, GL_CURRENT_VERTEX_ATTRIB, v[2].begin());
285
 
    check_get();
286
248
    return FloatMat3({ {
287
249
                        { { v[0][0], v[0][1], v[0][2] } },
288
250
                        { { v[1][0], v[1][1], v[1][2] } },
297
259
    glVertexAttrib3fv(location(), v[0].begin());
298
260
    glVertexAttrib3fv(location() + 1, v[1].begin());
299
261
    glVertexAttrib3fv(location() + 2, v[2].begin());
300
 
    check_set();
301
262
}
302
263
 
303
264
// FloatMat4
322
283
    glGetVertexAttribfv(location() + 1, GL_CURRENT_VERTEX_ATTRIB, v[1].begin());
323
284
    glGetVertexAttribfv(location() + 2, GL_CURRENT_VERTEX_ATTRIB, v[2].begin());
324
285
    glGetVertexAttribfv(location() + 3, GL_CURRENT_VERTEX_ATTRIB, v[3].begin());
325
 
    check_get();
326
286
    return v;
327
287
}
328
288
 
334
294
    glVertexAttrib4fv(location() + 1, v[1].begin());
335
295
    glVertexAttrib4fv(location() + 2, v[2].begin());
336
296
    glVertexAttrib4fv(location() + 3, v[3].begin());
337
 
    check_set();
338
297
}
339
298
 
340
299
} // namespace internal