GAM531 DPS931 – Week 10 Meshes and Buffers
Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object
Breaking Down an Actor Mesh + Advanced Material Wireframe Mesh
Breaking Down A Mesh Triangle Face Vertices X Y Z
What Is A Vertex? Class Vertex { }; [ 0, 10, 0 ] Vector<> normal; Vector uv; float weight; int boneID; Vector<> pos; [ 7, -7, 0 ][ -7, -7, 0 ]
Vertex Buffer Triangle How Do Vertices Make A Mesh [ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 0, 10, 0 ], [ 7, -7, 0 ], [ 7, -7, -7 ] ] Vertex
How Do Vertices Make Triangles? [ 0, 10, 0 ] [ 7, -7, 0 ][ -7, -7, 0 ] Winding Order Clock-Wise (Front) Vs Counter Clock-Wise (Back)
Triangle Face Culling No CullingBack Face CullingAll Face Culling
Vertex Buffer Optimizations [ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 0, 10, 0 ], [ 7, -7, 0 ], [ 7, -7, -7 ] ] Vertex 1 Vertex 2 Vertex 3 Vertex 1 Vertex 2 Vertex 4 Vertex Buffer Vertex Index Buffer Triangle Index
Index Buffer Vertex Buffer (No Index Buffer) [ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 0, 10, 0 ], [ 7, -7, 0 ], [ 7, -7, -7 ] ] Index Buffer [ 0, 1, 2, 0, 1, 4 ] Vertex Buffer [ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 7, -7, -7 ] ]
Primitive Types
Programming Buffers bSize = //Size of buffer glGenVertexArrays(1, &vID); //vertex buffer only glBindVertexArray(vID); //vertex buffer only glGenBuffers(1, &bufferID); glBindBuffer(GL_ARRAY_BUFFER,bufferID); //constructs a vertex definition (vertex buffer only) _initVertex(*(const VertexFormat *)&v); D3D11_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(D3D11_BUFFER_DESC)); bd.Usage = //how it will be used (static vs dynamic) bd.CPUAccessFlags = //cpu access bd.ByteWidth = //Size of the buffer bd.BindFlags = //type of buffer dev->CreateBuffer(&bd, 0, &buffer));
Writing to Buffers //set buffer to be written glBindVertexArray(vID); glBindBuffer(GL_ARRAY_BUFFER, bufferID); //write to the buffer glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSizeInBytes, someData, GL_STATIC_DRAW);//GL_DYNAMIC_DRAW glBindBuffer(GL_ARRAY_BUFFER, 0); //sets the buffer to be written to con->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sub) //write to the buffer Memcpy(sub.pData, someData, dataSizeInBytes); //unmap buffer Con->unmap(buffer, 0);
Binding Buffers //set vertex buffer glBindVertexArray(vID); glBindBuffer(GL_ARRAY_BUFFER, bufferID); //don’t forget to bind the vertex attributes... //set index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID); //bind uniform glBindBufferBase(GL_UNIFORM_BUFFER, slot, bufferID); //set vertex buffer con->IASetVertexBuffers(0,1, &buffer, &vSize, &offset); //set index buffer con->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, 0); //set uniform con->PSSetConstantBuffers(slot, 1, &buffer); con->VSSetConstantBuffers(slot, 1, &buffer);
To Do Continue work on engine enhancement Read this week’s lab Read this week’s notes Re-implement OpenGL Device functions