AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
State.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12//
   13// Created by alex2772 on 30.07.2018.
   14//
   15
   16#pragma once
   17
   18#include <tuple>
   19#include <cstdint>
   20#include "gl.h"
   21#include "AUI/Views.h"
   22
   23
   24// comment this define in order to debug state machine cache failures
   25#define SO_STATE
   26
   27namespace gl {
   31    class API_AUI_VIEWS State {
   32    private:
   33        State();
   34        ~State();
   35        State(const State&) = delete;
   36        template <int K, typename F, typename... Args>
   37        inline static void impl(F functor, Args... args) {
   38#ifdef SO_STATE
   39            static std::tuple<Args...> prevState;
   40            std::tuple<Args...> state(args...);
   41            if (prevState != state) {
   42                prevState = state;
   43                functor(args...);
   44            }
   45#else
   46            functor(args...);
   47#endif
   48        };
   49    public:
   50        static void bindTexture(GLenum mode, GLuint texture);
   51        static void activeTexture(uint8_t index);
   52        static void useProgram(GLuint program);
   53        static void bindFramebuffer(GLenum type, GLuint framebuffer);
   54        static void bindVertexArray(GLuint handle);
   55    };
   56}
   57
   58