150 likes | 280 Views
GAM531 DPS931 – Week 10. Meshes and Buffers. Breaking Down An Image. Actors. Actors = Mesh + Material. Mesh = Shape of the object. Breaking Down an Actor. Wireframe Mesh. Mesh + Advanced Material. Breaking Down A Mesh. Vertices. Triangle Face. X Y Z -10 10 -10
E N D
GAM531DPS931 – Week 10 Meshes and Buffers
Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object
Breaking Down an Actor Wireframe Mesh Mesh + Advanced Material
Breaking Down A Mesh Vertices Triangle Face X Y Z -10 10 -10 10 10 -10 10 -10 -10
What Is A Vertex? Class Vertex { [ 0, 10, 0 ] Vector<> pos; Vector<> normal; Vector<float,2> uv; float weight; intboneID; }; [ -7, -7, 0 ] [ 7, -7, 0 ]
How Do Vertices Make A Mesh Vertex Buffer Triangle Triangle Vertex Vertex Vertex Vertex Vertex Vertex [ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 0, 10, 0 ], [ 7, -7, 0 ], [ 7, -7, -7 ] ]
How Do Vertices Make Triangles? [ 0, 10, 0 ] Winding Order Clock-Wise (Front) Vs Counter Clock-Wise (Back) [ -7, -7, 0 ] [ 7, -7, 0 ]
Triangle Face Culling No Culling Back Face Culling All 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 Vertex Vertex Vertex Index Buffer Triangle Triangle Index Index Index Index Index 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 ] ] Vertex Buffer[ [ 0, 10, 0 ], [ 7, -7, 0 ], [ -7, -7, 0 ], [ 7, -7, -7 ] ] Index Buffer [ 0, 1, 2, 0, 1, 4 ]
Programming Buffers 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)); 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(*(constVertexFormat<RS_GL43>*)&v);
Writing to Buffers //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); //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);
Binding Buffers //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); //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);
To Do • Continue work on engine enhancement • Read this week’s lab • Read this week’s notes • Re-implement OpenGL Device functions