mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Reduce redundant state changes and error checks
This commit is contained in:
parent
059f67d1b5
commit
b323d73622
@ -616,6 +616,35 @@ enable_polygon_offset(bool val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GLGraphicsStateGuardian::set_color_write_mask
|
||||||
|
// Access: Protected
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE void CLP(GraphicsStateGuardian)::
|
||||||
|
set_color_write_mask(int mask) {
|
||||||
|
if (gl_color_mask && _active_color_write_mask != mask) {
|
||||||
|
_active_color_write_mask = mask;
|
||||||
|
glColorMask((_color_write_mask & ColorWriteAttrib::C_red) != 0,
|
||||||
|
(_color_write_mask & ColorWriteAttrib::C_green) != 0,
|
||||||
|
(_color_write_mask & ColorWriteAttrib::C_blue) != 0,
|
||||||
|
(_color_write_mask & ColorWriteAttrib::C_alpha) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GLGraphicsStateGuardian::clear_color_write_mask
|
||||||
|
// Access: Protected
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE void CLP(GraphicsStateGuardian)::
|
||||||
|
clear_color_write_mask() {
|
||||||
|
if (gl_color_mask && _active_color_write_mask != ColorWriteAttrib::C_all) {
|
||||||
|
_active_color_write_mask = ColorWriteAttrib::C_all;
|
||||||
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GLGraphicsStateGuardian::call_glFogfv
|
// Function: GLGraphicsStateGuardian::call_glFogfv
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -51,7 +51,6 @@
|
|||||||
#include "bamCacheRecord.h"
|
#include "bamCacheRecord.h"
|
||||||
#include "alphaTestAttrib.h"
|
#include "alphaTestAttrib.h"
|
||||||
#include "clipPlaneAttrib.h"
|
#include "clipPlaneAttrib.h"
|
||||||
#include "colorWriteAttrib.h"
|
|
||||||
#include "cullFaceAttrib.h"
|
#include "cullFaceAttrib.h"
|
||||||
#include "depthOffsetAttrib.h"
|
#include "depthOffsetAttrib.h"
|
||||||
#include "depthWriteAttrib.h"
|
#include "depthWriteAttrib.h"
|
||||||
@ -2094,6 +2093,7 @@ reset() {
|
|||||||
_polygon_offset_enabled = false;
|
_polygon_offset_enabled = false;
|
||||||
_flat_shade_model = false;
|
_flat_shade_model = false;
|
||||||
_decal_level = 0;
|
_decal_level = 0;
|
||||||
|
_active_color_write_mask = ColorWriteAttrib::C_all;
|
||||||
_tex_gen_point_sprite = false;
|
_tex_gen_point_sprite = false;
|
||||||
|
|
||||||
#ifndef OPENGLES
|
#ifndef OPENGLES
|
||||||
@ -2447,9 +2447,7 @@ clear(DrawableRegion *clearable) {
|
|||||||
if (clearable->get_clear_color_active()) {
|
if (clearable->get_clear_color_active()) {
|
||||||
LColor v = clearable->get_clear_color();
|
LColor v = clearable->get_clear_color();
|
||||||
glClearColor(v[0], v[1], v[2], v[3]);
|
glClearColor(v[0], v[1], v[2], v[3]);
|
||||||
if (gl_color_mask) {
|
clear_color_write_mask();
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
||||||
}
|
|
||||||
_state_mask.clear_bit(ColorWriteAttrib::get_class_slot());
|
_state_mask.clear_bit(ColorWriteAttrib::get_class_slot());
|
||||||
mask |= GL_COLOR_BUFFER_BIT;
|
mask |= GL_COLOR_BUFFER_BIT;
|
||||||
}
|
}
|
||||||
@ -2944,10 +2942,14 @@ end_frame(Thread *current_thread) {
|
|||||||
if (_check_errors || (_supports_debug && gl_debug)) {
|
if (_check_errors || (_supports_debug && gl_debug)) {
|
||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
} else {
|
} else {
|
||||||
PStatTimer timer(_check_error_pcollector);
|
static int frame_counter = -1;
|
||||||
|
|
||||||
// If _check_errors is false, we still want to check for errors
|
// If _check_errors is false, we still want to check for errors
|
||||||
// once during this frame, so that we know if anything went wrong.
|
// the first few frames and once every N frames, so that we know if
|
||||||
|
// anything went wrong at all.
|
||||||
|
if (frame_counter++ <= 0) {
|
||||||
|
PStatTimer timer(_check_error_pcollector);
|
||||||
|
|
||||||
GLenum error_code = glGetError();
|
GLenum error_code = glGetError();
|
||||||
if (error_code != GL_NO_ERROR) {
|
if (error_code != GL_NO_ERROR) {
|
||||||
int error_count = 0;
|
int error_count = 0;
|
||||||
@ -2974,6 +2976,10 @@ end_frame(Thread *current_thread) {
|
|||||||
panic_deactivate();
|
panic_deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (frame_counter > 100) {
|
||||||
|
// 100 frames have passed. Check next frame.
|
||||||
|
frame_counter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -5257,9 +5263,7 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z,
|
|||||||
const DisplayRegion *dr, const RenderBuffer &rb) {
|
const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||||
nassertr(tex != NULL && dr != NULL, false);
|
nassertr(tex != NULL && dr != NULL, false);
|
||||||
set_read_buffer(rb._buffer_type);
|
set_read_buffer(rb._buffer_type);
|
||||||
if (gl_color_mask) {
|
clear_color_write_mask();
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int xo, yo, w, h;
|
int xo, yo, w, h;
|
||||||
dr->get_region_pixels(xo, yo, w, h);
|
dr->get_region_pixels(xo, yo, w, h);
|
||||||
@ -5473,9 +5477,7 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z,
|
|||||||
nassertr(tex != NULL && dr != NULL, false);
|
nassertr(tex != NULL && dr != NULL, false);
|
||||||
set_read_buffer(rb._buffer_type);
|
set_read_buffer(rb._buffer_type);
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
if (gl_color_mask) {
|
clear_color_write_mask();
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bug fix for RE, RE2, and VTX - need to disable texturing in order
|
// Bug fix for RE, RE2, and VTX - need to disable texturing in order
|
||||||
// for glReadPixels() to work
|
// for glReadPixels() to work
|
||||||
@ -5806,7 +5808,7 @@ do_issue_render_mode() {
|
|||||||
_target_rs->get_attrib_def(target_render_mode);
|
_target_rs->get_attrib_def(target_render_mode);
|
||||||
|
|
||||||
_render_mode = target_render_mode->get_mode();
|
_render_mode = target_render_mode->get_mode();
|
||||||
_point_size = target_render_mode->get_thickness();
|
PN_stdfloat thickness = target_render_mode->get_thickness();
|
||||||
_point_perspective = target_render_mode->get_perspective();
|
_point_perspective = target_render_mode->get_perspective();
|
||||||
|
|
||||||
#ifndef OPENGLES // glPolygonMode not supported by OpenGL ES.
|
#ifndef OPENGLES // glPolygonMode not supported by OpenGL ES.
|
||||||
@ -5832,10 +5834,13 @@ do_issue_render_mode() {
|
|||||||
#endif // OPENGLES
|
#endif // OPENGLES
|
||||||
|
|
||||||
// The thickness affects both the line width and the point size.
|
// The thickness affects both the line width and the point size.
|
||||||
|
if (thickness != _point_size) {
|
||||||
glLineWidth(_point_size);
|
glLineWidth(_point_size);
|
||||||
#ifndef OPENGLES_2
|
#ifndef OPENGLES_2
|
||||||
glPointSize(_point_size);
|
glPointSize(_point_size);
|
||||||
#endif
|
#endif
|
||||||
|
_point_size = thickness;
|
||||||
|
}
|
||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
|
|
||||||
do_point_size();
|
do_point_size();
|
||||||
@ -6261,7 +6266,7 @@ do_issue_blending() {
|
|||||||
enable_multisample_alpha_mask(false);
|
enable_multisample_alpha_mask(false);
|
||||||
if (gl_color_mask) {
|
if (gl_color_mask) {
|
||||||
enable_blend(false);
|
enable_blend(false);
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
set_color_write_mask(ColorWriteAttrib::C_off);
|
||||||
} else {
|
} else {
|
||||||
enable_blend(true);
|
enable_blend(true);
|
||||||
_glBlendEquation(GL_FUNC_ADD);
|
_glBlendEquation(GL_FUNC_ADD);
|
||||||
@ -6269,14 +6274,8 @@ do_issue_blending() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (gl_color_mask) {
|
set_color_write_mask(color_channels);
|
||||||
glColorMask((color_channels & ColorWriteAttrib::C_red) != 0,
|
|
||||||
(color_channels & ColorWriteAttrib::C_green) != 0,
|
|
||||||
(color_channels & ColorWriteAttrib::C_blue) != 0,
|
|
||||||
(color_channels & ColorWriteAttrib::C_alpha) != 0);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const ColorBlendAttrib *target_color_blend;
|
const ColorBlendAttrib *target_color_blend;
|
||||||
_target_rs->get_attrib_def(target_color_blend);
|
_target_rs->get_attrib_def(target_color_blend);
|
||||||
@ -7029,12 +7028,7 @@ set_draw_buffer(int rbtype) {
|
|||||||
#endif // OPENGLES
|
#endif // OPENGLES
|
||||||
|
|
||||||
// Also ensure that any global color channels are masked out.
|
// Also ensure that any global color channels are masked out.
|
||||||
if (gl_color_mask) {
|
set_color_write_mask(_color_write_mask);
|
||||||
glColorMask((_color_write_mask & ColorWriteAttrib::C_red) != 0,
|
|
||||||
(_color_write_mask & ColorWriteAttrib::C_green) != 0,
|
|
||||||
(_color_write_mask & ColorWriteAttrib::C_blue) != 0,
|
|
||||||
(_color_write_mask & ColorWriteAttrib::C_alpha) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "displayRegion.h"
|
#include "displayRegion.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
#include "colorWriteAttrib.h"
|
||||||
#include "depthTestAttrib.h"
|
#include "depthTestAttrib.h"
|
||||||
#include "textureAttrib.h"
|
#include "textureAttrib.h"
|
||||||
#include "texMatrixAttrib.h"
|
#include "texMatrixAttrib.h"
|
||||||
@ -443,6 +444,9 @@ protected:
|
|||||||
INLINE void enable_alpha_test(bool val);
|
INLINE void enable_alpha_test(bool val);
|
||||||
INLINE void enable_polygon_offset(bool val);
|
INLINE void enable_polygon_offset(bool val);
|
||||||
|
|
||||||
|
INLINE void set_color_write_mask(int mask);
|
||||||
|
INLINE void clear_color_write_mask();
|
||||||
|
|
||||||
INLINE void call_glFogfv(GLenum pname, const LColor &color);
|
INLINE void call_glFogfv(GLenum pname, const LColor &color);
|
||||||
INLINE void call_glMaterialfv(GLenum face, GLenum pname, const LColor &color);
|
INLINE void call_glMaterialfv(GLenum face, GLenum pname, const LColor &color);
|
||||||
INLINE void call_glLightfv(GLenum light, GLenum pname, const LVecBase4 &value);
|
INLINE void call_glLightfv(GLenum light, GLenum pname, const LVecBase4 &value);
|
||||||
@ -539,6 +543,7 @@ protected:
|
|||||||
bool _polygon_offset_enabled;
|
bool _polygon_offset_enabled;
|
||||||
bool _flat_shade_model;
|
bool _flat_shade_model;
|
||||||
int _decal_level;
|
int _decal_level;
|
||||||
|
int _active_color_write_mask;
|
||||||
|
|
||||||
bool _dithering_enabled;
|
bool _dithering_enabled;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user