Descent3/lib/rend_opengl.h

161 lines
4.6 KiB
C
Raw Normal View History

/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2024-04-16 03:43:29 +00:00
#ifndef REND_OPENGL_H
#define REND_OPENGL_H
#include "renderer.h"
#include "3d.h"
class oeApplication;
// Starts up opengl
2024-04-16 18:56:40 +00:00
int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state);
2024-04-16 03:43:29 +00:00
// Closes down opengl
opengl: use SDL_WINDOW_FULLSCREEN_DESKTOP and an FBO. This now renders to an OpenGL Framebuffer Object at the game's resolution, and blits it to the window at whatever resolution it is currently using, scaling and letterboxing if necessary. Which is to say: display resolutions are now imaginary, and we never change the physical display mode now. A smaller resolution is simply drawing less pixels and scaling them up with the GPU for display. This solves a few problems: no more resizing background windows or desktop icons shuffling around, no more being stuck in a weird resolution when debugging or if the game crashes, no more waiting on monitors to click over to a new mode, and no more weird rendering when the display didn't exactly support the requested mode. This also means the game doesn't have to drop down to 640x480 for the config menu screen when it was otherwise using some other resolution. Some caveats: - This _requires_ OpenGL Framebuffer Object support; there is currently no fallback if it's missing and the game will refuse to start. But any desktop hardware of the last ~20 years should support it. For weird embedded things or whatnot, it will be possible to add a fallback. - This currently requires SDL. The OpenGL pieces should work on Windows, but someone would need to adjust the existing win32 code to create a fullscreen window and not change the physical display mode. It should still compile on windows and work as before (untested by me, though). - This is only OpenGL; it does not touch the Direct3D renderer, which should continue to work as before (again, untested by me).
2024-06-14 07:35:54 +00:00
void opengl_Close(const bool just_resizing=false);
2024-04-16 03:43:29 +00:00
void opengl_Shutdown();
// The main drawing function...draws a flat/textured/gouraud polygon
2024-04-16 18:56:40 +00:00
void opengl_DrawPolygon(int, g3Point **, int, int);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void opengl_SetFlatColor(ddgr_color color);
2024-04-16 03:43:29 +00:00
// Ends a frame
void opengl_EndFrame();
// Flips the screen
void opengl_Flip();
// Does setup for a new frame
2024-04-16 18:56:40 +00:00
void opengl_BeginFrame(int, int, int, int, int);
2024-04-16 03:43:29 +00:00
// Tells opengl what kind of texturing (linear/perspective) we want
2024-04-16 18:56:40 +00:00
void opengl_SetTextureType(texture_type);
2024-04-16 03:43:29 +00:00
// Sets the lighting state of opengl
2024-04-16 18:56:40 +00:00
void opengl_SetLightingState(light_state state);
2024-04-16 03:43:29 +00:00
// Sets the opengl color model (either rgb or mono)
2024-04-16 18:56:40 +00:00
void opengl_SetColorModel(color_model state);
2024-04-16 03:43:29 +00:00
// Sets the state of bilinear filtering for our textures
2024-05-24 03:05:05 +00:00
void opengl_SetFiltering(int8_t state);
2024-04-16 03:43:29 +00:00
// Sets the state of zbuffering to on or off
2024-05-24 03:05:05 +00:00
void opengl_SetZBufferState(int8_t state);
2024-04-16 03:43:29 +00:00
// Sets the near/far z values for zbuffering
2024-04-16 18:56:40 +00:00
void opengl_SetZValues(float nearz, float farz);
2024-04-16 03:43:29 +00:00
// Sets a bitmap as a lightmap to rendered on top of the next texture map
// a -1 value indicates no lighting map
2024-04-16 18:56:40 +00:00
void opengl_SetLightingMap(int handle);
2024-04-16 03:43:29 +00:00
// Clears the display to a specified color
2024-04-16 18:56:40 +00:00
void opengl_ClearScreen(ddgr_color color);
2024-04-16 03:43:29 +00:00
// Fills a rectangle on the display
2024-04-16 18:56:40 +00:00
void opengl_FillRect(ddgr_color color, int x1, int y1, int x2, int y2);
2024-04-16 03:43:29 +00:00
// Sets a pixel on the display
2024-04-16 18:56:40 +00:00
void opengl_SetPixel(ddgr_color color, int x, int y);
2024-04-16 03:43:29 +00:00
// Sets the near and far plane of fog
2024-04-16 18:56:40 +00:00
void opengl_SetFogBorders(float nearz, float farz);
2024-04-16 03:43:29 +00:00
// Sets the fog state to on or off
2024-05-24 03:05:05 +00:00
void opengl_SetFogState(int8_t state);
2024-04-16 03:43:29 +00:00
// Fills in projection variables
2024-04-16 18:56:40 +00:00
void opengl_GetProjectionParameters(int *width, int *height);
void opengl_GetProjectionScreenParameters(int &screenLX, int &screenTY, int &screenW, int &screenH);
2024-04-16 03:43:29 +00:00
// Returns the aspect ratio of the physical screen
2024-04-16 18:56:40 +00:00
float opengl_GetAspectRatio();
2024-04-16 03:43:29 +00:00
// Sets texture wrapping type
2024-04-16 18:56:40 +00:00
void opengl_SetWrapType(wrap_type val);
2024-04-16 03:43:29 +00:00
// Sets the constant alpha value
2024-05-24 03:07:26 +00:00
void opengl_SetAlphaValue(uint8_t val);
2024-04-16 03:43:29 +00:00
// Sets the overall alpha scale factor (all alpha values are scaled by this value)
// usefull for motion blur effect
void opengl_SetAlphaFactor(float val);
// Returns the current Alpha factor
float opengl_GetAlphaFactor(void);
// Sets the type of alpha blending you want
2024-05-24 03:05:05 +00:00
void opengl_SetAlphaType(int8_t atype);
2024-04-16 03:43:29 +00:00
// Sets whether or not to write into the zbuffer
2024-04-16 18:56:40 +00:00
void opengl_SetZBufferWriteMask(int state);
2024-04-16 03:43:29 +00:00
// Gets the current state of the renderer
2024-04-16 18:56:40 +00:00
void opengl_GetRenderState(rendering_state *rstate);
2024-04-16 03:43:29 +00:00
// draws a line
2024-04-16 18:56:40 +00:00
void opengl_DrawLine(int x1, int y1, int x2, int y2);
2024-04-16 03:43:29 +00:00
// draws a line
2024-04-16 18:56:40 +00:00
void opengl_DrawSpecialLine(g3Point *p0, g3Point *p1);
2024-04-16 03:43:29 +00:00
// Sets the color that opengl uses for fog
2024-04-16 18:56:40 +00:00
void opengl_SetFogColor(ddgr_color color);
2024-04-16 03:43:29 +00:00
// Sets the coplanar z bias for rendered polygons
2024-04-16 18:56:40 +00:00
void opengl_SetCoplanarPolygonOffset(float factor);
2024-04-16 03:43:29 +00:00
// Sets up a some global preferences for openGL
2024-04-16 18:56:40 +00:00
int opengl_SetPreferredState(renderer_preferred_state *pref_state);
2024-04-16 03:43:29 +00:00
// Sets the gamma correction value
2024-04-16 18:56:40 +00:00
void opengl_SetGammaValue(float val);
2024-04-16 03:43:29 +00:00
// Takes a screenshot of the frontbuffer and puts it into the passed bitmap handle
2024-04-16 18:56:40 +00:00
void opengl_Screenshot(int bm_handle);
2024-04-16 03:43:29 +00:00
// Returns the pixel color at x,y
2024-04-16 18:56:40 +00:00
ddgr_color opengl_GetPixel(int, int);
2024-04-16 03:43:29 +00:00
// Clears the zbuffer
2024-04-16 18:56:40 +00:00
void opengl_ClearZBuffer();
2024-04-16 03:43:29 +00:00
// Clears the texture cache
2024-04-16 18:56:40 +00:00
void opengl_ResetCache();
2024-04-16 03:43:29 +00:00
// Takes a bitmap and blits it to the screen using linear frame buffer stuff
// X and Y are the destination X,Y
2024-04-16 18:56:40 +00:00
void opengl_CopyBitmapToFramebuffer(int bm_handle, int x, int y);
2024-04-16 03:43:29 +00:00
// Gets a renderer ready for a framebuffer copy, or stops a framebuffer copy
2024-04-16 18:56:40 +00:00
void opengl_SetFrameBufferCopyState(bool state);
2024-04-16 03:43:29 +00:00
#if defined(WIN32)
// returns directdraw object
void *opengl_DirectDrawObj();
#endif
// returns rendering statistics for the frame
void opengl_GetStatistics(tRendererStats *stats);
#endif