15 #include "frameBufferProperties.h" 16 #include "string_utils.h" 17 #include "renderBuffer.h" 18 #include "config_display.h" 26 FrameBufferProperties::
27 FrameBufferProperties() {
36 void FrameBufferProperties::
38 _flags_specified = copy._flags_specified;
40 _specified = copy._specified;
42 for (
int i = 0; i < FBP_COUNT; ++i) {
43 _property[i] = copy._property[i];
56 if (((other._flags & other._flags_specified) & ~(_flags & _flags_specified)) != 0) {
61 for (
int i = 0; i < FBP_COUNT; ++i) {
62 if (other._property[i] > _property[i]) {
79 static bool default_ready =
false;
86 default_props.set_rgb_color(
true);
87 default_props.set_back_buffers(back_buffers);
92 <<
"The config-variable 'framebuffer-mode' no longer functions.\n";
94 <<
"Instead, use one or more of these:\n";
95 display_cat.error() <<
" framebuffer-hardware #t\n";
96 display_cat.error() <<
" framebuffer-software #t\n";
97 display_cat.error() <<
" framebuffer-depth #t\n";
98 display_cat.error() <<
" framebuffer-alpha #t\n";
99 display_cat.error() <<
" framebuffer-stencil #t\n";
100 display_cat.error() <<
" framebuffer-multisample #t\n";
101 display_cat.error() <<
" framebuffer-stereo #t\n";
102 display_cat.error() <<
" depth-bits N\n";
103 display_cat.error() <<
" color-bits N\n";
104 display_cat.error() <<
" red-bits N\n";
105 display_cat.error() <<
" green-bits N\n";
106 display_cat.error() <<
" blue-bits N\n";
107 display_cat.error() <<
" alpha-bits N\n";
108 display_cat.error() <<
" stencil-bits N\n";
109 display_cat.error() <<
" multisamples N\n";
110 display_cat.error() <<
" coverage-samples N\n";
111 display_cat.error() <<
" back-buffers N\n";
114 if (framebuffer_hardware) {
115 default_props.set_force_hardware(
true);
117 if (framebuffer_software) {
118 default_props.set_force_software(
true);
120 if (framebuffer_depth) {
121 default_props.set_depth_bits(1);
123 if (framebuffer_alpha) {
124 default_props.set_alpha_bits(1);
126 if (framebuffer_stencil) {
127 default_props.set_stencil_bits(1);
129 if (framebuffer_accum) {
130 default_props.set_accum_bits(1);
132 if (framebuffer_multisample) {
133 default_props.set_multisamples(1);
135 if (framebuffer_stereo) {
136 default_props.set_stereo(
true);
138 if (framebuffer_srgb) {
139 default_props.set_srgb_color(
true);
141 if (framebuffer_float) {
142 default_props.set_float_color(
true);
144 if (depth_bits > 0) {
145 default_props.set_depth_bits(depth_bits);
147 switch (color_bits.
size()) {
154 default_props.
set_color_bits(color_bits[0] + color_bits[1] + color_bits[2]);
155 default_props.set_red_bits(color_bits[0]);
156 default_props.set_green_bits(color_bits[1]);
157 default_props.set_blue_bits(color_bits[2]);
162 <<
"Configuration variable color-bits takes either 1 or 3 values, not " 163 << color_bits.
size() <<
"\n";
166 if (alpha_bits > 0) {
167 default_props.set_alpha_bits(alpha_bits);
169 if (stencil_bits > 0) {
170 default_props.set_stencil_bits(stencil_bits);
172 if (accum_bits > 0) {
173 default_props.set_accum_bits(accum_bits);
175 if (multisamples > 0) {
176 default_props.set_multisamples(multisamples);
179 if ((default_props._flags & FBF_force_software) != 0 &&
180 (default_props._flags & FBF_force_hardware) != 0){
181 default_props._flags &= ~(FBF_force_software | FBF_force_hardware);
184 default_ready =
true;
185 return default_props;
193 bool FrameBufferProperties::
195 if ((_flags & _flags_specified) != (other._flags & other._flags_specified)) {
199 if (_specified != other._specified) {
203 for (
int i = 0; i < FBP_COUNT; ++i) {
204 if (_property[i] != other._property[i]) {
222 _flags_specified = 0;
224 for (
int i = 0; i < FBP_COUNT; ++i) {
239 _flags &= ~other._flags_specified;
240 _flags |= other._flags & other._flags_specified;
242 for (
int i = 0; i < FBP_COUNT; ++i) {
243 if (other._specified & (1 << i)) {
244 _property[i] = other._property[i];
245 _specified |= (1 << i);
257 if ((_flags & FBF_float_depth) != 0) {
258 out <<
"float_depth ";
260 if (_property[FBP_depth_bits] > 0) {
261 out <<
"depth_bits=" << _property[FBP_depth_bits] <<
" ";
263 if ((_flags & FBF_float_color) != 0) {
264 out <<
"float_color ";
266 if ((_flags & FBF_srgb_color) != 0) {
267 out <<
"srgb_color ";
269 if ((_flags & FBF_indexed_color) != 0) {
270 out <<
"indexed_color ";
272 if (_property[FBP_color_bits] > 0) {
273 out <<
"color_bits=" << _property[FBP_color_bits] <<
" ";
275 if (_property[FBP_red_bits] > 0) {
276 out <<
"red_bits=" << _property[FBP_red_bits] <<
" ";
278 if (_property[FBP_green_bits] > 0) {
279 out <<
"green_bits=" << _property[FBP_green_bits] <<
" ";
281 if (_property[FBP_blue_bits] > 0) {
282 out <<
"blue_bits=" << _property[FBP_blue_bits] <<
" ";
284 if (_property[FBP_alpha_bits] > 0) {
285 out <<
"alpha_bits=" << _property[FBP_alpha_bits] <<
" ";
287 if (_property[FBP_stencil_bits] > 0) {
288 out <<
"stencil_bits=" << _property[FBP_stencil_bits] <<
" ";
290 if (_property[FBP_accum_bits] > 0) {
291 out <<
"accum_bits=" << _property[FBP_accum_bits] <<
" ";
293 if (_property[FBP_aux_rgba] > 0) {
294 out <<
"aux_rgba=" << _property[FBP_aux_rgba] <<
" ";
296 if (_property[FBP_aux_hrgba] > 0) {
297 out <<
"aux_hrgba=" << _property[FBP_aux_hrgba] <<
" ";
299 if (_property[FBP_aux_float] > 0) {
300 out <<
"aux_float=" << _property[FBP_aux_float] <<
" ";
302 if (_property[FBP_multisamples] > 0) {
303 out <<
"multisamples=" << _property[FBP_multisamples] <<
" ";
305 if (_property[FBP_coverage_samples] > 0) {
306 out <<
"coverage_samples=" << _property[FBP_coverage_samples] <<
" ";
308 if (_property[FBP_back_buffers] > 0) {
309 out <<
"back_buffers=" << _property[FBP_back_buffers] <<
" ";
311 if ((_flags & FBF_stereo) != 0) {
314 if ((_flags & FBF_force_hardware) != 0) {
315 out <<
"force_hardware ";
317 if ((_flags & FBF_force_software) != 0) {
318 out <<
"force_software ";
331 for (
int i=0; i<_property[FBP_aux_rgba]; i++) {
332 mask |= (RenderBuffer::T_aux_rgba_0 << i);
334 for (
int i=0; i<_property[FBP_aux_hrgba]; i++) {
335 mask |= (RenderBuffer::T_aux_hrgba_0 << i);
337 for (
int i=0; i<_property[FBP_aux_float]; i++) {
338 mask |= (RenderBuffer::T_aux_float_0 << i);
353 if (_property[FBP_back_buffers] > 0) {
354 mask = RenderBuffer::T_front | RenderBuffer::T_back;
356 mask = RenderBuffer::T_front;
358 if (_property[FBP_depth_bits] > 0) {
359 mask |= RenderBuffer::T_depth;
361 if (_property[FBP_stencil_bits] > 0) {
362 mask |= RenderBuffer::T_stencil;
375 return (_flags_specified | _specified) != 0;
385 _flags_specified = FBF_all;
386 _specified = (1 << FBP_COUNT) - 1;
399 if (_property[FBP_depth_bits] > 1) {
402 if (_property[FBP_color_bits] > 1) {
405 if (_property[FBP_red_bits] > 1) {
408 if (_property[FBP_green_bits] > 1) {
411 if (_property[FBP_blue_bits] > 1) {
414 if (_property[FBP_alpha_bits] > 1) {
417 if (_property[FBP_stencil_bits] > 0) {
420 if (_property[FBP_aux_rgba] > 0) {
423 if (_property[FBP_aux_hrgba] > 0) {
426 if (_property[FBP_aux_float] > 0) {
429 if (_property[FBP_multisamples] > 1) {
432 if (_property[FBP_coverage_samples] > 0) {
435 if (_property[FBP_back_buffers] > 0) {
438 if ((_flags & FBF_indexed_color) != 0) {
441 if ((_flags & FBF_force_hardware) != 0) {
444 if ((_flags & FBF_force_software) != 0) {
447 if ((_flags & FBF_srgb_color) != 0) {
450 if ((_flags & FBF_float_color) != 0) {
453 if ((_flags & FBF_float_depth) != 0) {
468 for (
int prop = FBP_depth_bits; prop <= FBP_accum_bits; ++prop) {
469 if (_property[prop] > 1) {
503 if (!get_indexed_color() && !get_rgb_color()) {
508 if ((reqs.get_rgb_color() && !get_rgb_color()) ||
509 (reqs.get_indexed_color() && !get_indexed_color())) {
514 int quality = 100000000;
519 if ((reqs._flags & FBF_force_hardware) > (_flags & FBF_force_hardware) ||
520 (reqs._flags & FBF_force_software) > (_flags & FBF_force_software)) {
527 for (
int prop = FBP_depth_bits; prop <= FBP_accum_bits; ++prop) {
528 if (reqs._property[prop] && _property[prop] == 0) {
536 for (
int prop = FBP_aux_rgba; prop <= FBP_aux_float; ++prop) {
537 if (reqs._property[prop] > _property[prop]) {
545 if (reqs.get_stereo() && !get_stereo()) {
552 if (reqs.get_srgb_color() && !get_srgb_color()) {
559 if (reqs.get_float_color() && !get_float_color()) {
563 if (reqs.get_float_depth() && !get_float_depth()) {
570 if (reqs._property[FBP_back_buffers] > _property[FBP_back_buffers]) {
576 if (reqs._property[FBP_multisamples] != 0 && _property[FBP_multisamples] == 0) {
583 for (
int prop = FBP_depth_bits; prop <= FBP_accum_bits; ++prop) {
584 if (_property[prop] != 0 && reqs._property[prop] > _property[prop]) {
592 if (_property[FBP_multisamples] != 0 &&
593 reqs._property[FBP_multisamples] > _property[FBP_multisamples]) {
600 for (
int prop = FBP_depth_bits; prop <= FBP_accum_bits; ++prop) {
601 if ((_property[prop]) && (reqs._property[prop] == 0)) {
605 for (
int prop = FBP_aux_rgba; prop <= FBP_aux_float; ++prop) {
606 int extra = _property[prop] > reqs._property[prop];
608 extra = min(extra, 3);
618 for (
int prop = FBP_depth_bits; prop <= FBP_accum_bits; ++prop) {
619 if (reqs._property[prop] > 1 &&
620 _property[prop] > reqs._property[prop]) {
627 if (reqs._property[FBP_depth_bits] != 0) {
628 quality += 2 * _property[FBP_depth_bits];
633 if (reqs._property[FBP_multisamples] != 0) {
634 quality += 2 * _property[FBP_multisamples];
639 if (reqs._property[FBP_coverage_samples] != 0) {
640 quality += 2 * _property[FBP_coverage_samples];
645 for (
int prop=FBP_color_bits; prop<=FBP_accum_bits; prop++) {
646 if (reqs._property[prop] != 0) {
647 quality += _property[prop];
664 if (get_force_hardware() < props.get_force_hardware()) {
666 <<
"The application requested harware acceleration, but your OpenGL\n";
668 <<
"driver, " << renderer <<
", only supports software rendering.\n";
670 <<
"You need to install a hardware-accelerated OpenGL driver, or,\n";
672 <<
"if you actually *want* to use a software renderer, then\n";
674 <<
"alter the hardware/software configuration in your Config.prc file.\n";
678 if (get_force_software() < props.get_force_software()) {
680 <<
"The application requested a software renderer, but your OpenGL\n";
682 <<
"driver, " << renderer <<
", is probably hardware-accelerated.\n";
684 <<
"If you want to allow hardware acceleration, then alter the\n";
686 <<
"hardware/software configuration in your Config.prc file.\n";
713 static const int num_formats = 12;
714 static const struct {
715 unsigned char color_bits, red_bits, green_bits, blue_bits, alpha_bits;
717 Texture::Format format;
718 } formats[num_formats] = {
720 { 1, 1, 1, 1, 0,
false, Texture::F_rgb },
721 { 1, 1, 1, 1, 1,
false, Texture::F_rgba },
722 { 24, 8, 8, 8, 0,
false, Texture::F_rgb8 },
723 { 32, 8, 8, 8, 8,
false, Texture::F_rgba8 },
724 { 16, 16, 0, 0, 0,
true, Texture::F_r16 },
725 { 32, 16, 16, 0, 0,
true, Texture::F_rg16 },
726 { 48, 16, 16, 16, 0,
true, Texture::F_rgb16 },
727 { 48, 16, 16, 16, 16,
true, Texture::F_rgba16 },
728 { 32, 32, 0, 0, 0,
true, Texture::F_r32 },
729 { 64, 32, 32, 0, 0,
true, Texture::F_rg32 },
730 { 96, 32, 32, 32, 0,
true, Texture::F_rgb32 },
731 { 96, 32, 32, 32, 32,
true, Texture::F_rgba32 },
734 if (get_srgb_color()) {
736 if (get_alpha_bits() == 0) {
742 return (get_color_bits() <= 24 &&
743 get_red_bits() <= 8 &&
744 get_green_bits() <= 8 &&
745 get_blue_bits() <= 8 &&
746 get_alpha_bits() <= 8);
749 if (get_float_color()) {
753 for (
int i = 0; i < num_formats; ++i) {
754 if (get_color_bits() <= (
int)formats[i].color_bits &&
755 get_red_bits() <= (
int)formats[i].red_bits &&
756 get_green_bits() <= (
int)formats[i].green_bits &&
757 get_blue_bits() <= (
int)formats[i].blue_bits &&
758 get_alpha_bits() <= (
int)formats[i].alpha_bits &&
759 get_float_color() <= formats[i].has_float) {
767 tex->
set_format((get_alpha_bits() == 0) ? Texture::F_rgb : Texture::F_rgba);
785 if (get_float_depth()) {
787 tex->
set_format(Texture::F_depth_component32);
788 return (get_depth_bits() <= 32);
790 }
else if (get_depth_bits() <= 1) {
794 }
else if (get_depth_bits() <= 16) {
795 tex->
set_format(Texture::F_depth_component16);
798 }
else if (get_depth_bits() <= 24) {
799 tex->
set_format(Texture::F_depth_component24);
802 }
else if (get_depth_bits() <= 32) {
803 tex->
set_format(Texture::F_depth_component32);
bool is_basic() const
Returns true if the properties are extremely basic.
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
void set_all_specified()
Marks all bits as having been specified.
void clear()
Unsets all properties that have been specified so far, and resets the FrameBufferProperties structure...
void output(ostream &out) const
Generates a string representation.
int get_aux_mask() const
Converts the aux bitplanes of the framebuffer into a RenderBuffer::Type.
void add_properties(const FrameBufferProperties &other)
Sets any properties that are explicitly specified in other on this object.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
void set_format(Format format)
Changes the format value for the texture components.
int get_buffer_mask() const
Converts the non-aux bitplanes of the framebuffer into a RenderBuffer::Type.
bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
bool setup_depth_texture(Texture *tex) const
Sets the texture up for render-to-texture matching these framebuffer properties.
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const
Validates that the properties represent the desired kind of renderer (hardware or software)...
void set_one_bit_per_channel()
If any of the depth, color, alpha, accum, or stencil properties is set to more than one...
int size() const
Returns the number of unique words in the variable.
int get_num_words() const
Returns the number of words in the variable's value.
void set_component_type(ComponentType component_type)
Changes the data value for the texture components.
bool setup_color_texture(Texture *tex) const
Sets the texture up for render-to-texture matching these framebuffer properties.
void set_color_bits(int n)
Sets the number of requested color bits as a single number that represents the sum of the individual ...
bool subsumes(const FrameBufferProperties &other) const
Returns true if this set of properties makes strictly greater or equal demands of the framebuffer tha...
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
int get_quality(const FrameBufferProperties &reqs) const
Assumes that these properties are a description of a window.