forked from Hartmut/paradiso
minor update poking around why the texturing code is broken
This commit is contained in:
parent
833a18a3ee
commit
0eebe25ea9
6 changed files with 47 additions and 24 deletions
11
README.md
11
README.md
|
@ -1,10 +1,13 @@
|
|||
# ParadisSO - a minimal 2D rendering engine for
|
||||
# ParadisSO - a minimal 2D graphics engine
|
||||
|
||||
**ParadiSO** was conceived as a heavily stripped down version of my pixwerx engine. It is a minimalistic 2D graphics engine for educational purposes. It uses modern C++ and a datadriven design, but no ECS.
|
||||
|
||||
## Educational
|
||||
|
||||
* plenty of mix and match of concepts and paradigms to write expressive but concise code
|
||||
* math code is eager evaluation but constexpr to compensate overheads
|
||||
* it hides old-style APIs behind a renovated facade
|
||||
Some arguments for its educational side:
|
||||
|
||||
* mix and match of various concepts and paradigms to write expressive but concise code
|
||||
* heavily inspired by Rust code
|
||||
* math code is eager evaluation but `constexpr` to compensate overheads
|
||||
* hides old-style `C` APIs behind a renovated facade
|
||||
* it leans heavily on the STL and its algorithms
|
|
@ -56,9 +56,9 @@ struct Shader final {
|
|||
Shader&
|
||||
set_uniform_at_location(int location,
|
||||
uint32_t v); //!< sets a 32bit unsigned in a shader
|
||||
Shader&
|
||||
const Shader&
|
||||
set_uniform_at_location(int location,
|
||||
int32_t v); //!< sets a 32bit signed in a shader
|
||||
int32_t v) const; //!< sets a 32bit signed in a shader
|
||||
|
||||
/**
|
||||
* @brief retrieves the position of a uniform
|
||||
|
@ -80,7 +80,7 @@ struct Shader final {
|
|||
* sets data of the
|
||||
*/
|
||||
template <typename T>
|
||||
Shader& set_uniform(std::string const& name, T&& value) {
|
||||
const Shader& set_uniform(std::string const& name, T&& value) const {
|
||||
return set_uniform_at_location(uniform_location(name),
|
||||
std::forward<T>(value));
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ struct Sprite final {
|
|||
|
||||
static constexpr Sprite create() noexcept { return {}; }
|
||||
|
||||
Bitmap bitmap{};
|
||||
|
||||
Vector2<float> pivot{Vector2<float>::zero()};
|
||||
|
||||
std::array<std::uint32_t, 6> indices{0, 3, 2, 2, 1, 0};
|
||||
|
@ -57,6 +59,7 @@ struct Sprite final {
|
|||
};
|
||||
|
||||
ChangeCountType change_count{};
|
||||
|
||||
};
|
||||
} // namespace paradiso
|
||||
|
||||
|
|
|
@ -53,12 +53,6 @@ struct Renderer::impl {
|
|||
GL_TRUE == glIsVertexArray(vertex_array_obj);
|
||||
}
|
||||
|
||||
void bind_texture() {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
}
|
||||
|
||||
void unbind_texture() { glBindTexture(GL_TEXTURE_2D, 0); }
|
||||
|
||||
bool build(const Sprite& sprite) {
|
||||
// reset if the Renderer already in use
|
||||
|
@ -120,7 +114,15 @@ struct Renderer::impl {
|
|||
return ready();
|
||||
}
|
||||
|
||||
void update_texture(const Bitmap& image) {
|
||||
|
||||
void texture_bind() {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
}
|
||||
|
||||
void texture_unbind() { glBindTexture(GL_TEXTURE_2D, 0); }
|
||||
|
||||
void texture_update(const Bitmap& image) {
|
||||
if (GL_FALSE == glIsTexture(texture_id)) {
|
||||
glGenTextures(1, &texture_id);
|
||||
|
||||
|
@ -170,7 +172,12 @@ struct Renderer::impl {
|
|||
image.data.data()); // pointer
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
// glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void texture_release()
|
||||
{
|
||||
glDeleteTextures(1, &texture_id);
|
||||
}
|
||||
|
||||
void release() {
|
||||
|
@ -181,7 +188,8 @@ struct Renderer::impl {
|
|||
|
||||
glDeleteVertexArrays(1, &vertex_array_obj);
|
||||
|
||||
// glDeleteTextures(1, &texture_id);
|
||||
texture_release();
|
||||
|
||||
}
|
||||
|
||||
void just_draw(const Sprite& sprite) {
|
||||
|
@ -215,6 +223,7 @@ bool Renderer::draw(const Sprite& sprite, const Shader& shader) {
|
|||
// if interna are not ready or sprite has been altered - rebuild
|
||||
if (!impl_->ready() || sprite.change_count != impl_->change_count) {
|
||||
impl_->build(sprite);
|
||||
impl_->texture_update(sprite.bitmap);
|
||||
}
|
||||
|
||||
// render the sprite with the shader
|
||||
|
@ -222,8 +231,16 @@ bool Renderer::draw(const Sprite& sprite, const Shader& shader) {
|
|||
|
||||
shader.use();
|
||||
|
||||
shader.set_uniform("tex_color", 0u); // texture unit 0
|
||||
|
||||
impl_->texture_bind();
|
||||
|
||||
impl_->just_draw(sprite);
|
||||
|
||||
//Renderer::impl::fetch_errors(__PRETTY_FUNCTION__);
|
||||
|
||||
// impl_->texture_unbind();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,11 +177,11 @@ struct Shader::impl {
|
|||
// glUniform4fv(location,1,v.ptr());
|
||||
// }
|
||||
|
||||
void bind(int location, const float& v) { glUniform1f(location, v); }
|
||||
void bind(int location, const float& v) const { glUniform1f(location, v); }
|
||||
|
||||
void bind(int location, const uint32_t& i) { glUniform1ui(location, i); }
|
||||
void bind(int location, const uint32_t& i) const { glUniform1ui(location, i); }
|
||||
|
||||
void bind(int location, const int32_t& i) { glUniform1i(location, i); }
|
||||
void bind(int location, const int32_t& i) const { glUniform1i(location, i); }
|
||||
|
||||
// void bind(int location,const texture& v)
|
||||
// {
|
||||
|
@ -206,7 +206,7 @@ Shader& Shader::set_uniform_at_location(int location, uint32_t v) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Shader& Shader::set_uniform_at_location(int location, int32_t v) {
|
||||
const Shader& Shader::set_uniform_at_location(int location, int32_t v) const {
|
||||
impl_->bind(location, v);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ auto main() -> int {
|
|||
auto ctx = paradiso::Context{};
|
||||
|
||||
auto sprite = paradiso::Sprite{
|
||||
//
|
||||
.bitmap = checker_board_2
|
||||
};
|
||||
|
||||
auto renderer = paradiso::Renderer{};
|
||||
|
@ -102,9 +102,9 @@ auto main() -> int {
|
|||
while (window.update([&](auto& w) -> bool {
|
||||
|
||||
ctx.set_clearcolor(paradiso::RGBA::from_rgb(0xFF, green_slider, 0x00));
|
||||
ctx.set_viewport(paradiso::Rectangle{
|
||||
.size = w.client_size()
|
||||
});
|
||||
// ctx.set_viewport(paradiso::Rectangle{
|
||||
// .size = w.client_size()
|
||||
// });
|
||||
ctx.clear();
|
||||
|
||||
renderer.draw(sprite, shader);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue