2010 September 25 / j|d|a|v|i|s|@|c|a|r|l|e|t|o|n|.|e|d|u

Architecture

This page describes some of the internal structure of Bopagopa. It may be helpful to readers who are transitioning from Bopagopa Jr. to Bopagopa or who are implementing their own high-level graphics libraries atop OpenGL.

Each Bopagopa program possesses one or more Windows. In addition to various other data, each window possesses one Renderer2D and one Renderer3D.

The 2D renderer possesses a list of Body2Ds. These bodies must all be of the same "body type" — they must have the same numbers and kinds of uniform (per-body), attribute (per-vertex), and sampler (per-fragment) data. The renderer possesses a list of drawing options, which specify how the uniform, attribute, and sampler data contribute to the final drawing output. Some of these drawing options are simple flags, while others are strings of OpenGL Shader Language (GLSL) code. The renderer possesses an OpenGL shader program that has been automatically generated to match the exact body type and drawing options in use. Changing the body type or drawing options requires regeneration of the shader program — an expensive operation. On the other hand, the user can add and remove bodies at will, as long as they are of the correct body type.

The 3D renderer is similar to the 2D renderer but has more features. It possesses a list of Body3Ds of a single "body type" and a large set of drawing options. It possesses a Camera and zero or more Lights of various types; the lights emit their own GLSL code. It also possesses a shader program that has been automatically generated for its body type, drawing options, camera type, and lighting configuration. Changing any of these requires regeneration of the shader program. As in 2D, the user can add and remove bodies at will, as long as they are of the correct body type.

Bopagopa Jr.'s WindowJr manages to hide the 2D and 3D renderers from the user completely. It does so by choosing the body types and drawing options, and discouraging the user from altering them. The user is allowed to configure the camera and lights; Bopagopa Jr. pretends that they belong to the window.

Each Body2D and Body3D possesses a Mesh, zero or more Textures, and zero or more uniforms. The mesh specifies attribute (per-vertex) data, the textures specify sampler (per-fragment) data, and the uniforms specify uniform (per-body) data. Bopagopa Jr.'s Body2DJr and Body3DJr classes are wrappers for Body2D and Body3D that enforce Bopagopa Jr.'s drawing options.

A mesh object is a sequence of attribute arrays and a sequence of triangles. A triangle is a triple of integers that serve as indices into the attribute arrays. Intuitively, the attribute arrays specify data about the vertices of a triangular mesh, and the triangles specify how to form triangles among those vertices. In Bopagopa, the attribute arrays do not have any specific semantics; they can be used for any purpose, as determined by the renderer drawing options. In Bopagopa Jr., the attribute arrays for a Body2D's mesh must be 2D vertices and 2D texture coordinates, and the attribute arrays for a Body3D's mesh must be 3D vertices, 2D texture coordinates, and 3D normals.

A texture object is essentially a 2D grid of data that has been loaded into OpenGL. In Bopagopa, texture data can be used for almost any purpose, as determined by the renderer drawing options. In Bopagopa Jr. texture data can be used only to control the diffuse color of the surface.