Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- virtual void on_bind(Surface* surface) override {
- this->surface = surface;
- using namespace render;
- Device* device = surface_get_device(surface);
- staging_buffer = buffer_create(
- device,
- (
- BufferUsage::MapClientWriteBit |
- BufferUsage::MapClientPersistentBit |
- BufferUsage::MapClientCoherentBit |
- BufferUsage::TransferSrcBit
- ),
- BufferResidence::DeviceLocal,
- 256,
- nullptr
- );
- u8* p = buffer_map(
- device,
- staging_buffer,
- (
- BufferMap::DiscardAllBit |
- BufferMap::WriteBit |
- BufferMap::CoherentBit |
- BufferMap::PersistentBit
- ),
- 0,
- 256
- );
- memcpy(p, vdata, sizeof(vdata));
- memcpy(p + 128, idata, sizeof(idata));
- buffer_flush(device, staging_buffer, 0, 256);
- vertex_buffer = buffer_create(
- device,
- (
- BufferUsage::TransferDstBit |
- BufferUsage::VertexDataBit
- ),
- BufferResidence::DeviceLocal,
- 128,
- nullptr
- );
- buffer_copy(device, staging_buffer, 0, vertex_buffer, 0, 128);
- index_buffer = buffer_create(
- device,
- (
- BufferUsage::TransferDstBit |
- BufferUsage::IndexDataBit |
- BufferUsage::ClientUpdateBit
- ),
- BufferResidence::DeviceLocal,
- sizeof(idata),
- nullptr
- );
- buffer_copy(device, staging_buffer, 128, index_buffer, 0, sizeof(idata));
- VertexBinding vertex_binding {};
- VertexAttrib vertex_attribs[] = {
- {0, 0, VertexAttribFormat::R32G32_SFLOAT, 0},
- };
- VertexInput vertex_input {};
- vertex_input.vertex_bindings = &vertex_binding;
- vertex_input.vertex_bindings_count = 1;
- vertex_input.vertex_attribs = vertex_attribs;
- vertex_input.vertex_attribs_count = elements_of(vertex_attribs);
- PipelineDefinition pipeline_def{};
- pipeline_def.vertex_input = &vertex_input;
- pipeline_def.primitive_type = PrimitiveType::TriangleStrip;
- pipeline = pipeline_create(device, &pipeline_def);
- }
- virtual void on_render(Surface* surface, render::Device* device) override {
- using namespace render;
- cmd_bind_pipeline(device, pipeline);
- cmd_bind_vertex_buffer(device, 0, vertex_buffer, 0);
- cmd_bind_index_buffer(device, index_buffer, IndexFormat::U16, 0);
- cmd_draw_indexed(device, 6, 0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement