root_function R_Handle
R_handle_zero(void) 
{
  R_Handle out = {0};
  return out;
}

root_function B32
R_handle_match(R_Handle a, R_Handle b)
{
  return (a.u64[0] == b.u64[0] &&
          a.u64[1] == b.u64[1] &&
          a.u64[2] == b.u64[2] &&
          a.u64[3] == b.u64[3]);
}

root_function B32
R_handle_is_zero(R_Handle handle)
{
  return R_handle_match(handle, R_handle_zero());
}

root_function U64 
R_bytes_per_pixel_from_tex2d_format(R_Tex2DFormat fmt)
{
  U64 result = 0;
  switch(fmt)
  {
    default:
    case R_Tex2DFormat_R8: {result = 1;} break;
    case R_Tex2DFormat_RGBA8: {result = 4;} break;
  }
  return result;
}

root_function R_Pass * 
R_pass_list_push(Arena *arena, R_PassList *list, R_PassKind kind)
{
  R_PassNode *node = PushArrayZero(arena, R_PassNode, 1);
  QueuePush(list->first, list->last, node);
  list->count += 1;
  R_Pass *pass = &node->v;
  pass->kind = kind;
  switch(kind)
  {
    default:{} break;
    case R_PassKind_UI: { pass->params_ui = PushArrayZero(arena, R_PassParams_UI, 1); } break;
  }
  
  return pass;
}

root_function void *
R_batch_list_push(Arena *arena, R_BatchList *list, U64 cap, U64 instance_size)
{
  void *result = 0;
  // TODO(anton): 
  // A batch is a collection of instances. We should make something
  // that checks so we can grow batches if possible, or makes a new batch if
  // the current batch is full.
  // Right now we just have a single batch and we should fit cap number of instances in it.
  R_Batch *batch = list->last;
  if(batch == 0)
  {
    batch = PushArrayZero(arena, R_Batch, 1);
    // v is just the collection of bytes for this batch.
    batch->v = PushArray(arena, U8, instance_size*cap);
    batch->instance_cap = cap;
    batch->byte_cap = instance_size*cap;
    QueuePush(list->first, list->last, batch);
    list->batch_count += 1;
  }
  
  // Catch full batch
  if(batch->instance_count >= cap)
  {
    break_debugger();
  }
  
  // Grab pointer to the memory that holds the new instance.
  // This is indexed by the current instance count (previous count)
  // and the size in bytes of the instance type.
  U64 instance_count = batch->instance_count;
  result = &batch->v[instance_count*instance_size];
  // Increment count afterwards
  batch->instance_count += 1;
  batch->byte_count += instance_size;
  list->instance_count += 1;
  list->byte_count += instance_size;
  
  return result;
}