History

Moving all the variables for the Input stage cache into a struct just like for transformStage

Sam Gateau committed 12 years ago

Commit 5c9c78e1 parent 420118e2 files · +63 −54Browse files

Showing the changes to interface/src/gpu/GLBackend.cpp (1 of 2 files). Show all

Unified · Split

interface/src/gpu/GLBackend.cpp+30−38
@@ -113,15 +113,7 @@ static const GLenum _elementTypeToGLType[NUM_TYPES]= { · 112 unmodified lines
113 113
114 114
115GLBackend::GLBackend() :115GLBackend::GLBackend() :
116 _needInputFormatUpdate(true),116 _input(),
117 _inputFormat(0),
118 _inputBuffersState(0),
119 _inputBuffers(_inputBuffersState.size(), BufferPointer(0)),
120 _inputBufferOffsets(_inputBuffersState.size(), 0),
121 _inputBufferStrides(_inputBuffersState.size(), 0),
122 _indexBuffer(0),
123 _indexBufferOffset(0),
124 _inputAttributeActivation(0),
125 _transform()117 _transform()
126{118{
127 119
@@ -203,9 +195,9 @@ void GLBackend::do_drawIndexed(Batch& batch, uint32 paramOffset) { · 75 unmodified lines
203 uint32 numIndices = batch._params[paramOffset + 1]._uint;195 uint32 numIndices = batch._params[paramOffset + 1]._uint;
204 uint32 startIndex = batch._params[paramOffset + 0]._uint;196 uint32 startIndex = batch._params[paramOffset + 0]._uint;
205 197
206 GLenum glType = _elementTypeToGLType[_indexBufferType];198 GLenum glType = _elementTypeToGLType[_input._indexBufferType];
207 199
208 glDrawElements(mode, numIndices, glType, reinterpret_cast<GLvoid*>(startIndex + _indexBufferOffset));200 glDrawElements(mode, numIndices, glType, reinterpret_cast<GLvoid*>(startIndex + _input._indexBufferOffset));
209 CHECK_GL_ERROR();201 CHECK_GL_ERROR();
210}202}
211 203
@@ -220,9 +212,9 @@ void GLBackend::do_drawIndexedInstanced(Batch& batch, uint32 paramOffset) { · 8 unmodified lines
220void GLBackend::do_setInputFormat(Batch& batch, uint32 paramOffset) {212void GLBackend::do_setInputFormat(Batch& batch, uint32 paramOffset) {
221 Stream::FormatPointer format = batch._streamFormats.get(batch._params[paramOffset]._uint);213 Stream::FormatPointer format = batch._streamFormats.get(batch._params[paramOffset]._uint);
222 214
223 if (format != _inputFormat) {215 if (format != _input._format) {
224 _inputFormat = format;216 _input._format = format;
225 _needInputFormatUpdate = true;217 _input._invalidFormat = true;
226 }218 }
227}219}
228 220
@@ -233,10 +225,10 @@ void GLBackend::do_setInputBuffer(Batch& batch, uint32 paramOffset) { · 4 unmodified lines
233 uint32 channel = batch._params[paramOffset + 3]._uint;225 uint32 channel = batch._params[paramOffset + 3]._uint;
234 226
235 if (channel < getNumInputBuffers()) {227 if (channel < getNumInputBuffers()) {
236 _inputBuffers[channel] = buffer;228 _input._buffers[channel] = buffer;
237 _inputBufferOffsets[channel] = offset;229 _input._bufferOffsets[channel] = offset;
238 _inputBufferStrides[channel] = stride;230 _input._bufferStrides[channel] = stride;
239 _inputBuffersState.set(channel);231 _input._buffersState.set(channel);
240 }232 }
241}233}
242 234
@@ -252,14 +244,14 @@ static const GLenum attributeSlotToClassicAttribName[NUM_CLASSIC_ATTRIBS] = { · 9 unmodified lines
252#endif244#endif
253 245
254void GLBackend::updateInput() {246void GLBackend::updateInput() {
255 if (_needInputFormatUpdate || _inputBuffersState.any()) {247 if (_input._invalidFormat || _input._buffersState.any()) {
256 248
257 if (_needInputFormatUpdate) {249 if (_input._invalidFormat) {
258 InputActivationCache newActivation;250 InputStageState::ActivationCache newActivation;
259 251
260 // Check expected activation252 // Check expected activation
261 if (_inputFormat) {253 if (_input._format) {
262 const Stream::Format::AttributeMap& attributes = _inputFormat->getAttributes();254 const Stream::Format::AttributeMap& attributes = _input._format->getAttributes();
263 for (Stream::Format::AttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++) {255 for (Stream::Format::AttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
264 const Stream::Attribute& attrib = (*it).second;256 const Stream::Attribute& attrib = (*it).second;
265 newActivation.set(attrib._slot);257 newActivation.set(attrib._slot);
@@ -269,7 +261,7 @@ void GLBackend::updateInput() { · 3 unmodified lines
269 // Manage Activation what was and what is expected now261 // Manage Activation what was and what is expected now
270 for (unsigned int i = 0; i < newActivation.size(); i++) {262 for (unsigned int i = 0; i < newActivation.size(); i++) {
271 bool newState = newActivation[i];263 bool newState = newActivation[i];
272 if (newState != _inputAttributeActivation[i]) {264 if (newState != _input._attributeActivation[i]) {
273#if defined(SUPPORT_LEGACY_OPENGL)265#if defined(SUPPORT_LEGACY_OPENGL)
274 if (i < NUM_CLASSIC_ATTRIBS) {266 if (i < NUM_CLASSIC_ATTRIBS) {
275 if (newState) {267 if (newState) {
@@ -290,31 +282,31 @@ void GLBackend::updateInput() { · 14 unmodified lines
290 }282 }
291 CHECK_GL_ERROR();283 CHECK_GL_ERROR();
292 284
293 _inputAttributeActivation.flip(i);285 _input._attributeActivation.flip(i);
294 }286 }
295 }287 }
296 }288 }
297 289
298 // now we need to bind the buffers and assign the attrib pointers290 // now we need to bind the buffers and assign the attrib pointers
299 if (_inputFormat) {291 if (_input._format) {
300 const Buffers& buffers = _inputBuffers;292 const Buffers& buffers = _input._buffers;
301 const Offsets& offsets = _inputBufferOffsets;293 const Offsets& offsets = _input._bufferOffsets;
302 const Offsets& strides = _inputBufferStrides;294 const Offsets& strides = _input._bufferStrides;
303 295
304 const Stream::Format::AttributeMap& attributes = _inputFormat->getAttributes();296 const Stream::Format::AttributeMap& attributes = _input._format->getAttributes();
305 297
306 for (Stream::Format::ChannelMap::const_iterator channelIt = _inputFormat->getChannels().begin();298 for (Stream::Format::ChannelMap::const_iterator channelIt = _input._format->getChannels().begin();
307 channelIt != _inputFormat->getChannels().end();299 channelIt != _input._format->getChannels().end();
308 channelIt++) {300 channelIt++) {
309 const Stream::Format::ChannelMap::value_type::second_type& channel = (*channelIt).second;301 const Stream::Format::ChannelMap::value_type::second_type& channel = (*channelIt).second;
310 if ((*channelIt).first < buffers.size()) {302 if ((*channelIt).first < buffers.size()) {
311 int bufferNum = (*channelIt).first;303 int bufferNum = (*channelIt).first;
312 304
313 if (_inputBuffersState.test(bufferNum) || _needInputFormatUpdate) {305 if (_input._buffersState.test(bufferNum) || _input._invalidFormat) {
314 GLuint vbo = gpu::GLBackend::getBufferID((*buffers[bufferNum]));306 GLuint vbo = gpu::GLBackend::getBufferID((*buffers[bufferNum]));
315 glBindBuffer(GL_ARRAY_BUFFER, vbo);307 glBindBuffer(GL_ARRAY_BUFFER, vbo);
316 CHECK_GL_ERROR();308 CHECK_GL_ERROR();
317 _inputBuffersState[bufferNum] = false;309 _input._buffersState[bufferNum] = false;
318 310
319 for (unsigned int i = 0; i < channel._slots.size(); i++) {311 for (unsigned int i = 0; i < channel._slots.size(); i++) {
320 const Stream::Attribute& attrib = attributes.at(channel._slots[i]);312 const Stream::Attribute& attrib = attributes.at(channel._slots[i]);
@@ -354,7 +346,7 @@ void GLBackend::updateInput() { · 33 unmodified lines
354 }346 }
355 }347 }
356 // everything format related should be in sync now348 // everything format related should be in sync now
357 _needInputFormatUpdate = false;349 _input._invalidFormat = false;
358 }350 }
359 351
360/* TODO: Fancy version GL4.4352/* TODO: Fancy version GL4.4
@@ -415,10 +407,10 @@ void GLBackend::updateInput() { · 54 unmodified lines
415 407
416 408
417void GLBackend::do_setIndexBuffer(Batch& batch, uint32 paramOffset) {409void GLBackend::do_setIndexBuffer(Batch& batch, uint32 paramOffset) {
418 _indexBufferType = (Type) batch._params[paramOffset + 2]._uint;410 _input._indexBufferType = (Type) batch._params[paramOffset + 2]._uint;
419 BufferPointer indexBuffer = batch._buffers.get(batch._params[paramOffset + 1]._uint);411 BufferPointer indexBuffer = batch._buffers.get(batch._params[paramOffset + 1]._uint);
420 _indexBufferOffset = batch._params[paramOffset + 0]._uint;412 _input._indexBufferOffset = batch._params[paramOffset + 0]._uint;
421 _indexBuffer = indexBuffer;413 _input._indexBuffer = indexBuffer;
422 if (indexBuffer) {414 if (indexBuffer) {
423 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferID(*indexBuffer));415 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferID(*indexBuffer));
424 } else {416 } else {