Skip to content

OpenGL Differences

Adam Gorski edited this page Aug 22, 2021 · 12 revisions

Key differences from OpenGL

There are a few key difference that make XFDraw from OpenGL. Obviously the first one is that its a software renderer.

Projection is handled internally

XFDraw uses a GLMatrix to store transform data. You do not need to multiply your vertex by a projection matrix. Interestingly, GLMatrix in not even a matrix.

Clipping is done via vec3's / Vector3's

XFDraw uses a vector3/vec3 as its gl_Position variable in the vertex shader.

Normalized World Coordinates

XFDraw does not use NWC. After the vertex shader is executed, the triangles are clipped either in a perspective camera view frustrum, a orthograpic (rectangular prism) frustrum or a blended one. At this stage they are still in 3D camera space. Finally they are transformed from 3D to 2D coordinates.

Color framebuffers are stored in byte4 format

To save memory bandwidth and improve bliting performance, XFDraw stores colors in BGRA format. While you can always store things in vec4 format and convert the values to BGRA afterwards before a blit operation, by default every demo utilizes byte4's.

Dedicated screenspace shaders

You do not need to render a quad for a screenspace effect. To improve performance, you can just use the dedicated screenspace shaders, which have extra features for performance. It is combined with multiple in support.

Texture sampling is done via exact coordinates. Not values ranging from 0 - 1

When you use the texture() function, it will return your data based of the exact coordinates of the texture.

Depthbuffer is encoded as dbuffer = farZ - trueDepth

This is done like this so it would be faster to clear the depth buffer.

Type differences

When working between your C# code and the shader code, many types are not exactly the same name. This was done so that the shader language was very similar to GLSL, but the C# side also was very similar to C#/Unity.

C++/GLSL Type Size (Bytes) C# Equivalent
byte4 4 Color4
int 4 int
float 4 float
int2 8 Not implemented
vec2 8 Vector2
vec3 12 Vector3
vec4 16 Vector4
mat3 36 Matrix3x3
mat4 64 Matrix4x4
GLMatrix 56/Auto Cast GLMatrix
sampler1D Managed GLBuffer
sampler2D Managed GLTexture
samplerCube Managed GLCubemap

The last three items are managed, meaning that they the references to the GL classes are kept and those buffers are only locked when the Draw/Pass command is issued. This prevents writing to a buffer while it is being resized. GLMatrix is auto cast to an internal type GLMat which is 56 bytes in size.

Keep in mind XFDraw SetValue() and AssignBuffer() do not perform type checking. They only perform size checking. This means that you can use Color4/byte4/int interchangeably when using SetValue() or AssignBuffer()
Clone this wiki locally