blob: 137a6d247197658d742427432953d1e62d7e000e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//==================================================================
//
// valueuniformreader.cpp - BGFX chain entry value mapper reader
//
//==================================================================
#include "valueuniformreader.h"
#include "entryuniform.h"
#include "valueuniform.h"
bgfx_entry_uniform* value_uniform_reader::read_from_value(const Value& value, const std::string &prefix, bgfx_uniform* uniform)
{
if (!validate_parameters(value, prefix))
{
return nullptr;
}
float values[4];
int count = 1;
if (value["value"].IsNumber())
{
values[0] = float(value["value"].GetDouble());
}
else
{
const Value& value_array = value["value"];
count = int(value_array.Size());
for (int i = 0; i < count; i++)
{
values[i] = float(value_array[i].GetDouble());
}
}
return new bgfx_value_uniform(uniform, values, count);
}
bool value_uniform_reader::validate_parameters(const Value& value, const std::string &prefix)
{
if (!READER_CHECK(value.HasMember("value"), "%sMust have string value 'value' (what value is being assigned?)\n", prefix)) return false;
if (!READER_CHECK(value["value"].IsArray() || value["value"].IsNumber(), "%sValue 'value' must be numeric or an array\n", prefix)) return false;
return true;
}
|