mirror of
https://github.com/kevinbentley/Descent3.git
synced 2026-04-04 20:00:04 -04:00
[gl] extracted some common GPU rendering code
This commit is contained in:
@@ -2806,159 +2806,11 @@ void rend_SetZBufferWriteMask(int state) {
|
||||
}
|
||||
}
|
||||
|
||||
// Gets a pointer to a linear frame buffer
|
||||
void rend_GetLFBLock(renderer_lfb *lfb) {}
|
||||
|
||||
// Releases an lfb lock
|
||||
void rend_ReleaseLFBLock(renderer_lfb *lfb) {}
|
||||
|
||||
// Returns the aspect ratio of the physical screen
|
||||
void rend_GetProjectionParameters(int *width, int *height) {
|
||||
*width = gpu_state.clip_x2 - gpu_state.clip_x1;
|
||||
*height = gpu_state.clip_y2 - gpu_state.clip_y1;
|
||||
int rend_ReInit() {
|
||||
opengl_Close();
|
||||
return opengl_Init(NULL, &gpu_preferred_state);
|
||||
}
|
||||
|
||||
void rend_GetProjectionScreenParameters(int &screenLX, int &screenTY, int &screenW, int &screenH) {
|
||||
screenLX = gpu_state.clip_x1;
|
||||
screenTY = gpu_state.clip_y1;
|
||||
screenW = gpu_state.clip_x2 - gpu_state.clip_x1 + 1;
|
||||
screenH = gpu_state.clip_y2 - gpu_state.clip_y1 + 1;
|
||||
}
|
||||
|
||||
// Returns the aspect ratio of the physical screen
|
||||
float rend_GetAspectRatio(void) {
|
||||
float aspect_ratio = (float)((3.0f * gpu_state.screen_width) / (4.0f * gpu_state.screen_height));
|
||||
return aspect_ratio;
|
||||
}
|
||||
|
||||
// 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) {}
|
||||
|
||||
// given a chunked bitmap, renders it.
|
||||
void rend_DrawChunkedBitmap(chunked_bitmap *chunk, int x, int y, ubyte alpha) {
|
||||
int *bm_array = chunk->bm_array;
|
||||
int w = chunk->w;
|
||||
int h = chunk->h;
|
||||
int piece_w = bm_w(bm_array[0], 0);
|
||||
int piece_h = bm_h(bm_array[0], 0);
|
||||
int screen_w, screen_h;
|
||||
int i, t;
|
||||
rend_SetZBufferState(0);
|
||||
rend_GetProjectionParameters(&screen_w, &screen_h);
|
||||
for (i = 0; i < h; i++) {
|
||||
for (t = 0; t < w; t++) {
|
||||
int dx = x + (piece_w * t);
|
||||
int dy = y + (piece_h * i);
|
||||
int dw, dh;
|
||||
if ((dx + piece_w) > screen_w)
|
||||
dw = piece_w - ((dx + piece_w) - screen_w);
|
||||
else
|
||||
dw = piece_w;
|
||||
if ((dy + piece_h) > screen_h)
|
||||
dh = piece_h - ((dy + piece_h) - screen_h);
|
||||
else
|
||||
dh = piece_h;
|
||||
|
||||
float u2 = (float)dw / (float)piece_w;
|
||||
float v2 = (float)dh / (float)piece_h;
|
||||
rend_DrawSimpleBitmap(bm_array[i * w + t], dx, dy);
|
||||
}
|
||||
}
|
||||
rend_SetZBufferState(1);
|
||||
}
|
||||
|
||||
// given a chunked bitmap, renders it.scaled
|
||||
void rend_DrawScaledChunkedBitmap(chunked_bitmap *chunk, int x, int y, int neww, int newh, ubyte alpha) {
|
||||
int *bm_array = chunk->bm_array;
|
||||
int w = chunk->w;
|
||||
int h = chunk->h;
|
||||
int piece_w;
|
||||
int piece_h;
|
||||
int screen_w, screen_h;
|
||||
int i, t;
|
||||
|
||||
float scalew, scaleh;
|
||||
|
||||
scalew = ((float)neww) / ((float)chunk->pw);
|
||||
scaleh = ((float)newh) / ((float)chunk->ph);
|
||||
piece_w = scalew * ((float)bm_w(bm_array[0], 0));
|
||||
piece_h = scaleh * ((float)bm_h(bm_array[0], 0));
|
||||
rend_GetProjectionParameters(&screen_w, &screen_h);
|
||||
rend_SetOverlayType(OT_NONE);
|
||||
rend_SetLighting(LS_NONE);
|
||||
rend_SetColorModel(CM_MONO);
|
||||
rend_SetZBufferState(0);
|
||||
rend_SetAlphaType(AT_CONSTANT_TEXTURE);
|
||||
rend_SetAlphaValue(alpha);
|
||||
rend_SetWrapType(WT_WRAP);
|
||||
for (i = 0; i < h; i++) {
|
||||
for (t = 0; t < w; t++) {
|
||||
int dx = x + (piece_w * t);
|
||||
int dy = y + (piece_h * i);
|
||||
int dw, dh;
|
||||
if ((dx + piece_w) > screen_w)
|
||||
dw = piece_w - ((dx + piece_w) - screen_w);
|
||||
else
|
||||
dw = piece_w;
|
||||
if ((dy + piece_h) > screen_h)
|
||||
dh = piece_h - ((dy + piece_h) - screen_h);
|
||||
else
|
||||
dh = piece_h;
|
||||
|
||||
float u2 = (float)dw / (float)piece_w;
|
||||
float v2 = (float)dh / (float)piece_h;
|
||||
rend_DrawScaledBitmap(dx, dy, dx + dw, dy + dh, bm_array[i * w + t], 0, 0, u2, v2);
|
||||
}
|
||||
}
|
||||
rend_SetZBufferState(1);
|
||||
}
|
||||
|
||||
// Sets some global preferences for the renderer
|
||||
int rend_SetPreferredState(renderer_preferred_state *pref_state) {
|
||||
int retval = 1;
|
||||
renderer_preferred_state old_state = gpu_preferred_state;
|
||||
|
||||
gpu_preferred_state = *pref_state;
|
||||
if (gpu_state.initted) {
|
||||
int reinit = 0;
|
||||
mprintf((0, "Inside pref state!\n"));
|
||||
|
||||
// Change gamma if needed
|
||||
if (pref_state->width != gpu_state.screen_width || pref_state->height != gpu_state.screen_height ||
|
||||
old_state.bit_depth != pref_state->bit_depth) {
|
||||
reinit = 1;
|
||||
}
|
||||
|
||||
if (reinit) {
|
||||
opengl_Close();
|
||||
retval = opengl_Init(NULL, &gpu_preferred_state);
|
||||
} else {
|
||||
if (old_state.gamma != pref_state->gamma) {
|
||||
rend_SetGammaValue(pref_state->gamma);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gpu_preferred_state = *pref_state;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// Draws a simple bitmap at the specified x,y location
|
||||
void rend_DrawSimpleBitmap(int bm_handle, int x, int y) {
|
||||
rend_SetAlphaType(AT_CONSTANT_TEXTURE);
|
||||
rend_SetAlphaValue(255);
|
||||
rend_SetLighting(LS_NONE);
|
||||
rend_SetColorModel(CM_MONO);
|
||||
rend_SetOverlayType(OT_NONE);
|
||||
rend_SetFiltering(0);
|
||||
rend_DrawScaledBitmap(x, y, x + bm_w(bm_handle, 0), y + bm_h(bm_handle, 0), bm_handle, 0, 0, 1, 1);
|
||||
rend_SetFiltering(1);
|
||||
}
|
||||
|
||||
// Fills in the passed in pointer with the current rendering state
|
||||
void rend_GetRenderState(rendering_state *rstate) { memcpy(rstate, &gpu_state, sizeof(rendering_state)); }
|
||||
|
||||
// Takes a bitmap and blits it to the screen using linear frame buffer stuff
|
||||
// X and Y are the destination X,Y
|
||||
void rend_CopyBitmapToFramebuffer(int bm_handle, int x, int y) {
|
||||
|
||||
Reference in New Issue
Block a user