Advertisement
tinyevil

Untitled

Dec 15th, 2019
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. virtual void on_bind(Surface* surface) override {
  2.     this->surface = surface;
  3.  
  4.     using namespace render;
  5.  
  6.     Device* device = surface_get_device(surface);
  7.     staging_buffer = buffer_create(
  8.         device,
  9.         (
  10.             BufferUsage::MapClientWriteBit |
  11.             BufferUsage::MapClientPersistentBit |
  12.             BufferUsage::MapClientCoherentBit |
  13.             BufferUsage::TransferSrcBit
  14.         ),
  15.         BufferResidence::DeviceLocal,
  16.         256,
  17.         nullptr
  18.     );
  19.     u8* p = buffer_map(
  20.         device,
  21.         staging_buffer,
  22.         (
  23.             BufferMap::DiscardAllBit |
  24.             BufferMap::WriteBit |
  25.             BufferMap::CoherentBit |
  26.             BufferMap::PersistentBit
  27.         ),
  28.         0,
  29.         256
  30.     );
  31.     memcpy(p, vdata, sizeof(vdata));
  32.     memcpy(p + 128, idata, sizeof(idata));
  33.     buffer_flush(device, staging_buffer, 0, 256);
  34.    
  35.  
  36.     vertex_buffer = buffer_create(
  37.         device,
  38.         (
  39.             BufferUsage::TransferDstBit |
  40.             BufferUsage::VertexDataBit
  41.         ),
  42.         BufferResidence::DeviceLocal,
  43.         128,
  44.         nullptr
  45.     );
  46.     buffer_copy(device, staging_buffer, 0, vertex_buffer, 0, 128);
  47.  
  48.     index_buffer = buffer_create(
  49.         device,
  50.         (
  51.             BufferUsage::TransferDstBit |
  52.             BufferUsage::IndexDataBit |
  53.             BufferUsage::ClientUpdateBit
  54.         ),
  55.         BufferResidence::DeviceLocal,
  56.         sizeof(idata),
  57.         nullptr
  58.     );
  59.     buffer_copy(device, staging_buffer, 128, index_buffer, 0, sizeof(idata));
  60.  
  61.     VertexBinding vertex_binding {};
  62.  
  63.     VertexAttrib vertex_attribs[] = {
  64.         {0, 0, VertexAttribFormat::R32G32_SFLOAT, 0},
  65.     };
  66.  
  67.     VertexInput vertex_input {};
  68.     vertex_input.vertex_bindings = &vertex_binding;
  69.     vertex_input.vertex_bindings_count = 1;
  70.     vertex_input.vertex_attribs = vertex_attribs;
  71.     vertex_input.vertex_attribs_count = elements_of(vertex_attribs);
  72.  
  73.     PipelineDefinition pipeline_def{};
  74.     pipeline_def.vertex_input = &vertex_input;
  75.     pipeline_def.primitive_type = PrimitiveType::TriangleStrip;
  76.  
  77.     pipeline = pipeline_create(device, &pipeline_def);
  78.  
  79.    
  80. }
  81.  
  82. virtual void on_render(Surface* surface, render::Device* device) override {
  83.     using namespace render;
  84.  
  85.  
  86.     cmd_bind_pipeline(device, pipeline);
  87.     cmd_bind_vertex_buffer(device, 0, vertex_buffer, 0);
  88.     cmd_bind_index_buffer(device, index_buffer, IndexFormat::U16, 0);
  89.     cmd_draw_indexed(device, 6, 0, 0);
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement