Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 360 vs 363 for /trunk/Source Code/Libs/src/GLIM/glimBatchData.cpp

Diff revisions: vs.
  @@ -8,6 +8,7 @@
8 8 #include "glimInterface.h"
9 9
10 10 #include "Platform/Video/OpenGL/Headers/GLWrapper.h"
11 + #include "Platform/Video/OpenGL/Buffers/Headers/glMemoryManager.h"
11 12
12 13 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
13 14
  @@ -218,9 +219,9 @@
218 219 if (z > m_fMaxZ)
219 220 m_fMaxZ = z;
220 221
221 - m_PositionData.push_back (x);
222 - m_PositionData.push_back (y);
223 - m_PositionData.push_back (z);
222 + m_PositionData.push_back (Glim4ByteData(x));
223 + m_PositionData.push_back (Glim4ByteData(y));
224 + m_PositionData.push_back (Glim4ByteData(z));
224 225
225 226 std::map<stringImpl, GlimArrayData>::iterator it, itend;
226 227 itend = m_Attributes.end ();
  @@ -464,42 +465,39 @@
464 465 glGenBuffers (1, &m_uiElementBufferID_Triangles);
465 466 glGenBuffers (1, &m_uiElementBufferID_Wireframe);
466 467 }
467 -
468 - Divide::GL_API::setActiveBuffer(GL_ARRAY_BUFFER, m_uiVertexBufferID);
469 - glBufferData (GL_ARRAY_BUFFER, uiVertices * uiVertexDataSize, NULL, GL_STREAM_DRAW);
468 +
469 + std::vector<Glim4ByteData> bufferData;
470 + bufferData.insert(bufferData.end(), m_PositionData.begin(), m_PositionData.end());
471 + m_PositionData.clear();
470 472
471 - // first upload the position data
472 - unsigned int uiOffset = uiVertices * sizeof (float) * 3;
473 + unsigned int uiOffset = uiVertices * sizeof(Glim4ByteData) * 3;
473 474
474 - // offset is zero, but can use uiOffset as size
475 - glBufferSubData (GL_ARRAY_BUFFER, 0, uiOffset, m_PositionData.data());
476 - // the buffer in RAM can be cleared now
477 - m_PositionData.clear ();
478 -
479 475 // now upload each attribute array one after another
480 -
481 476 std::map<stringImpl, GlimArrayData>::iterator it, itend;
482 - itend = m_Attributes.end ();
477 + it = m_Attributes.begin();
478 + itend = m_Attributes.end();
483 479
484 - for (it = m_Attributes.begin (); it != itend; ++it)
485 - {
486 - const unsigned int uiAttributeSize = (unsigned int) (it->second.m_ArrayData.size ()) * sizeof(int); // already includes the number of vertices
487 -
488 - // upload the data
489 - glBufferSubData (GL_ARRAY_BUFFER, uiOffset, uiAttributeSize, &it->second.m_ArrayData[0].Float);
490 -
491 - // free the temporary buffer in RAM, the data is now in a better place (the VRAM)
492 - it->second.m_ArrayData.clear ();
480 + for (; it != itend; ++it) {
481 + bufferData.insert(bufferData.end(), it->second.m_ArrayData.begin(),
482 + it->second.m_ArrayData.end());
483 + const unsigned int uiAttributeSize =
484 + (unsigned int)(it->second.m_ArrayData.size()) *
485 + sizeof(Glim4ByteData); // already includes the number of vertices
493 486
487 + // free the temporary buffer in RAM
488 + it->second.m_ArrayData.clear();
494 489 it->second.m_uiBufferStride = uiAttributeSize / uiVertices;
495 -
496 490 // store the buffer offset for later use
497 491 it->second.m_uiBufferOffset = uiOffset;
498 -
499 492 // increase the buffer offset
500 493 uiOffset += uiAttributeSize;
501 494 }
502 - Divide::GL_API::setActiveBuffer(GL_ARRAY_BUFFER, 0);
495 +
496 + Divide::GLUtil::allocBuffer(m_uiVertexBufferID,
497 + uiVertices * uiVertexDataSize,
498 + GL_STREAM_DRAW, bufferData.data());
499 + // the buffer in RAM can be cleared now
500 + bufferData.clear();
503 501
504 502 m_uiWireframeElements = (unsigned int) m_IndexBuffer_Wireframe.size();
505 503 m_uiPointElements = (unsigned int) m_IndexBuffer_Points.size ();
  @@ -508,31 +506,38 @@
508 506
509 507 // upload the index buffer for the points
510 508 if (m_uiPointElements > 0) {
511 - //glNamedBufferData(
512 - gl45ext::glNamedBufferDataEXT(
513 - m_uiElementBufferID_Points, m_uiPointElements * sizeof(unsigned int), m_IndexBuffer_Points.data(), GL_STATIC_DRAW);
514 - m_IndexBuffer_Points.clear ();
509 + Divide::GLUtil::allocBuffer(
510 + m_uiElementBufferID_Points,
511 + m_uiPointElements * sizeof(unsigned int), GL_STATIC_DRAW,
512 + m_IndexBuffer_Points.data());
513 + m_IndexBuffer_Points.clear();
515 514 }
516 -
515 +
517 516 // upload the index buffer for the lines
518 517 if (m_uiLineElements > 0) {
519 - //glNamedBufferData(
520 - gl45ext::glNamedBufferDataEXT(m_uiElementBufferID_Lines, m_uiLineElements * sizeof(unsigned int), m_IndexBuffer_Lines.data(), GL_STATIC_DRAW);
521 - m_IndexBuffer_Lines.clear ();
518 + Divide::GLUtil::allocBuffer(m_uiElementBufferID_Lines,
519 + m_uiLineElements * sizeof(unsigned int),
520 + GL_STATIC_DRAW,
521 + m_IndexBuffer_Lines.data());
522 + m_IndexBuffer_Lines.clear();
522 523 }
523 524
524 525 // upload the index buffer for the triangles
525 526 if (m_uiTriangleElements > 0) {
526 - //glNamedBufferData(
527 - gl45ext::glNamedBufferDataEXT(m_uiElementBufferID_Triangles, m_uiTriangleElements * sizeof(unsigned int), m_IndexBuffer_Triangles.data(), GL_STATIC_DRAW);
528 - m_IndexBuffer_Triangles.clear ();
527 + Divide::GLUtil::allocBuffer(
528 + m_uiElementBufferID_Triangles,
529 + m_uiTriangleElements * sizeof(unsigned int), GL_STATIC_DRAW,
530 + m_IndexBuffer_Triangles.data());
531 + m_IndexBuffer_Triangles.clear();
529 532 }
530 533
531 534 // upload the index buffer for the wireframe
532 535 if (m_uiWireframeElements > 0) {
533 - //glNamedBufferData(
534 - gl45ext::glNamedBufferDataEXT(m_uiElementBufferID_Wireframe, m_uiWireframeElements * sizeof(unsigned int), m_IndexBuffer_Wireframe.data(), GL_STATIC_DRAW);
535 - m_IndexBuffer_Wireframe.clear ();
536 + Divide::GLUtil::allocBuffer(
537 + m_uiElementBufferID_Wireframe,
538 + m_uiWireframeElements * sizeof(unsigned int), GL_STATIC_DRAW,
539 + m_IndexBuffer_Wireframe.data());
540 + m_IndexBuffer_Wireframe.clear();
536 541 }
537 542 }
538 543 #endif