| 1682 | } |
| 1683 | |
| 1684 | s32 parse_states(RenderState::State &state, const char *json) |
| 1685 | { |
| 1686 | // gui = { |
| 1687 | // states = { <-- You are here. |
| 1688 | // } |
| 1689 | // ... |
| 1690 | // } |
| 1691 | // |
| 1692 | // Possible cases: |
| 1693 | // a) "some_expr" = { state_a = b, state_b = c, ... } |
| 1694 | // Ignore, this is handled by parse_conditional_states(). |
| 1695 | // b) state_x = y |
| 1696 | |
| 1697 | TempAllocator4096 ta; |
| 1698 | JsonObject states(ta); |
| 1699 | RETURN_IF_ERROR(sjson::parse_object(states, json)); |
| 1700 | |
| 1701 | auto cur = json_object::begin(states); |
| 1702 | auto end = json_object::end(states); |
| 1703 | for (; cur != end; ++cur) { |
| 1704 | JSON_OBJECT_SKIP_HOLE(states, cur); |
| 1705 | |
| 1706 | // It must be a regular key/value state. |
| 1707 | if (cur->first == "rgb_write_enable") { |
| 1708 | bool enable = RETURN_IF_ERROR(sjson::parse_bool(states["rgb_write_enable"])); |
| 1709 | state._rgb_write_enable.set_value(enable); |
| 1710 | } else if (cur->first == "alpha_write_enable") { |
| 1711 | bool enable = RETURN_IF_ERROR(sjson::parse_bool(states["alpha_write_enable"])); |
| 1712 | state._alpha_write_enable.set_value(enable); |
| 1713 | } else if (cur->first == "depth_write_enable") { |
| 1714 | bool enable = RETURN_IF_ERROR(sjson::parse_bool(states["depth_write_enable"])); |
| 1715 | state._depth_write_enable.set_value(enable); |
| 1716 | } else if (cur->first == "depth_enable") { |
| 1717 | bool enable = RETURN_IF_ERROR(sjson::parse_bool(states["depth_enable"])); |
| 1718 | state._depth_enable.set_value(enable); |
| 1719 | } else if (cur->first == "blend_enable") { |
| 1720 | bool enable = RETURN_IF_ERROR(sjson::parse_bool(states["blend_enable"])); |
| 1721 | state._blend_enable.set_value(enable); |
| 1722 | } else if (cur->first == "depth_func") { |
| 1723 | DynamicString depth_func(ta); |
| 1724 | RETURN_IF_ERROR(sjson::parse_string(depth_func, states["depth_func"])); |
| 1725 | state._depth_func.set_value(name_to_depth_func(depth_func.c_str())); |
| 1726 | RETURN_IF_FALSE(SHADER_RESOURCE, state._depth_func.value() != DepthFunc::COUNT |
| 1727 | , _opts |
| 1728 | , "Unknown depth test: '%s'" |
| 1729 | , depth_func.c_str() |
| 1730 | ); |
| 1731 | } else if (cur->first == "blend_src") { |
| 1732 | DynamicString blend_src(ta); |
| 1733 | RETURN_IF_ERROR(sjson::parse_string(blend_src, states["blend_src"])); |
| 1734 | state._blend_src.set_value(name_to_blend_func(blend_src.c_str())); |
| 1735 | RETURN_IF_FALSE(SHADER_RESOURCE, state._blend_src.value() != BlendFunc::COUNT |
| 1736 | , _opts |
| 1737 | , "Unknown blend function: '%s'" |
| 1738 | , blend_src.c_str() |
| 1739 | ); |
| 1740 | } else if (cur->first == "blend_dst") { |
| 1741 | DynamicString blend_dst(ta); |
nothing calls this directly
no test coverage detected