15
GAM531 DPS931 – Week 10 Meshes and Buffers

GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Embed Size (px)

Citation preview

Page 1: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

GAM531DPS931 – Week 10Meshes and Buffers

Page 2: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Breaking Down An Image

Actors

Actors = Mesh + Material

Mesh = Shape of the object

Page 3: 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

WireframeMesh

Page 4: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Breaking Down A Mesh

Triangle Face Vertices

X Y Z-10 10 -10 10 10 -10 10 -10 -10

Page 5: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

What Is A Vertex?

Class Vertex {

};

[ 0, 10, 0 ]

Vector<> normal;Vector<float,2> uv;float weight;int boneID;

Vector<> pos;

[ 7, -7, 0 ][ -7, -7, 0 ]

Page 6: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Vertex Buffer

TriangleTriangle

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 Vertex Vertex Vertex Vertex Vertex

Page 7: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

How Do Vertices Make Triangles?

[ 0, 10, 0 ]

[ 7, -7, 0 ][ -7, -7, 0 ]

Winding Order

Clock-Wise (Front)Vs

Counter Clock-Wise (Back)

Page 8: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Triangle Face Culling

No Culling Back Face Culling All Face Culling

Page 9: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

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

TriangleTriangle

Index Index Index Index Index Index

Page 10: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

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 ] ]

Page 11: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Primitive Types

Page 12: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Programming Buffers

bSize = //Size of bufferglGenVertexArrays(1, &vID); //vertex buffer onlyglBindVertexArray(vID); //vertex buffer onlyglGenBuffers(1, &bufferID);glBindBuffer(GL_ARRAY_BUFFER,bufferID);//constructs a vertex definition (vertex buffer only)_initVertex(*(const VertexFormat<RS_GL43>*)&v);

D3D11_BUFFER_DESC bd;ZeroMemory(&bd, sizeof(D3D11_BUFFER_DESC));

bd.Usage = //how it will be used (static vs dynamic)bd.CPUAccessFlags = //cpu accessbd.ByteWidth = //Size of the bufferbd.BindFlags = //type of buffer

dev->CreateBuffer(&bd, 0, &buffer));

Page 13: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Writing to Buffers

//set buffer to be writtenglBindVertexArray(vID);glBindBuffer(GL_ARRAY_BUFFER, bufferID);

//write to the bufferglBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSizeInBytes, someData, GL_STATIC_DRAW);//GL_DYNAMIC_DRAWglBindBuffer(GL_ARRAY_BUFFER, 0);

//sets the buffer to be written tocon->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sub)

//write to the bufferMemcpy(sub.pData, someData, dataSizeInBytes);

//unmap bufferCon->unmap(buffer, 0);

Page 14: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

Binding Buffers

//set vertex bufferglBindVertexArray(vID);glBindBuffer(GL_ARRAY_BUFFER, bufferID);//don’t forget to bind the vertex attributes...

//set index bufferglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID);

//bind uniformglBindBufferBase(GL_UNIFORM_BUFFER, slot, bufferID);

//set vertex buffercon->IASetVertexBuffers(0,1, &buffer, &vSize, &offset);

//set index buffercon->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, 0);

//set uniformcon->PSSetConstantBuffers(slot, 1, &buffer);con->VSSetConstantBuffers(slot, 1, &buffer);

Page 15: GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object

To Do• Continue work on engine enhancement

• Read this week’s lab

• Read this week’s notes

• Re-implement OpenGL Device functions