Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: I'm trying to render a triangle

  1. #11
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    435
    Quote Originally Posted by DragonautX View Post
    How would a redundant state change filtering system work?
    somehow like this:
    Code cpp:
    /* describe the current gl state completely */
    struct RenderState
    {
        GLuint program_used, vao_used, xfb_used, etcpp;
        bool depth_testing, culling, wireframe_mode, blending, etc;
    };
     
     
    class RenderState_Manager
    {
    private:
        RenderState current_state;
     
    public:
     
        void SetNewState(const RenderState& state)
        {
            if (state.depth_testing != current_state.depth_testing)
            {
                /* change state */
                state.depth_testing ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
            }
     
            /* ... do the same for each remaining GL state accordingly ... */
     
            /* when everything is set, "cache" the current state */
            current_state = state;
        }
     
    };

    more advanced way would be to sort the states in a way that allows you to minimize the number of different states needed to draw everything.
    Last edited by john_connor; 11-15-2017 at 12:54 AM.

  2. #12
    Intern Newbie
    Join Date
    Mar 2017
    Posts
    47
    That's a nice idea, thanks. So basically, for any requested state, check if that state is already set, and if not, then set it. At first, I'd think it think it'd be less efficient since you may do 2 operations (conditional check, then possible state setting), but I can see how this can actually be more efficient if the client and server are connected via a slow network and a repetitive state setting function can take more time than just checking state in the client.

    Sorting the states is also a nice idea. Maybe if I had two parts of my code that drew pure triangles (they'd just differ by what's passed to the DrawArrays command), and one part that draws a square, I could put the two triangle code snippets together and only bind a triangle VAO once, and put the square snippet afterwards. Seems less flexible than the filtering system, but it's still interesting. I'll think about trying the filtering system in the future. Anyways, thanks for the help.

  3. #13
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    435
    you may want to check that out:
    https://www.sfml-dev.org/documentati...nderStates.php
    https://www.sfml-dev.org/documentati...57b29583556f39

    consider each renderstate as "key value" in a std::map<...> or just an array of these, each state has its "bunch of drawcalls" (batch), by sorting a new drawcall (mesh) to existing states, you can avoid setting a particular state twice (or multiple times). a new drawcall (that is the arguments of any glDraw*(...)) can also be "packed" into structures, take a look at that:
    https://sites.google.com/site/john87.../draw-commands

    by the way:
    in some of my examples i do explicitly "unbind" everything each frame, i do that to make it clear what changes have been made and how to reverse them, not for performace-reasons, but to make the code flow more "apparent" or easier to understand for beginners .. (i hope) maybe i'll comment them out soon ..
    Last edited by john_connor; 11-15-2017 at 05:35 PM.

  4. #14
    Intern Newbie
    Join Date
    Mar 2017
    Posts
    47
    I like the idea. Had to think about it for a bit. So you're saying like have some form of list of renderstates, and somehow associate these renderstates with certain draw calls. Then somehow write a function that says something like, "Given a renderstate, do all the draw calls associated with it." Which can be considered like a batch drawing command. Packing drawing arguments is creative too, I've seen that in Windows API a lot, esp. with creating windows.

    I'll keep a note of SFML and your google site. Heard of SFML, but wanted to go very low-level, so went for OpenGL. And it'd be cool to look at your site to see how other people code OpenGL. Anyways, thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •