The OpenGL-specific parts of the hardware renderer are partially separated into the OpenGL backend. Ideally this would allow easier adaptation to other 3D rendering APIs by just implementing a new backend for it.
OpenGL backend functions:
void Init (void)
Loads the OpenGL library. Some of the internal gl function pointers are loaded here and the rest are loaded in OglSdlSurface
. TODO why?
void SetTexture (GLMipmap_t *TexInfo)
TexInfo
becomes the current texture, used in future draw calls. If NULL, then a white texture is used. The texture will be uploaded to the GPU if it has not been yet. The texture will be converted to a format usable by the GPU if required.
void UpdateTexture (GLMipmap_t *TexInfo)
Updated data from TexInfo
is uploaded to the GPU. (TexInfo
is left as the current texture?) The texture will be converted to a format usable by the GPU if required.
void DeleteTexture (GLMipmap_t *TexInfo)
TexInfo
is deleted from the GPU.
void ClearMipMapCache (void)
All textures are deleted from the GPU.
INT32 GetTextureUsed (void)
Returns the number of bytes used by the textures uploaded to the GPU.
void SetPalette (RGBA_t *ppal)
Sets the palette used in textures. All textures are also deleted from the GPU since they still have the old colors.
void SetSpecialState (hwdspecialstate_t IdState, INT32 Value)
Some states are set through this function: model lighting, shader/fixed-function toggle and texture filtering.
void GClipRect (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip)
Sets the viewport coordinates on the screen and also the depth of the near clipping plane.
void SetTransform (FTransform *ptransform)
Sets the current projection and modelview matrices according to the parameters in ptransform
. (If NULL then some simple UI drawing matrices are set?)
void SetBlend (FBITFIELD PolyFlags)
The current rendering state is set according to PolyFlags
. (Most of the time the state is included into the Draw* calls instead)
void ClearBuffer (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor)
Clears the color buffer with ClearColor
if ColorMask
is set. Clears the depth buffer if DepthMask
is set. (The PF_Occlude flag is set to DepthMask
?)
void Draw2DLine (F2DCoord *v1, F2DCoord *v2, RGBA_t Color)
Draws a 2D line to the screen. (Used for drawing the devmode map)
void DrawPolygon (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags)
Draws a 3D triangle fan to the screen with properties from pSurf
and PolyFlags
. The vertex data is in pOutVerts
and iNumPts
contains the number of vertices.
void DrawIndexedTriangles (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, UINT32 *IndexArray)
Draws 3D triangles to the screen with properties from pSurf
and PolyFlags
. The vertex data is in pOutVerts
. IndexArray
contains indices into pOutVerts
that define the triangles and iNumPts
is the length of the array. (Used by batched rendering)
void RenderSkyDome (gl_sky_t *sky)
Renders the "Sky dome" using the current texture.
void FlushScreenTextures (void)
Deletes the screen textures. (Used when the rendering resolution is changed)
void StartScreenWipe (void)
Saves the screen used for the starting point of screen wipes.
void EndScreenWipe (void)
Saves the screen used for the destination of screen wipes.
void DoScreenWipe (void)
Renders one frame of a screen wipe, using the current texture as the fade mask.
void MakeScreenTexture (void)
Saves the screen into a screen texture that can be used with DrawIntermissionBG
and PostImgRedraw
.
void DrawIntermissionBG (void)
Draws the saved screen texture on the screen.
void PostImgRedraw (float points[SCREENVERTS][SCREENVERTS][2])
Draws the saved screen texture on the screen with distortion defined by points
.
void MakeScreenFinalTexture (void)
Saves the screen into a "final" screen texture that can be used with DrawScreenFinalTexture
.
void DrawScreenFinalTexture (int width, int height)
Renders the "final" screen texture on the screen, stretched into dimensions defined by width
and height
. (Used for stretching a low resolution to the screen without changing the display resolution)
boolean CompileShaders (void)
Compiles the shaders so they can be used in rendering. Needs to be called before using shaders for the first time. Any custom shaders set with LoadCustomShader
will be compiled too. The function can be called again to remove old compiled shaders and re-compile them.
If the function returns false, it means that the hardware does not support shaders or that the code has been compiled without shader support. In either case, the user of the backend needs to take the lack of shader capability into account. This is currently the method that will reveal if shaders can be used or not for the user of the backend.
void CleanShaders (void)
Removes custom shader source code from memory. Next call to CompileShaders
will not have them. Call CompileShaders
for the changes to come into effect.
void LoadCustomShader (int number, char *code, size_t size, boolean isfragment)
Puts a custom shader into slot number
. (See SHADER_* in hw_defs.h for slots.) The source code is in code
and the length of the source code string is defined in size
. isfragment
is true for fragment shaders and false for vertex shaders. Call CompileShaders
for the changes to come into effect.
void SetShader (int type)
If shaders are enabled, the currently used shader is set to type
.
void UnSetShader (void)
The fixed function pipeline is used for draw calls instead of shaders. (used for most/all non-3d stuff?)
void SetShaderInfo (hwdshaderinfo_t info, INT32 value)
Sets certain values that are given to shader uniform variables. (currently only level time)
void DrawModel (model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface)
CreateModelVBOs
needs to be called for model
before drawing it for the first time.
void CreateModelVBOs (model_t *model)
Creates vertex buffer objects for model
so it can be rendered.
void ReadRect (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data)
Reads a rectangle from the framebuffer. TODO: dst_stride
and output format?