This commit is contained in:
2018-11-12 06:28:00 +07:00
parent e0e06dde9e
commit bb3245cb9e
8 changed files with 96 additions and 33 deletions

View File

@@ -454,7 +454,6 @@ namespace e2d
f32 range_far_ = 1.0f;
bool write_ = true;
compare_func func_ = compare_func::less;
u8 _pad[2] = {0};
};
class stencil_state final {
@@ -478,7 +477,6 @@ namespace e2d
stencil_op sfail_ = stencil_op::keep;
stencil_op zfail_ = stencil_op::keep;
compare_func func_ = compare_func::always;
u8 _pad[1] = {0};
};
class culling_state final {
@@ -491,7 +489,6 @@ namespace e2d
private:
culling_mode mode_ = culling_mode::ccw;
culling_face face_ = culling_face::back;
u8 _pad[2] = {0};
};
class blending_state final {
@@ -535,7 +532,6 @@ namespace e2d
blending_factor src_alpha_factor_ = blending_factor::one;
blending_factor dst_alpha_factor_ = blending_factor::zero;
blending_equation alpha_equation_ = blending_equation::add;
u8 _pad[1] = {0};
};
class capabilities_state final {
@@ -608,7 +604,6 @@ namespace e2d
sampler_wrap t_wrap_;
sampler_min_filter min_filter_;
sampler_mag_filter mag_filter_;
u8 _pad[4] = {0};
};
using property_value = stdex::variant<
@@ -669,7 +664,6 @@ namespace e2d
property_block properties_;
shader_ptr shader_;
state_block states_;
u8 _pad[4] = {0};
};
class material final {
@@ -713,7 +707,6 @@ namespace e2d
array<vertex_buffer_ptr, max_vertices_count> vertices_;
std::size_t vertices_count_ = 0;
topology topology_ = topology::triangles;
u8 _pad[7] = {0};
};
class swap_command final {
@@ -788,7 +781,6 @@ namespace e2d
f32 depth_value_ = 1.f;
u8 stencil_value_ = 0;
buffer clear_buffer_ = buffer::color_depth_stencil;
u8 _pad[2] = {0};
};
class target_command final {
@@ -804,13 +796,25 @@ namespace e2d
class viewport_command final {
public:
viewport_command() = default;
viewport_command(const b2u& rect) noexcept;
viewport_command& rect(const b2u& value) noexcept;
b2u& rect() noexcept;
const b2u& rect() const noexcept;
viewport_command() = delete;
viewport_command(const b2u& viewport_rect) noexcept;
viewport_command(const b2u& viewport_rect, const b2u& scissor_rect) noexcept;
viewport_command& viewport_rect(const b2u& value) noexcept;
viewport_command& scissor_rect(const b2u& value) noexcept;
viewport_command& scissoring(bool value) noexcept;
b2u& viewport_rect() noexcept;
b2u& scissor_rect() noexcept;
bool& scissoring() noexcept;
const b2u& viewport_rect() const noexcept;
const b2u& scissor_rect() const noexcept;
bool scissoring() const noexcept;
private:
b2u rect_;
b2u viewport_rect_ = b2u::zero();
b2u scissor_rect_ = b2u::zero();
bool scissoring_ = false;
};
using command_value = stdex::variant<
@@ -853,7 +857,6 @@ namespace e2d
bool npot_texture_supported = false;
bool depth_texture_supported = false;
bool render_target_supported = false;
u8 _pad[1] = {0};
};
public:
render(debug& d, window& w);

View File

@@ -22,6 +22,9 @@ namespace e2d
public:
vec2<T> position;
vec2<T> size;
public:
static const rect& zero() noexcept;
static const rect& unit() noexcept;
public:
rect() noexcept = default;
rect(const rect& other) noexcept = default;
@@ -40,6 +43,18 @@ namespace e2d
namespace e2d
{
template < typename T >
const rect<T>& rect<T>::zero() noexcept {
static const rect<T> zero{0, 0, 0, 0};
return zero;
}
template < typename T >
const rect<T>& rect<T>::unit() noexcept {
static const rect<T> unit{0, 0, 1, 1};
return unit;
}
template < typename T >
rect<T>::rect(T w, T h) noexcept
: size(w, h) {}

View File

@@ -220,7 +220,10 @@ namespace
the<render>().execute(render::command_block<64>()
.add_command(render::target_command(nullptr))
.add_command(render::viewport_command(the<window>().real_size()))
.add_command(render::clear_command()
.color_value(color::blue()))
.add_command(render::viewport_command(the<window>().real_size())
.scissor_rect(make_rect(v2u{100u}, the<window>().real_size() - 200u)))
.add_command(render::clear_command()
.color_value({1.f, 0.4f, 0.f, 1.f}))
.add_command(render::draw_command(material_, geometry_, rt_props_))

View File

@@ -298,7 +298,6 @@ namespace e2d
std::atomic<u32> frame_rate_{0};
std::atomic<u32> frame_count_{0};
std::atomic<u32> frame_rate_counter_{0};
u8 _pad[4] = {0};
};
//

View File

@@ -1049,20 +1049,52 @@ namespace e2d
// viewport_command
//
render::viewport_command::viewport_command(const b2u& rect) noexcept
: rect_(rect) {}
render::viewport_command::viewport_command(const b2u& viewport_rect) noexcept
: viewport_rect_(viewport_rect) {}
render::viewport_command& render::viewport_command::rect(const b2u& value) noexcept {
rect_ = value;
render::viewport_command::viewport_command(const b2u& viewport_rect, const b2u& scissor_rect) noexcept
: viewport_rect_(viewport_rect)
, scissor_rect_(scissor_rect)
, scissoring_(true) {}
render::viewport_command& render::viewport_command::viewport_rect(const b2u& value) noexcept {
viewport_rect_ = value;
return *this;
}
b2u& render::viewport_command::rect() noexcept {
return rect_;
render::viewport_command& render::viewport_command::scissor_rect(const b2u& value) noexcept {
scissor_rect_ = value;
scissoring_ = true;
return *this;
}
const b2u& render::viewport_command::rect() const noexcept {
return rect_;
render::viewport_command& render::viewport_command::scissoring(bool value) noexcept {
scissoring_ = value;
return *this;
}
b2u& render::viewport_command::viewport_rect() noexcept {
return viewport_rect_;
}
b2u& render::viewport_command::scissor_rect() noexcept {
return scissor_rect_;
}
bool& render::viewport_command::scissoring() noexcept {
return scissoring_;
}
const b2u& render::viewport_command::viewport_rect() const noexcept {
return viewport_rect_;
}
const b2u& render::viewport_command::scissor_rect() const noexcept {
return scissor_rect_;
}
bool render::viewport_command::scissoring() const noexcept {
return scissoring_;
}
//

View File

@@ -971,12 +971,26 @@ namespace e2d
render& render::execute(const viewport_command& command) {
E2D_ASSERT(main_thread() == std::this_thread::get_id());
const b2u vp = make_minmax_rect(command.rect());
const b2u viewport = make_minmax_rect(command.viewport_rect());
GL_CHECK_CODE(state_->dbg(), glViewport(
math::numeric_cast<GLint>(vp.position.x),
math::numeric_cast<GLint>(vp.position.y),
math::numeric_cast<GLsizei>(vp.size.x),
math::numeric_cast<GLsizei>(vp.size.y)));
math::numeric_cast<GLint>(viewport.position.x),
math::numeric_cast<GLint>(viewport.position.y),
math::numeric_cast<GLsizei>(viewport.size.x),
math::numeric_cast<GLsizei>(viewport.size.y)));
if ( command.scissoring() ) {
const b2u scissor = make_minmax_rect(command.scissor_rect());
GL_CHECK_CODE(state_->dbg(), glScissor(
math::numeric_cast<GLint>(scissor.position.x),
math::numeric_cast<GLint>(scissor.position.y),
math::numeric_cast<GLsizei>(scissor.size.x),
math::numeric_cast<GLsizei>(scissor.size.y)));
GL_CHECK_CODE(state_->dbg(), glEnable(GL_SCISSOR_TEST));
} else {
GL_CHECK_CODE(state_->dbg(), glDisable(GL_SCISSOR_TEST));
}
return *this;
}

View File

@@ -311,7 +311,6 @@ namespace e2d { namespace opengl
GLint size = 0;
GLint location = -1;
uniform_type type = uniform_type::floating_point;
u8 _pad[3] = {0};
public:
uniform_info(
str_hash nname,
@@ -329,7 +328,6 @@ namespace e2d { namespace opengl
GLint size = 0;
GLint location = -1;
attribute_type type = attribute_type::floating_point;
u8 _pad[3] = {0};
public:
attribute_info(
str_hash nname,

View File

@@ -24,7 +24,6 @@ namespace e2d
bool visible = true;
bool focused = true;
bool minimized = false;
char _pad[2];
public:
state(const v2u& size, str_view title, bool fullscreen)
: virtual_size(size)