[gl] extracted some common GPU rendering code

This commit is contained in:
Edu García
2024-05-08 18:08:19 +01:00
parent d93ca0d5fd
commit 2e59199b24
2 changed files with 70 additions and 70 deletions

View File

@@ -125,6 +125,25 @@ void rend_SetCharacterParameters(ddgr_color color1, ddgr_color color2, ddgr_colo
rend_FontAlpha[3] = (color4 >> 24) / 255.0f;
}
// Sets where the software renderer should write to
void rend_SetSoftwareParameters(float aspect, int width, int height, int pitch, ubyte *framebuffer) {}
// Sets the state of bilinear filtering for our textures
void rend_SetFiltering(sbyte state) {
gpu_state.cur_bilinear_state = state;
}
// Sets the near and far planes for z buffer
void rend_SetZValues(float nearz, float farz) {
gpu_state.cur_near_z = nearz;
gpu_state.cur_far_z = farz;
// mprintf ((0,"OPENGL:Setting depth range to %f - %f\n",nearz,farz));
// JEFF: glDepthRange must take parameters [0,1]
// It is set in init
//@@dglDepthRange (0,farz);
}
// Sets a bitmap as a overlay map to rendered on top of the next texture map
// a -1 value indicates no overlay map
void rend_SetOverlayMap(int handle) { gpu_Overlay_map = handle; }
@@ -225,6 +244,57 @@ float rend_GetAspectRatio(void) {
// Given a source x,y and width,height, draws any sized bitmap into the renderer lfb
void rend_DrawLFBBitmap(int sx, int sy, int w, int h, int dx, int dy, ushort *data, int rowsize) {}
// draws a scaled 2d bitmap to our buffer
void rend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, float u0, float v0, float u1, float v1, int color,
float *alphas) {
g3Point *ptr_pnts[4];
g3Point pnts[4];
float r, g, b;
if (color != -1) {
r = GR_COLOR_RED(color) / 255.0;
g = GR_COLOR_GREEN(color) / 255.0;
b = GR_COLOR_BLUE(color) / 255.0;
}
for (int i = 0; i < 4; i++) {
if (color == -1)
pnts[i].p3_l = 1.0;
else {
pnts[i].p3_r = r;
pnts[i].p3_g = g;
pnts[i].p3_b = b;
}
if (alphas) {
pnts[i].p3_a = alphas[i];
}
pnts[i].p3_z = 1.0f;
pnts[i].p3_flags = PF_PROJECTED;
}
pnts[0].p3_sx = x1;
pnts[0].p3_sy = y1;
pnts[0].p3_u = u0;
pnts[0].p3_v = v0;
pnts[1].p3_sx = x2;
pnts[1].p3_sy = y1;
pnts[1].p3_u = u1;
pnts[1].p3_v = v0;
pnts[2].p3_sx = x2;
pnts[2].p3_sy = y2;
pnts[2].p3_u = u1;
pnts[2].p3_v = v1;
pnts[3].p3_sx = x1;
pnts[3].p3_sy = y2;
pnts[3].p3_u = u0;
pnts[3].p3_v = v1;
ptr_pnts[0] = &pnts[0];
ptr_pnts[1] = &pnts[1];
ptr_pnts[2] = &pnts[2];
ptr_pnts[3] = &pnts[3];
rend_SetTextureType(TT_LINEAR);
rend_DrawPolygon2D(bm, ptr_pnts, 4);
}
// given a chunked bitmap, renders it.
void rend_DrawChunkedBitmap(chunked_bitmap *chunk, int x, int y, ubyte alpha) {
int *bm_array = chunk->bm_array;

View File

@@ -2320,65 +2320,6 @@ void rend_Flip(void) {
void rend_EndFrame(void) {}
// draws a scaled 2d bitmap to our buffer
void rend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, float u0, float v0, float u1, float v1, int color,
float *alphas) {
g3Point *ptr_pnts[4];
g3Point pnts[4];
float r, g, b;
if (color != -1) {
r = GR_COLOR_RED(color) / 255.0;
g = GR_COLOR_GREEN(color) / 255.0;
b = GR_COLOR_BLUE(color) / 255.0;
}
for (int i = 0; i < 4; i++) {
if (color == -1)
pnts[i].p3_l = 1.0;
else {
pnts[i].p3_r = r;
pnts[i].p3_g = g;
pnts[i].p3_b = b;
}
if (alphas) {
pnts[i].p3_a = alphas[i];
}
pnts[i].p3_z = 1.0f;
pnts[i].p3_flags = PF_PROJECTED;
}
pnts[0].p3_sx = x1;
pnts[0].p3_sy = y1;
pnts[0].p3_u = u0;
pnts[0].p3_v = v0;
pnts[1].p3_sx = x2;
pnts[1].p3_sy = y1;
pnts[1].p3_u = u1;
pnts[1].p3_v = v0;
pnts[2].p3_sx = x2;
pnts[2].p3_sy = y2;
pnts[2].p3_u = u1;
pnts[2].p3_v = v1;
pnts[3].p3_sx = x1;
pnts[3].p3_sy = y2;
pnts[3].p3_u = u0;
pnts[3].p3_v = v1;
ptr_pnts[0] = &pnts[0];
ptr_pnts[1] = &pnts[1];
ptr_pnts[2] = &pnts[2];
ptr_pnts[3] = &pnts[3];
rend_SetTextureType(TT_LINEAR);
rend_DrawPolygon2D(bm, ptr_pnts, 4);
}
// Sets where the software renderer should write to
void rend_SetSoftwareParameters(float aspect, int width, int height, int pitch, ubyte *framebuffer) {}
// Sets the state of bilinear filtering for our textures
void rend_SetFiltering(sbyte state) {
gpu_state.cur_bilinear_state = state;
}
// Sets the state of z-buffering to on or off
void rend_SetZBufferState(sbyte state) {
if (state == gpu_state.cur_zbuffer_state)
@@ -2399,17 +2340,6 @@ void rend_SetZBufferState(sbyte state) {
CHECK_ERROR(14)
}
// Sets the near and far planes for z buffer
void rend_SetZValues(float nearz, float farz) {
gpu_state.cur_near_z = nearz;
gpu_state.cur_far_z = farz;
// mprintf ((0,"OPENGL:Setting depth range to %f - %f\n",nearz,farz));
// JEFF: glDepthRange must take parameters [0,1]
// It is set in init
//@@dglDepthRange (0,farz);
}
// Clears the display to a specified color
void rend_ClearScreen(ddgr_color color) {
int r = (color >> 16 & 0xFF);