<commit_before>#pragma once

#include <stack>

#include "gl_resources.h"
#include "texture.h"

namespace asdf
{
    struct gl_state_t
    {
        bool initialized = false;

        std::vector<std::string> gl_extensions;
        GLint max_uniform_components = 0;
        size_t highest_glsl_version = 0;

        GLuint current_vao = 0;
        GLuint current_shader = 0;
        //GLuint current_framebuffer = 0;

        std::stack<std::pair<GLuint, gl_viewport_t>> fbo_stack;
        inline GLuint current_framebuffer() const { return fbo_stack.top().first; }
        inline gl_viewport_t const& current_viewport() const { return fbo_stack.top().second; };

        std::array<GLuint, gl_buffer_target_count> current_buffers;
        
        gl_state_t(){init_openGL();}
        void init_openGL();

        void bind(vao_t const&);
        void bind(std::shared_ptr<shader_t> const& shader);
        void bind(framebuffer_t const&);
        void bind(render_target_t const&);

        void bind(gl_buffer_object_t const&);

        GLuint current_vbo() const { return current_buffers[gl_array_buffer]; }

        void unbind_vao();
        void unbind_vbo();
        void unbind_fbo();
        void unbind_render_target();
        void unbind_shader();

        void push_fbo(GLuint fbo_id, gl_viewport_t const&);
        void push_fbo(framebuffer_t const& fbo, gl_viewport_t const&);
        void push_fbo(GLuint fbo_id, GLint x, GLint y, GLsizei width, GLsizei height);
        void push_fbo(framebuffer_t const&, GLint x, GLint y, GLsizei width, GLsizei height);
        void pop_fbo();

        void buffer_data(gl_buffer_object_t const& buffer, GLsizeiptr size, const GLvoid * data);
        void init_render_target(framebuffer_t const&, texture_t const&);

        bool assert_sync(); //ensures the values here are sync'd with openGL
    };

    struct gl_state_proxy_t
    {
        gl_state_proxy_t(){}

        gl_state_t* operator->();
    };

    size_t get_highest_glsl_ver();

    extern gl_state_proxy_t GL_State;


    struct scoped_fbo_t
    {
        scoped_fbo_t(GLuint fbo_id, GLint x, GLint y, GLsizei width, GLsizei height)
        {
            GL_State->push_fbo(fbo_id, x, y, width, height);
        }

        scoped_fbo_t(framebuffer_t const& fbo, GLint x, GLint y, GLsizei width, GLsizei height)
        {
            GL_State->push_fbo(fbo, x, y, width, height);
        }

        scoped_fbo_t(framebuffer_t const& fbo, gl_viewport_t v)
        {
            GL_State->push_fbo(fbo, v);
        }

        ~scoped_fbo_t()
        {
            GL_State->pop_fbo();
        }

        DELETE_COPY_ASSIGNMENT_MOVE(scoped_fbo_t);
    };

    struct scoped_render_target_t : scoped_fbo_t
    {
        scoped_render_target_t(render_target_t const& r)
        : scoped_fbo_t(r.fbo.id, 0, 0, r.texture.halfwidth, r.texture.halfheight)
        {
        }

        ~scoped_render_target_t() = default;

        DELETE_COPY_ASSIGNMENT_MOVE(scoped_render_target_t);
    };
}<commit_msg>minor fix<commit_after>#pragma once

#include <stack>

#include "gl_resources.h"
#include "texture.h"

namespace asdf
{
    struct gl_state_t
    {
        bool initialized = false;

        std::vector<std::string> gl_extensions;
        GLint max_uniform_components = 0;
        size_t highest_glsl_version = 0;

        GLuint current_vao = 0;
        GLuint current_shader = 0;
        //GLuint current_framebuffer = 0;

        std::stack<std::pair<GLuint, gl_viewport_t>> fbo_stack;
        inline GLuint current_framebuffer() const { return fbo_stack.top().first; }
        inline gl_viewport_t const& current_viewport() const { return fbo_stack.top().second; };

        std::array<GLuint, gl_buffer_target_count> current_buffers;
        
        gl_state_t(){init_openGL();}
        void init_openGL();

        void bind(vao_t const&);
        void bind(std::shared_ptr<shader_t> const& shader);
        void bind(framebuffer_t const&);
        void bind(render_target_t const&);

        void bind(gl_buffer_object_t const&);

        GLuint current_vbo() const { return current_buffers[gl_array_buffer]; }

        void unbind_vao();
        void unbind_vbo();
        void unbind_fbo();
        void unbind_render_target();
        void unbind_shader();

        void push_fbo(GLuint fbo_id, gl_viewport_t const&);
        void push_fbo(framebuffer_t const& fbo, gl_viewport_t const&);
        void push_fbo(GLuint fbo_id, GLint x, GLint y, GLsizei width, GLsizei height);
        void push_fbo(framebuffer_t const&, GLint x, GLint y, GLsizei width, GLsizei height);
        void pop_fbo();

        void buffer_data(gl_buffer_object_t const& buffer, GLsizeiptr size, const GLvoid * data);
        void init_render_target(framebuffer_t const&, texture_t const&);

        bool assert_sync(); //ensures the values here are sync'd with openGL
    };

    struct gl_state_proxy_t
    {
        gl_state_proxy_t(){}

        gl_state_t* operator->();
    };

    size_t get_highest_glsl_ver();

    extern gl_state_proxy_t GL_State;


    struct scoped_fbo_t
    {
        scoped_fbo_t(GLuint fbo_id, GLint x, GLint y, GLsizei width, GLsizei height)
        {
            GL_State->push_fbo(fbo_id, x, y, width, height);
        }

        scoped_fbo_t(framebuffer_t const& fbo, GLint x, GLint y, GLsizei width, GLsizei height)
        {
            GL_State->push_fbo(fbo, x, y, width, height);
        }

        scoped_fbo_t(framebuffer_t const& fbo, gl_viewport_t v)
        {
            GL_State->push_fbo(fbo, v);
        }

        ~scoped_fbo_t()
        {
            GL_State->pop_fbo();
        }

        DELETE_COPY_ASSIGNMENT_MOVE(scoped_fbo_t);
    };

    struct scoped_render_target_t : scoped_fbo_t
    {
        scoped_render_target_t(render_target_t const& r)
        : scoped_fbo_t(r.fbo.id, 0, 0, r.texture.width, r.texture.height)
        {
        }

        ~scoped_render_target_t() = default;

        DELETE_COPY_ASSIGNMENT_MOVE(scoped_render_target_t);
    };
}
{'fraction_non_alphanumeric': 0.0967741935483871, 'fraction_numerical': 0.002327901563019621, 'mean_word_length': 2.6147836538461537, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842137', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2068, 'n_words': 423}