FS2_Open
Open source remastering of the Freespace 2 engine
gropenglbmpman.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "anim/animplay.h"
13 #include "anim/packunpack.h"
14 #include "cmdline/cmdline.h"
15 #include "ddsutils/ddsutils.h"
16 #include "globalincs/systemvars.h"
19 #include "graphics/gropenglstate.h"
21 #include "jpgutils/jpgutils.h"
22 #include "pcxutils/pcxutils.h"
23 #include "pngutils/pngutils.h"
24 #include "tgautils/tgautils.h"
25 
26 #define BMPMAN_INTERNAL
27 #include "bmpman/bm_internal.h"
28 
29 
30 
31 static inline int is_power_of_two(int w, int h)
32 {
33  // NOTE: OpenGL texture code has a min tex size of 16 (currently), so we need to be at least
34  // the min size here to qualify as power-of-2 and not get resized later on
35  return ( ((w >= GL_min_texture_width) && !(w & (w-1))) && ((h >= GL_min_texture_height) && !(h & (h-1))) );
36 }
37 
38 int get_num_mipmap_levels(int w, int h)
39 {
40  int size, levels = 0;
41 
42  // make sure we can and should generate mipmaps before trying to use them
44  return 1;
45 
46  size = MAX(w, h);
47 
48  while (size > 0) {
49  size >>= 1;
50  levels++;
51  }
52 
53  return (levels > 1) ? levels : 1;
54 }
55 
59 void gr_opengl_bm_free_data(int n, bool release)
60 {
61  Assert( (n >= 0) && (n < MAX_BITMAPS) );
62 
63  // might as well free up the on card texture data too in order to get rid
64  // of old interface stuff but don't free USER types, unless it's a total release,
65  // since we can reuse ANI slots for faster and less resource intensive rendering
66  if ( release || (bm_bitmaps[n].type != BM_TYPE_USER) )
68 
71 }
72 
77 {
78  Assert( (n >= 0) && (n < MAX_BITMAPS) );
79 }
80 
85 {
86  Assert( (n >= 0) && (n < MAX_BITMAPS) );
87 }
88 
93 {
95 }
96 
97 extern void bm_clean_slot(int n);
98 
99 extern bool opengl_texture_slot_valid(int n, int handle);
100 
102 {
103  Assert( (n >= 0) && (n < MAX_BITMAPS) );
104 
106  return;
107  }
108 
109  bitmap_entry *be = &bm_bitmaps[n];
110  bitmap *bmp = &be->bm;
111 
112  size_t rc = opengl_export_render_target( n, bmp->w, bmp->h, (bmp->true_bpp == 32), be->num_mipmaps, (ubyte*)bmp->data );
113 
114  if (rc != be->mem_taken) {
115  Int3();
116  return;
117  }
118 
120  dds_save_image(bmp->w, bmp->h, bmp->true_bpp, be->num_mipmaps, (ubyte*)bmp->data, (bmp->flags & BMP_FLAG_CUBEMAP));
121  }
122 }
123 
124 int gr_opengl_bm_make_render_target(int n, int *width, int *height, ubyte *bpp, int *mm_lvl, int flags)
125 {
126  Assert( (n >= 0) && (n < MAX_BITMAPS) );
127 
129  return 0;
130  }
131 
133  return 0;
134  }
135 
136  if ( (flags & BMP_FLAG_CUBEMAP) && (*width != *height) ) {
137  MIN(*width, *height) = MAX(*width, *height);
138  }
139 
140  // Only enforce power of two size if not supported
142  {
143  Assert( is_power_of_two(*width, *height) );
144  }
145 
146  if ( opengl_make_render_target(bm_bitmaps[n].handle, n, width, height, bpp, mm_lvl, flags) ) {
147  return 1;
148  }
149 
150  return 0;
151 }
152 
154 {
156  return 0;
157  }
158 
159  if (n == -1) {
161  return 1;
162  }
163 
164  Assert( (n >= 0) && (n < MAX_BITMAPS) );
165 
166  int is_static = (bm_bitmaps[n].type == BM_TYPE_RENDER_TARGET_STATIC);
167 
168  if ( opengl_set_render_target(n, face, is_static) ) {
169  return 1;
170  }
171 
172  return 0;
173 }
174 
175 bool gr_opengl_bm_data(int n, bitmap* bm)
176 {
177  // Do nothing here
178  return true;
179 }
#define OGL_EXT_FRAMEBUFFER_OBJECT
int get_num_mipmap_levels(int w, int h)
#define MIN(a, b)
Definition: pstypes.h:296
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
size_t mem_taken
How much memory does this bitmap use? - UnknownPlayer.
Definition: bm_internal.h:65
ubyte true_bpp
The image's actual bitdepth.
Definition: bmpman.h:107
Assert(pm!=NULL)
ubyte flags
Various texture type flags.
Definition: bmpman.h:108
bitmap_entry bm_bitmaps[MAX_BITMAPS]
Definition: bmpman.cpp:85
BM_TYPE type
PCX, USER, ANI, etc.
Definition: bm_internal.h:58
void bm_clean_slot(int n)
Definition: bmpman.cpp:455
#define OGL_SGIS_GENERATE_MIPMAP
GLsizeiptr size
Definition: Glext.h:5496
#define Int3()
Definition: pstypes.h:292
short h
Height, in number of pixels.
Definition: bmpman.h:104
GLenum type
Definition: Gl.h:1492
int opengl_set_render_target(int slot, int face, int is_static)
GLint GLsizei width
Definition: Gl.h:1505
GLenum GLuint GLint GLenum face
Definition: Glext.h:6586
int gr_opengl_bm_set_render_target(int n, int face)
Definition: bm_internal.h:49
int GL_min_texture_height
void gr_opengl_bm_free_data(int n, bool release)
#define BMP_FLAG_CUBEMAP
Texture is a cubemap.
Definition: bmpman.h:68
int GL_min_texture_width
size_t opengl_export_render_target(int slot, int width, int height, int alpha, int num_mipmaps, ubyte *image_data)
short w
Width, in number of pixels.
Definition: bmpman.h:103
Definition: bmpman.h:101
void gr_opengl_bm_page_in_start()
#define OGL_ARB_TEXTURE_CUBE_MAP
in-memory
Definition: bmpman.h:74
int Cmdline_mipmap
Definition: cmdline.cpp:324
void opengl_kill_render_target(int slot)
#define Is_Extension_Enabled(x)
GLclampd n
Definition: Glext.h:7286
unsigned char ubyte
Definition: pstypes.h:62
bool gr_opengl_bm_data(int n, bitmap *bm)
GLbitfield flags
Definition: Glext.h:6722
24/32 bit setup internally as a dynamic render target
Definition: bmpman.h:85
bool opengl_texture_slot_valid(int n, int handle)
void opengl_free_texture_slot(int n)
int gr_opengl_bm_make_render_target(int n, int *width, int *height, ubyte *bpp, int *mm_lvl, int flags)
bitmap bm
Bitmap info.
Definition: bm_internal.h:74
GLint GLsizei GLsizei height
Definition: Gl.h:1505
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
#define OGL_ARB_TEXTURE_NON_POWER_OF_TWO
24/32 bit setup internally as a static render target
Definition: bmpman.h:84
ptr_u data
Pointer to data, or maybe offset into VRAM.
Definition: bmpman.h:109
int num_mipmaps
number of mipmap levels, we need to read all of them
Definition: bm_internal.h:66
void opengl_preload_init()
#define MAX_BITMAPS
How many bitmaps the game can handle.
Definition: bmpman.h:48
int opengl_make_render_target(int handle, int slot, int *w, int *h, ubyte *bpp, int *mm_lvl, int flags)
int Cmdline_no_fbo
Definition: cmdline.cpp:442
#define MAX(a, b)
Definition: pstypes.h:299
void gr_opengl_bm_create(int n)
int Cmdline_save_render_targets
Definition: cmdline.cpp:500
void gr_opengl_bm_save_render_target(int n)
void dds_save_image(int width, int height, int bpp, int num_mipmaps, ubyte *data, int cubemap, const char *filename)
Definition: ddsutils.cpp:324
void gr_opengl_bm_init(int n)