Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. // semantic names
  2. typedef enum {
  3.     V_POSITION,
  4.     V_NORMAL,
  5.     V_TANGENT,
  6.     V_BITANGENT,
  7.     V_TEXCOORD,
  8.     V_BLEND_INDICES,
  9.     V_BLEND_WEIGHTS,
  10.     V_UNKNOWN,
  11.     V_COUNT = V_UNKNOWN
  12. } VertexSemantic;
  13.  
  14. typedef enum {
  15.     SIGN_BIT = 31,
  16.     FORMAT = 30,
  17.     // Bit range 20-29 unused
  18.     BITS_W = 15,
  19.     BITS_Z = 10,
  20.     BITS_Y = 5,
  21.     BITS_X = 0
  22. } FormatEncoding;
  23.  
  24. typedef enum {
  25.     FLOAT,
  26.     INTEGER
  27. } ComponentType;
  28.  
  29. // helper functions for encoding / decoding Format
  30. inline uint32_t format(ComponentType type, bool signed_, uint8_t bit_depth_x, uint8_t bit_depth_y, uint8_t bit_depth_z, uint8_t bit_depth_w) {
  31.     return ((uint8_t)signed_) << SIGN_BIT | ((uint8_t)type) << FORMAT | bit_depth_x << BITS_X | bit_depth_y << BITS_Y | bit_depth_z << BITS_Z | bit_depth_w << BITS_W;
  32. }
  33.  
  34. inline uint32_t bits(uint32_t format) {
  35.     return ((format >> BITS_X) & 0x1f) + ((format >> BITS_Y) & 0x1f) + ((format >> BITS_Z) & 0x1f) + ((format >> BITS_W) & 0x1f);
  36. }
  37.  
  38. struct VertexBufferView {
  39.     typedef enum { MAX_CHANNELS = 16 };
  40.     struct Channel {
  41.         uint32_t format;
  42.         uint8_t semantic;
  43.         uint8_t stream;
  44.         uint8_t set;
  45.         bool instance;
  46.     } channels[MAX_CHANNELS];
  47.     uint32_t n_channels;
  48. };
  49.  
  50. struct IndexBufferView {
  51.     // either 2 or 4 depending on if index buffer is 32
  52.     uint8_t stride;
  53. };
  54.  
  55. struct RenderBufferApi
  56. {
  57.     typedef uint32_t Handle;
  58.  
  59.     typedef enum { VERTEX_BUFFER_VIEW, INDEX_BUFFER_VIEW } View;
  60.     typedef enum { STATIC, UPDATABLE } Validity;
  61.  
  62.     Handle (*create_buffer)(uint32_t size, Validity validity, View view, const void *view_desc, const void *data = nullptr);
  63.     void (*update_buffer)(Handle handle, uint32_t size, const void *data = nullptr);
  64.     void (*destroy_buffer)(Handle handle);
  65. }:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement