Tuesday, September 27, 2011

MyGL

Part of The Rewrite Engine is a pseudo-abstraction layer that sits on top of OpenGL called MyGL. I originally wrote it as a fully namespaced library for software rendering within my Computer Graphics 1 course on rasterization theory and implementation. In that original form MyGL was essentially a hybrid of practices found within both Deprecated-OpenGL and DirectX. The overall library was a state machine much as OpenGL, having matrix stacks as well as a dedicated vertex buffer, color specification etc. The DirectX likeness came in the form of Object-Oriented practices being employed to manage this state. Vertices themselves were objects containing various state and helper functions. Colors were specified per-vertex,  model transformations resided with a specific "Model", and the view and projection matrices were part of an encapsulating Camera class that provided additional levels of abstraction and functionality for implementing different cameras.


MyGL made an appearance once more in VolTex and mRay, both projects created for my Computer Graphics 2 course the following quarter at RIT. This time however, OpenGL was involved from the start and a lot of the great work I did on my software renderer was scrapped in favor of a wrapper around the state machine that is the OpenGL API. In mRay MyGL served mainly as a way to allocate buffer space for the screen pixels and later blit that to the screen using OpenGL. In VolTex MyGL was more involved; it handled shader loading and management, Camera control, data packing for the 3D textures and various other functions that looked more like the hardware equivalents of the original software renderer I had started.

Fast-Forward to now, when I'm actually writing The Rewrite Engine, and MyGL is once again a large component. I'm doing all of my rendering through it rather than in native OpenGL, and at the moment I even handle window creation and context specification with it as well. Herein lies my current dilemma...

This isn't what I wanted MyGL to be! MyGL is and always was a graphics layer, not an OpenGL/Win32/X/Cocoa replacement. Over the past week or so I've been struggling to find a sweet spot with the code I have written so far. Sometimes I like the code I wrote to manage windows, sometimes I don't; same with context creation and management (minimizing, maximizing, sizing, etc.). I've finally decided that I truly don't like those elements of The Rewrite Engine, but that's not to say that they necessarily need to be rewritten. I've been toying with the idea of switching most of these issues to SFML or SDL 1.3, either of which would solve the issues. I tried to implement this into The Rewrite Engine last night only to find that I was writing generic ApplicationWindow classes that did nothing but wrap the functionality that these libraries already provided with little or no added benefit. Finally it dawned on me: If MyGL shouldn't be anything it's not, then neither should The Rewrite Engine! Engines should run regardless of the frame they are put in (within reason) and even in the most severe situations the added work to make the engine work in a frame that it was not intended for lies with the person adapting it, not with the person who built the engine. Window creation and and context management should be left out of the equation almost entirely. In other words, the Rewrite Engine should operate regardless of the window it's attached to, and by relation MyGL should operate regardless of what is controlling the underlying context, as long as the versions match up to MyGL's minimum requirements.

So that is where I am currently at. I'm staring at the shattered remains of my engine after trying about 5 different things over the last weekend only to find that I didn't like the outcome of any of them, with a completely different idea in my head now. With this new vision of what MyGL should be, I'm about to rearrange a lot of code. Sadly, this means I am technically rewriting this code, but I count this as slightly different, as it was never right to begin with this time.

So to summarize, the new MyGL library will be comprised of a wrapper around native OpenGL's rendering and buffering operations. Things like texture loading / manipulation, vertex buffers and indexing. Context creation and management will be handled by the windowing api used, and left entirely out of The Rewrite Engine. I'm also planning to bring MyGL back to the state-machine it once was, via a combination of data-driven design and object oriented practices. More on that later...

No comments:

Post a Comment