1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "anim/animplay.h"
#include "anim/packunpack.h"
#include "cmdline/cmdline.h"
#include "ddsutils/ddsutils.h"
#include "globalincs/systemvars.h"
#include "gropenglbmpman.h"
#include "gropenglstate.h"
#include "gropengltexture.h"
#include "jpgutils/jpgutils.h"
#include "pcxutils/pcxutils.h"
#include "pngutils/pngutils.h"
#include "tgautils/tgautils.h"
#define BMPMAN_INTERNAL
#include "bmpman/bm_internal.h"
int get_num_mipmap_levels(int w, int h)
{
int size, levels = 0;
size = MAX(w, h);
while (size > 0) {
size >>= 1;
levels++;
}
return (levels > 1) ? levels : 1;
}
/**
* Anything API specific to freeing bm data
*/
void gr_opengl_bm_free_data(bitmap_slot* slot, bool release)
{
if ( release )
opengl_free_texture_slot( slot );
if ( (slot->entry.type == BM_TYPE_RENDER_TARGET_STATIC) || (slot->entry.type == BM_TYPE_RENDER_TARGET_DYNAMIC) )
opengl_kill_render_target( slot );
}
/**
* API specifics for creating a user bitmap
*/
void gr_opengl_bm_create(bitmap_slot* /*entry*/)
{
}
/**
* API specific init instructions
*/
void gr_opengl_bm_init(bitmap_slot* slot)
{
slot->gr_info = new tcache_slot_opengl;
}
/**
* Specific instructions for setting up the start of a page-in session
*/
void gr_opengl_bm_page_in_start()
{
opengl_preload_init();
}
extern bool opengl_texture_slot_valid(int n, int handle);
void gr_opengl_bm_save_render_target(int handle)
{
if ( Cmdline_no_fbo ) {
return;
}
bitmap_entry *be = bm_get_entry(handle);
bitmap *bmp = &be->bm;
size_t rc = opengl_export_render_target( handle, bmp->w, bmp->h, (bmp->true_bpp == 32), be->num_mipmaps, (ubyte*)bmp->data );
if (rc != be->mem_taken) {
Int3();
return;
}
dds_save_image(bmp->w, bmp->h, bmp->true_bpp, be->num_mipmaps, (ubyte*)bmp->data, (bmp->flags & BMP_FLAG_CUBEMAP));
}
int gr_opengl_bm_make_render_target(int handle, int *width, int *height, int *bpp, int *mm_lvl, int flags)
{
if ( Cmdline_no_fbo ) {
return 0;
}
if ( (flags & BMP_FLAG_CUBEMAP) && (*width != *height) ) {
MIN(*width, *height) = MAX(*width, *height);
}
if ( opengl_make_render_target(handle, width, height, bpp, mm_lvl, flags) ) {
return 1;
}
return 0;
}
int gr_opengl_bm_set_render_target(int n, int face)
{
if ( Cmdline_no_fbo ) {
return 0;
}
if (n == -1) {
opengl_set_render_target(-1);
return 1;
}
auto entry = bm_get_entry(n);
int is_static = (entry->type == BM_TYPE_RENDER_TARGET_STATIC);
if ( opengl_set_render_target(n, face, is_static) ) {
return 1;
}
return 0;
}
bool gr_opengl_bm_data(int /*n*/, bitmap* /*bm*/)
{
// Do nothing here
return true;
}
|