Is this an overkill?

I've been rewrapping the entire OpenGL 4.5 api inside classes.
Long story short: Is it worth it? Will somebody find it useful?
Long story long:
Here's my testcase (which shows api and such): http://pastebin.com/wDXbuEyd
The multiple iterations are simply used to calculate performance.
This (custom, huge, and procedurally generated from glcorearb.h) header is also required: http://pastebin.com/rsE92pLP (Implementation is somewhere else, this is a library in my project).

For the more curious readers, the shader is a really simple 1-by-1 equivalent of the CPU version, as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#version 430
layout (local_size_x=1, local_size_y=1) in;
layout(std430, binding = 0) buffer Destination {
	float result[];
} dst;
layout(std430, binding = 1) buffer SourceA {
	float data[];
} srca;
layout(std430, binding = 2) buffer SourceB {
	float data[];
} srcb;
uniform uint length;
void main() {
	for(uint i = 0; i < length; ++i)
		dst.result[i] = sqrt((sqrt(srca.data[i]) * sqrt(srcb.data[i])) *
			sqrt(srca.data[i]*srcb.data[i]));
}


Another note about the available customizations:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* These are all the configuration's defines:
 *
 * Debug Only (NDEBUG not defined):
 *		GLPP_DEBUG_NO_COUNT
 *			Avoid counting OpenGL objects
 *		GLPP_DEBUG_COUNT_ALL
 *			Count all OpenGL objects and interfaces
 *		Neither one:
 *			Count all OpenGL objects
 * Release Only (NDEBUG defined):
 * 
 * Debug/Release Indipendent:
 *		GLPP_NO_EXCEPTIONS
 *			Do not throw exception or check glError every time a function is called.
 *			This also does not throw an exception in case the context is destroyed.
 *			You may want to define GLPP_NO_KEEP_CONTEXT too, for perfomance reasons.
 *		GLPP_NO_KEEP_CONTEXT
 *			Do not store context pointer state in OpenGL objects.
 *			Note: Also defines GLPP_NO_CHECK_CONTEXT.
 *		GLPP_NO_CHECK_CONTEXT
 *			Do not check for context validity every time a function is called
 *		GLPP_NO_CHECK_FUNCTIONS
 *			Do not check for functions to be in the current context every time a
 *			function is called. Only works for OpenGL objects.
 *			Recommended for Release builds only.
 * 
 */


Back to the question: Is this an overkill?
All the required items in the snippet over do work, and the test's results are correct, but I had to change the implementation multiple times (context-checking, function-checking, error-checking) and I feel really tired about going through code I already changed to make other changes.
Side note: -- what the hell AMD? I've tried doing the above test using a lot of memory, and you let the gfx card allocate that much memory. Not only it couldn't allocate 0xFFFFFF * 12 bytes of memory (3x67mb contiguous vram chunks), but the drivers also crashed, and the PC froze! Error checking anywhere?

In case an error happens, an exception is correctly thrown, along with a (sadly) english-only description.
Localization not a priority right now, but GLPP_NO_EXCEPTIONS disables exception-throwing and all internal glError calls, even in form of GLContext::CheckErrors.
GLPP_NO_KEEP_CONTEXT disables reference counting, and only stores a plain pointer to the GLContext and GLFunctions.
GLPP_NO_CHECK_CONTEXT disables context checking. Basically only useful if GLPP_NO_KEEP_CONTEXT is disabled.
In case the context has been deleted, GLPP_CONTEXT_DELETED is the error-code.
GLPP_NO_CHECK_FUNCTIONS checks for functions before calling, and throws GLPP_NOT_IN_CONTEXT as error-code.
Last edited on
I don't really think it should be done, it's more on the overkill side. You're just adding unnecessary overhead if anything. Just create a generic renderer interface if you want to create a 3D app. It will ease your porting later, too. You'll avoid GL-specific details.

I mean, if it's just for shits and giggles it's fine.
Last edited on
When I used OpenGL I created classes to wrap things like glUseProgram with RAII semantics:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace gl {
    class useProgram {
    public:
        explicit useProgram(GLint id)
        {
            glUseProgram(id);
            m_current_program = this;
        }

        ~useProgram()
        {
            if (m_current_program == this) {
                glUseProgram(0);
                m_current_program = nullptr;
            }
        }
    private:
        static useProgram* m_current_program;
    };

    useProgram* useProgram::m_current_program = nullptr;
}

// ...

void foo(GLint program_a, GLint program_b)
{
    gl::useProgram a(program_a); // Bind program A.
    gl::useProgram b(program_b); // Bind program B, unbinding program A.
    // ...
    // A's destructor does nothing because A is not the current program. B will be unbound in its destructor.
}

Of course, this is not thread-safe though it's trivial to make it such, but IIRC OpenGL contexts are not thread-safe so you wouldn't have two threads calling glUseProgram anyway.
Last edited on
Topic archived. No new replies allowed.