mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
rename render_state to capabilities_state
This commit is contained in:
@@ -69,9 +69,6 @@ namespace e2d
|
||||
|
||||
class vertex_declaration final {
|
||||
public:
|
||||
constexpr static std::size_t max_attribute_name = 128;
|
||||
constexpr static std::size_t max_attribute_count = 16;
|
||||
|
||||
enum class attribute_type : u8 {
|
||||
signed_byte,
|
||||
unsigned_byte,
|
||||
@@ -82,7 +79,7 @@ namespace e2d
|
||||
|
||||
class attribute_info final {
|
||||
public:
|
||||
char name[max_attribute_name] = {0};
|
||||
str name;
|
||||
std::size_t rows = 0;
|
||||
std::size_t columns = 0;
|
||||
std::size_t stride = 0;
|
||||
@@ -92,8 +89,8 @@ namespace e2d
|
||||
attribute_info() noexcept;
|
||||
~attribute_info() noexcept;
|
||||
|
||||
attribute_info(const attribute_info&) noexcept;
|
||||
attribute_info& operator=(const attribute_info&) noexcept;
|
||||
attribute_info(const attribute_info&);
|
||||
attribute_info& operator=(const attribute_info&);
|
||||
|
||||
attribute_info(
|
||||
str_view name,
|
||||
@@ -109,11 +106,11 @@ namespace e2d
|
||||
vertex_declaration() noexcept;
|
||||
~vertex_declaration() noexcept;
|
||||
|
||||
vertex_declaration(const vertex_declaration&) noexcept;
|
||||
vertex_declaration& operator=(const vertex_declaration&) noexcept;
|
||||
vertex_declaration(const vertex_declaration&);
|
||||
vertex_declaration& operator=(const vertex_declaration&);
|
||||
|
||||
template < typename T >
|
||||
vertex_declaration& add_attribute(str_view name) noexcept;
|
||||
vertex_declaration& add_attribute(str_view name);
|
||||
vertex_declaration& normalized() noexcept;
|
||||
|
||||
vertex_declaration& skip_bytes(
|
||||
@@ -124,12 +121,13 @@ namespace e2d
|
||||
std::size_t rows,
|
||||
std::size_t columns,
|
||||
attribute_type type,
|
||||
bool normalized) noexcept;
|
||||
bool normalized);
|
||||
|
||||
const attribute_info& attribute(std::size_t i) const noexcept;
|
||||
std::size_t attribute_count() const noexcept;
|
||||
std::size_t vertex_size() const noexcept;
|
||||
private:
|
||||
constexpr static std::size_t max_attribute_count = 16;
|
||||
array<attribute_info, max_attribute_count> attributes_;
|
||||
std::size_t attribute_count_ = 0;
|
||||
std::size_t vertex_size_ = 0;
|
||||
@@ -287,6 +285,14 @@ namespace e2d
|
||||
};
|
||||
using vertex_buffer_ptr = std::shared_ptr<vertex_buffer>;
|
||||
|
||||
//
|
||||
// render_state
|
||||
//
|
||||
|
||||
class render_state final : private noncopyable {
|
||||
public:
|
||||
};
|
||||
|
||||
//
|
||||
// render
|
||||
//
|
||||
@@ -393,20 +399,6 @@ namespace e2d
|
||||
u8 _pad[2] = {0};
|
||||
};
|
||||
|
||||
class render_state {
|
||||
public:
|
||||
render_state& culling(bool enable) noexcept;
|
||||
render_state& blending(bool enable) noexcept;
|
||||
render_state& depth_test(bool enable) noexcept;
|
||||
render_state& stencil_test(bool enable) noexcept;
|
||||
private:
|
||||
friend class render;
|
||||
bool culling_ = false;
|
||||
bool blending_ = false;
|
||||
bool depth_test_ = false;
|
||||
bool stencil_test_ = false;
|
||||
};
|
||||
|
||||
class stencil_state {
|
||||
public:
|
||||
stencil_state& write(u8 mask) noexcept;
|
||||
@@ -457,6 +449,20 @@ namespace e2d
|
||||
blending_color_mask color_mask_ = blending_color_mask::rgba;
|
||||
u8 _pad[1] = {0};
|
||||
};
|
||||
|
||||
class capabilities_state {
|
||||
public:
|
||||
capabilities_state& culling(bool enable) noexcept;
|
||||
capabilities_state& blending(bool enable) noexcept;
|
||||
capabilities_state& depth_test(bool enable) noexcept;
|
||||
capabilities_state& stencil_test(bool enable) noexcept;
|
||||
private:
|
||||
friend class render;
|
||||
bool culling_ = false;
|
||||
bool blending_ = false;
|
||||
bool depth_test_ = false;
|
||||
bool stencil_test_ = false;
|
||||
};
|
||||
public:
|
||||
render(debug& d, window& w);
|
||||
~render() noexcept final;
|
||||
@@ -499,10 +505,10 @@ namespace e2d
|
||||
render& set_viewport(u32 x, u32 y, u32 w, u32 h) noexcept;
|
||||
|
||||
render& set_depth_state(const depth_state& ds) noexcept;
|
||||
render& set_render_state(const render_state& rs) noexcept;
|
||||
render& set_stencil_state(const stencil_state& ss) noexcept;
|
||||
render& set_culling_state(const culling_state& cs) noexcept;
|
||||
render& set_blending_state(const blending_state& bs) noexcept;
|
||||
render& set_capabilities_state(const capabilities_state& cs) noexcept;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace e2d
|
||||
{
|
||||
template < typename T >
|
||||
vertex_declaration& vertex_declaration::add_attribute(str_view name) noexcept {
|
||||
vertex_declaration& vertex_declaration::add_attribute(str_view name) {
|
||||
E2D_UNUSED(name);
|
||||
static_assert(sizeof(T) == 0, "not implemented for this type");
|
||||
return *this;
|
||||
@@ -22,7 +22,7 @@ namespace e2d
|
||||
|
||||
#define DEFINE_ADD_ATTRIBUTE_SPECIALIZATION(t, rows, columns, type)\
|
||||
template <>\
|
||||
inline vertex_declaration& vertex_declaration::add_attribute<t>(str_view name) noexcept {\
|
||||
inline vertex_declaration& vertex_declaration::add_attribute<t>(str_view name) {\
|
||||
return add_attribute(name, (rows), (columns), attribute_type::type, false);\
|
||||
}
|
||||
|
||||
|
||||
@@ -109,9 +109,9 @@ namespace e2d
|
||||
vertex_declaration::attribute_info::~attribute_info() noexcept = default;
|
||||
|
||||
vertex_declaration::attribute_info::attribute_info(
|
||||
const attribute_info&) noexcept = default;
|
||||
const attribute_info&) = default;
|
||||
vertex_declaration::attribute_info& vertex_declaration::attribute_info::operator=(
|
||||
const attribute_info&) noexcept = default;
|
||||
const attribute_info&) = default;
|
||||
|
||||
vertex_declaration::attribute_info::attribute_info(
|
||||
str_view nname,
|
||||
@@ -120,16 +120,12 @@ namespace e2d
|
||||
std::size_t nstride,
|
||||
attribute_type ntype,
|
||||
bool nnormalized)
|
||||
: rows(nrows)
|
||||
: name(nname)
|
||||
, rows(nrows)
|
||||
, columns(ncolumns)
|
||||
, stride(nstride)
|
||||
, type(ntype)
|
||||
, normalized(nnormalized) {
|
||||
bool name_format_success = strings::format_nothrow(
|
||||
name, E2D_COUNTOF(name), nullptr, "%0", nname);
|
||||
E2D_UNUSED(name_format_success);
|
||||
E2D_ASSERT(name_format_success);
|
||||
}
|
||||
, normalized(nnormalized) {}
|
||||
|
||||
std::size_t vertex_declaration::attribute_info::row_size() const noexcept {
|
||||
return attribute_element_size(type) * columns;
|
||||
@@ -143,9 +139,9 @@ namespace e2d
|
||||
vertex_declaration::~vertex_declaration() noexcept = default;
|
||||
|
||||
vertex_declaration::vertex_declaration(
|
||||
const vertex_declaration&) noexcept = default;
|
||||
const vertex_declaration&) = default;
|
||||
vertex_declaration& vertex_declaration::operator=(
|
||||
const vertex_declaration&) noexcept = default;
|
||||
const vertex_declaration&) = default;
|
||||
|
||||
vertex_declaration& vertex_declaration::normalized() noexcept {
|
||||
E2D_ASSERT(attribute_count_ > 0);
|
||||
@@ -163,7 +159,7 @@ namespace e2d
|
||||
std::size_t rows,
|
||||
std::size_t columns,
|
||||
attribute_type type,
|
||||
bool normalized) noexcept
|
||||
bool normalized)
|
||||
{
|
||||
E2D_ASSERT(attribute_count_ < attributes_.size());
|
||||
const std::size_t stride = vertex_size_;
|
||||
@@ -215,7 +211,7 @@ namespace e2d
|
||||
const vertex_declaration::attribute_info& l,
|
||||
const vertex_declaration::attribute_info& r) noexcept
|
||||
{
|
||||
return !std::strcmp(l.name, r.name)
|
||||
return l.name == r.name
|
||||
&& l.rows == r.rows
|
||||
&& l.columns == r.columns
|
||||
&& l.stride == r.stride
|
||||
@@ -254,22 +250,22 @@ namespace e2d
|
||||
// render_state
|
||||
//
|
||||
|
||||
render::render_state& render::render_state::culling(bool enable) noexcept {
|
||||
render::capabilities_state& render::capabilities_state::culling(bool enable) noexcept {
|
||||
culling_ = enable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
render::render_state& render::render_state::blending(bool enable) noexcept {
|
||||
render::capabilities_state& render::capabilities_state::blending(bool enable) noexcept {
|
||||
blending_ = enable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
render::render_state& render::render_state::depth_test(bool enable) noexcept {
|
||||
render::capabilities_state& render::capabilities_state::depth_test(bool enable) noexcept {
|
||||
depth_test_ = enable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
render::render_state& render::render_state::stencil_test(bool enable) noexcept {
|
||||
render::capabilities_state& render::capabilities_state::stencil_test(bool enable) noexcept {
|
||||
stencil_test_ = enable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <enduro2d/core/debug.hpp>
|
||||
#include <enduro2d/core/window.hpp>
|
||||
#include <enduro2d/core/render.hpp>
|
||||
#include <enduro2d/core/window.hpp>
|
||||
|
||||
#define E2D_RENDER_MODE_NONE 1
|
||||
#define E2D_RENDER_MODE_OPENGL 2
|
||||
|
||||
@@ -704,7 +704,7 @@ namespace
|
||||
for ( std::size_t i = 0, e = decl.attribute_count(); i < e; ++i ) {
|
||||
const vertex_declaration::attribute_info& ai = decl.attribute(i);
|
||||
GL_CHECK_CODE(debug, glBindAttribLocation(
|
||||
program, location, ai.name));
|
||||
program, location, ai.name.c_str()));
|
||||
location += math::numeric_cast<GLuint>(ai.rows);
|
||||
}
|
||||
return true;
|
||||
@@ -1239,18 +1239,6 @@ namespace e2d
|
||||
return *this;
|
||||
}
|
||||
|
||||
render& render::set_render_state(const render_state& bs) noexcept {
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_CULL_FACE, bs.culling_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_BLEND, bs.blending_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_DEPTH_TEST, bs.depth_test_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_STENCIL_TEST, bs.stencil_test_));
|
||||
return *this;
|
||||
}
|
||||
|
||||
render& render::set_stencil_state(const stencil_state& ss) noexcept {
|
||||
GL_CHECK_CODE(state_->debug_, glStencilMask(
|
||||
math::numeric_cast<GLuint>(ss.write_)));
|
||||
@@ -1294,6 +1282,18 @@ namespace e2d
|
||||
(enum_to_number(bs.color_mask_) & enum_to_number(blending_color_mask::a)) != 0));
|
||||
return *this;
|
||||
}
|
||||
|
||||
render& render::set_capabilities_state(const capabilities_state& cs) noexcept {
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_CULL_FACE, cs.culling_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_BLEND, cs.blending_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_DEPTH_TEST, cs.depth_test_));
|
||||
GL_CHECK_CODE(state_->debug_, gl_enable_or_disable(
|
||||
GL_STENCIL_TEST, cs.stencil_test_));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST_CASE("render"){
|
||||
REQUIRE(vd.vertex_size() == 8);
|
||||
|
||||
vertex_declaration::attribute_info ai = vd.attribute(0);
|
||||
REQUIRE(!std::strcmp(ai.name, "hello"));
|
||||
REQUIRE(ai.name == "hello");
|
||||
REQUIRE(ai.columns == 2);
|
||||
REQUIRE(ai.stride == 0);
|
||||
REQUIRE(ai.type == vertex_declaration::attribute_type::floating_point);
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("render"){
|
||||
REQUIRE(vd.vertex_size() == 14);
|
||||
|
||||
vertex_declaration::attribute_info ai2 = vd.attribute(1);
|
||||
REQUIRE(!std::strcmp(ai2.name, "world"));
|
||||
REQUIRE(ai2.name == "world");
|
||||
REQUIRE(ai2.columns == 1);
|
||||
REQUIRE(ai2.stride == 12);
|
||||
REQUIRE(ai2.type == vertex_declaration::attribute_type::unsigned_short);
|
||||
|
||||
Reference in New Issue
Block a user