From 470e352ab87ceae6e30429720e4690c8371f5a55 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 20 Dec 2022 12:33:42 +0100 Subject: [PATCH 01/14] readme: Update version number to 1.10.13 [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47ef68448d..ba63493244 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Installing Panda3D ================== The latest Panda3D SDK can be downloaded from -[this page](https://www.panda3d.org/download/sdk-1-10-12/). +[this page](https://www.panda3d.org/download/sdk-1-10-13/). If you are familiar with installing Python packages, you can use the following command: From 2e42400700c64e9ebe00c0be7750ebf406d4a130 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 9 Jan 2023 13:19:09 +0100 Subject: [PATCH 02/14] deploy-stub: Fix crash when running in Python 3.11 Fixes #1423 --- pandatool/src/deploy-stub/deploy-stub.c | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pandatool/src/deploy-stub/deploy-stub.c b/pandatool/src/deploy-stub/deploy-stub.c index b0251be473..c9a9272b15 100644 --- a/pandatool/src/deploy-stub/deploy-stub.c +++ b/pandatool/src/deploy-stub/deploy-stub.c @@ -90,6 +90,16 @@ static struct _inittab extensions[] = { static wchar_t *log_pathw = NULL; #endif +#if PY_VERSION_HEX >= 0x030b0000 +typedef struct { + const char *name; + const unsigned char *code; + int size; +} ModuleDef; +#else +typedef struct _frozen ModuleDef; +#endif + #if defined(_WIN32) && PY_VERSION_HEX < 0x03060000 static int supports_code_page(UINT cp) { if (cp == 0) { @@ -742,7 +752,7 @@ int wmain(int argc, wchar_t *argv[]) { int main(int argc, char *argv[]) { #endif int retval; - struct _frozen *moddef; + ModuleDef *moddef; const char *log_filename; void *blob = NULL; log_filename = NULL; @@ -792,6 +802,9 @@ int main(int argc, char *argv[]) { // Offset the pointers in the module table using the base mmap address. moddef = blobinfo.pointers[0]; +#if PY_VERSION_HEX < 0x030b0000 + PyImport_FrozenModules = moddef; +#endif while (moddef->name) { moddef->name = (char *)((uintptr_t)moddef->name + (uintptr_t)blob); if (moddef->code != 0) { @@ -800,6 +813,24 @@ int main(int argc, char *argv[]) { //printf("MOD: %s %p %d\n", moddef->name, (void*)moddef->code, moddef->size); moddef++; } + + // In Python 3.11, we need to convert this to the new structure format. +#if PY_VERSION_HEX >= 0x030b0000 + ModuleDef *moddef_end = moddef; + ptrdiff_t num_modules = moddef - (ModuleDef *)blobinfo.pointers[0]; + struct _frozen *new_moddef = (struct _frozen *)calloc(num_modules + 1, sizeof(struct _frozen)); + PyImport_FrozenModules = new_moddef; + for (moddef = blobinfo.pointers[0]; moddef < moddef_end; ++moddef) { + new_moddef->name = moddef->name; + new_moddef->code = moddef->code; + new_moddef->size = moddef->size < 0 ? -(moddef->size) : moddef->size; + new_moddef->is_package = moddef->size < 0; + new_moddef->get_code = NULL; + new_moddef++; + } +#endif + } else { + PyImport_FrozenModules = blobinfo.pointers[0]; } if (log_filename != NULL) { @@ -822,12 +853,16 @@ int main(int argc, char *argv[]) { #endif // Run frozen application - PyImport_FrozenModules = blobinfo.pointers[0]; retval = Py_FrozenMain(argc, argv); fflush(stdout); fflush(stderr); +#if PY_VERSION_HEX >= 0x030b0000 + free((void *)PyImport_FrozenModules); + PyImport_FrozenModules = NULL; +#endif + unmap_blob(blob); return retval; } From 1867094afeb44a9e7a1c63140659bad9e4f54b9c Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 9 Jan 2023 13:21:37 +0100 Subject: [PATCH 03/14] Bump version number on release/1.10.x branch to 1.10.14 --- dtool/PandaVersion.pp | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dtool/PandaVersion.pp b/dtool/PandaVersion.pp index 4b071d3777..9b8f30b25d 100644 --- a/dtool/PandaVersion.pp +++ b/dtool/PandaVersion.pp @@ -7,7 +7,7 @@ // place to put this. // Use spaces to separate the major, minor, and sequence numbers here. -#define PANDA_VERSION 1 10 12 +#define PANDA_VERSION 1 10 14 // This variable will be defined to false in the CVS repository, but // scripts that generate source tarballs and/or binary releases for diff --git a/setup.cfg b/setup.cfg index 886f85f894..c3a79e56c0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = Panda3D -version = 1.10.13 +version = 1.10.14 url = https://www.panda3d.org/ description = Panda3D is a framework for 3D rendering and game development for Python and C++ programs. license = Modified BSD License From 6404704ee3898fa99027f89ac804df8f509b67c8 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 12 Jan 2023 22:51:49 +0100 Subject: [PATCH 04/14] x11display: Attempt to fix crash on shutdown with custom cursor --- panda/src/x11display/x11GraphicsWindow.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index c8ab5e1e9c..facb467f74 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -130,12 +130,6 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, */ x11GraphicsWindow:: ~x11GraphicsWindow() { - if (!_cursor_filenames.empty()) { - LightReMutexHolder holder(x11GraphicsPipe::_x_mutex); - for (auto item : _cursor_filenames) { - XFreeCursor(_display, item.second); - } - } } /** @@ -1031,6 +1025,10 @@ close_window() { _orig_size_id = -1; } + for (auto item : _cursor_filenames) { + XFreeCursor(_display, item.second); + } + GraphicsWindow::close_window(); } From 86a1973f897b9f2974dc2afd454fe8c4dc054a47 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 14:53:25 +0100 Subject: [PATCH 05/14] x11display: Clean up cursor filename map after freeing it Not essential, but slightly neater --- panda/src/x11display/x11GraphicsWindow.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index facb467f74..7e03bb73c5 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -1028,6 +1028,7 @@ close_window() { for (auto item : _cursor_filenames) { XFreeCursor(_display, item.second); } + _cursor_filenames.clear(); GraphicsWindow::close_window(); } From 21347bb2d5f2ce4fc37843aa9db627277fba1d9f Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:00:12 +0100 Subject: [PATCH 06/14] glgsg: Fix bug if same texture is used with different tex gen modes in FFP --- .../glstuff/glGraphicsStateGuardian_src.cxx | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 1b0190ab93..4de04bf814 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -11620,6 +11620,8 @@ set_state_and_transform(const RenderState *target, } int texture_slot = TextureAttrib::get_class_slot(); + int tex_gen_slot = TexGenAttrib::get_class_slot(); + int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); if (_target_rs->get_attrib(texture_slot) != _state_rs->get_attrib(texture_slot) || !_state_mask.get_bit(texture_slot)) { PStatGPUTimer timer(this, _draw_set_state_texture_pcollector); @@ -11635,7 +11637,7 @@ set_state_and_transform(const RenderState *target, _target_texture = (const TextureAttrib *) _target_rs->get_attrib_def(TextureAttrib::get_class_slot()); _target_tex_gen = (const TexGenAttrib *) - _target_rs->get_attrib_def(TexGenAttrib::get_class_slot()); + _target_rs->get_attrib_def(tex_gen_slot); } #endif do_issue_texture(); @@ -11643,28 +11645,36 @@ set_state_and_transform(const RenderState *target, // Since the TexGen and TexMatrix states depend partly on the particular // set of textures in use, we should force both of those to be reissued // every time we change the texture state. - _state_mask.clear_bit(TexGenAttrib::get_class_slot()); - _state_mask.clear_bit(TexMatrixAttrib::get_class_slot()); + _state_mask.clear_bit(tex_gen_slot); + _state_mask.clear_bit(tex_matrix_slot); _state_texture = _target_texture; _state_mask.set_bit(texture_slot); } + else if (_target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) || + !_state_mask.get_bit(tex_gen_slot)) { + _target_tex_gen = (const TexGenAttrib *)_target_rs->get_attrib_def(tex_gen_slot); - // If one of the previously-loaded TexGen modes modified the texture matrix, - // then if either state changed, we have to change both of them now. - if (_tex_gen_modifies_mat) { - int tex_gen_slot = TexGenAttrib::get_class_slot(); - int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); - if (_target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) || - _target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) || - !_state_mask.get_bit(tex_gen_slot) || - !_state_mask.get_bit(tex_matrix_slot)) { +#ifdef SUPPORT_FIXED_FUNCTION +#ifdef OPENGLES_1 + if (_has_texture_alpha_scale) { +#else + if (_has_texture_alpha_scale && _current_shader == nullptr) { +#endif + PT(TextureStage) stage = get_alpha_scale_texture_stage(); + _target_tex_gen = DCAST(TexGenAttrib, _target_tex_gen->add_stage + (stage, TexGenAttrib::M_constant, LTexCoord3(_current_color_scale[3], 0.0f, 0.0f))); + } +#endif // SUPPORT_FIXED_FUNCTION + + // If one of the previously-loaded TexGen modes modified the texture matrix, + // then if either state changed, we have to change both of them now. + if (_tex_gen_modifies_mat) { _state_mask.clear_bit(tex_gen_slot); _state_mask.clear_bit(tex_matrix_slot); } } - int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); if (_target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) || !_state_mask.get_bit(tex_matrix_slot)) { // PStatGPUTimer timer(this, _draw_set_state_tex_matrix_pcollector); @@ -11679,11 +11689,15 @@ set_state_and_transform(const RenderState *target, _current_shader_context->issue_parameters(Shader::SSD_tex_matrix); } #endif + + // See previous occurrence of this check. + if (_tex_gen_modifies_mat) { + _state_mask.clear_bit(tex_gen_slot); + } } #ifdef SUPPORT_FIXED_FUNCTION if (has_fixed_function_pipeline()) { - int tex_gen_slot = TexGenAttrib::get_class_slot(); if (_target_tex_gen != _state_tex_gen || !_state_mask.get_bit(tex_gen_slot)) { // PStatGPUTimer timer(this, _draw_set_state_tex_gen_pcollector); From 10f4c6bb21e089fc724f813fcf843d15fbeba2f3 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:01:20 +0100 Subject: [PATCH 07/14] shader: Add texconst_i shader input for Cg shaders to access TexGen constant --- panda/src/display/graphicsStateGuardian.cxx | 12 ++++++++++ panda/src/glstuff/glCgShaderContext_src.cxx | 4 ++++ panda/src/glstuff/glShaderContext_src.cxx | 4 ++++ panda/src/gobj/shader.cxx | 26 +++++++++++++++++++++ panda/src/gobj/shader.h | 4 ++++ 5 files changed, 50 insertions(+) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index b1f0961658..b06e520fd3 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1175,6 +1175,18 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, return &LMatrix4::zeros_mat(); } } + case Shader::SMO_texconst_i: { + const TexGenAttrib *tga; + const TextureAttrib *ta; + if (_target_rs->get_attrib(ta) && _target_rs->get_attrib(tga) && + index < ta->get_num_on_stages()) { + LVecBase3 value = tga->get_constant_value(ta->get_on_stage(index)); + t.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, value[0], value[1], value[2], 1); + return &t; + } else { + return &LMatrix4::ident_mat(); + } + } case Shader::SMO_tex_is_alpha_i: { // This is a hack so we can support both F_alpha and other formats in the // default shader, to fix font rendering in GLES2 diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 4a71b074c6..5d2886cf39 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -483,6 +483,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) { altered |= Shader::SSD_tex_matrix; } + if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) != + target_rs->get_attrib(TexGenAttrib::get_class_slot())) { + altered |= Shader::SSD_tex_gen; + } _state_rs = target_rs; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 79db239f35..44a22b8c71 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -2131,6 +2131,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TextureAttrib::get_class_slot())) { altered |= Shader::SSD_texture; } + if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) != + target_rs->get_attrib(TexGenAttrib::get_class_slot())) { + altered |= Shader::SSD_tex_gen; + } _state_rs = target_rs; } diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index e01c123c66..95235ba5a8 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -494,6 +494,9 @@ cp_dependency(ShaderMatInput inp) { if (inp == SMO_tex_is_alpha_i || inp == SMO_texcolor_i) { dep |= SSD_texture | SSD_frame; } + if (inp == SMO_texconst_i) { + dep |= SSD_tex_gen; + } return dep; } @@ -1218,6 +1221,29 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) { return true; } + if (pieces[0] == "texconst") { + if ((!cp_errchk_parameter_words(p,2))|| + (!cp_errchk_parameter_in(p)) || + (!cp_errchk_parameter_uniform(p))|| + (!cp_errchk_parameter_float(p,3,4))) { + return false; + } + ShaderMatSpec bind; + bind._id = p._id; + bind._piece = SMP_row3; + bind._func = SMF_first; + bind._part[0] = SMO_texconst_i; + bind._arg[0] = nullptr; + bind._part[1] = SMO_identity; + bind._arg[1] = nullptr; + bind._index = atoi(pieces[1].c_str()); + + cp_optimize_mat_spec(bind); + _mat_spec.push_back(bind); + _mat_deps |= bind._dep[0] | bind._dep[1]; + return true; + } + if (pieces[0] == "plane") { if ((!cp_errchk_parameter_words(p,2))|| (!cp_errchk_parameter_in(p)) || diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index d2035a26ea..3dc9777b26 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -214,6 +214,9 @@ public: // Color of an M_blend texture stage. SMO_texcolor_i, + // Constant value of the TexGenAttrib of stage i. + SMO_texconst_i, + SMO_INVALID }; @@ -321,6 +324,7 @@ public: SSD_projection = 0x800, SSD_texture = 0x1000, SSD_view_transform= 0x2000, + SSD_tex_gen = 0x4000, }; enum ShaderBug { From 6ad50b5cb13f6196ab570ef72bf45af840ee0d8f Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:04:04 +0100 Subject: [PATCH 08/14] ShaderGenerator: implement remaining missing TexGenAttrib modes Fixes #1437 --- panda/src/pgraphnodes/shaderGenerator.cxx | 69 +++++++++++++++++------ 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 21fdb106ec..6fd05e35e3 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -781,23 +781,34 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } } + bool need_eye_reflection = false; + bool need_fragment_view_to_world = false; + text << "void vshader(\n"; for (size_t i = 0; i < key._textures.size(); ++i) { const ShaderKey::TextureInfo &tex = key._textures[i]; switch (tex._gen_mode) { - case TexGenAttrib::M_world_position: - need_world_position = true; + case TexGenAttrib::M_world_cube_map: + need_fragment_view_to_world = true; + case TexGenAttrib::M_eye_sphere_map: + case TexGenAttrib::M_eye_cube_map: + need_eye_position = true; + need_eye_normal = true; + need_eye_reflection = true; break; case TexGenAttrib::M_world_normal: need_world_normal = true; break; - case TexGenAttrib::M_eye_position: - need_eye_position = true; - break; case TexGenAttrib::M_eye_normal: need_eye_normal = true; break; + case TexGenAttrib::M_world_position: + need_world_position = true; + break; + case TexGenAttrib::M_eye_position: + need_eye_position = true; + break; default: break; } @@ -1049,6 +1060,13 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (tex._flags & ShaderKey::TF_uses_color) { text << "\t uniform float4 texcolor_" << i << ",\n"; } + + if (tex._gen_mode == TexGenAttrib::M_constant) { + text << "\t uniform float4 texconst_" << i << ",\n"; + } + } + if (need_fragment_view_to_world) { + text << "\t uniform float3x3 trans_view_to_world,\n"; } if (need_tangents) { text << "\t in float4 l_tangent : " << tangent_freg << ",\n"; @@ -1119,6 +1137,17 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (need_eye_normal && pack_eye_normal) { text << "\t float3 l_eye_normal = float3(l_tangent.w, l_binormal.w, l_eye_position.w);\n"; } + if (need_eye_normal) { + text << "\t // Correct the surface normal for interpolation effects\n"; + text << "\t l_eye_normal = normalize(l_eye_normal);\n"; + } + if (need_eye_reflection || + (need_eye_position && have_specular && (key._material_flags & Material::F_local) != 0 && !key._lights.empty())) { + text << "\t float3 norm_eye_position = normalize(l_eye_position.xyz);\n"; + } + if (need_eye_reflection) { + text << "\t float3 eye_reflection = norm_eye_position - l_eye_normal * 2 * dot(l_eye_normal, norm_eye_position);\n"; + } text << "\t float4 result;\n"; if (key._outputs & (AuxBitplaneAttrib::ABO_aux_normal | AuxBitplaneAttrib::ABO_aux_glow)) { @@ -1137,17 +1166,29 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { // Cg seems to be able to optimize this temporary away when appropriate. text << "\t float4 texcoord" << i << " = l_" << tex._texcoord_name->join("_") << ";\n"; break; - case TexGenAttrib::M_world_position: - text << "\t float4 texcoord" << i << " = l_world_position;\n"; + case TexGenAttrib::M_eye_sphere_map: + text << "\t float4 texcoord" << i << " = float4(eye_reflection.xz * (1.0f / (2.0f * length(eye_reflection + float3(0, -1, 0)))) + float2(0.5f, 0.5f), 0.0f, 1.0f);\n"; + break; + case TexGenAttrib::M_world_cube_map: + text << "\t float4 texcoord" << i << " = float4(mul(trans_view_to_world, eye_reflection), 1.0f);\n"; + break; + case TexGenAttrib::M_eye_cube_map: + text << "\t float4 texcoord" << i << " = float4(eye_reflection, 1.0f);\n"; break; case TexGenAttrib::M_world_normal: text << "\t float4 texcoord" << i << " = l_world_normal;\n"; break; + case TexGenAttrib::M_eye_normal: + text << "\t float4 texcoord" << i << " = float4(l_eye_normal, 1.0f);\n"; + break; + case TexGenAttrib::M_world_position: + text << "\t float4 texcoord" << i << " = l_world_position;\n"; + break; case TexGenAttrib::M_eye_position: text << "\t float4 texcoord" << i << " = float4(l_eye_position.xyz, 1.0f);\n"; break; - case TexGenAttrib::M_eye_normal: - text << "\t float4 texcoord" << i << " = float4(l_eye_normal, 1.0f);\n"; + case TexGenAttrib::M_constant: + text << "\t float4 texcoord" << i << " = texconst_" << i << ";\n"; break; default: text << "\t float4 texcoord" << i << " = float4(0, 0, 0, 0);\n"; @@ -1237,10 +1278,6 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << ");\n"; } } - if (need_eye_normal) { - text << "\t // Correct the surface normal for interpolation effects\n"; - text << "\t l_eye_normal = normalize(l_eye_normal);\n"; - } if (need_tangents) { text << "\t // Translate tangent-space normal in map to view-space.\n"; @@ -1335,7 +1372,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0, 1, 0));\n"; } @@ -1370,7 +1407,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0, 1, 0));\n"; } @@ -1410,7 +1447,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0,1,0));\n"; } From 709555577f638b9ee6d18c1e860e0827b427ac66 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:12:01 +0100 Subject: [PATCH 09/14] ShaderGenerator: Add support for perspective points Fixes #1440 --- panda/src/display/graphicsStateGuardian.cxx | 28 +++++++++++++++++ panda/src/glstuff/glCgShaderContext_src.cxx | 4 +++ panda/src/glstuff/glShaderContext_src.cxx | 5 +++ panda/src/gobj/shader.cxx | 14 +++++++++ panda/src/gobj/shader.h | 4 +++ panda/src/pgraphnodes/shaderGenerator.cxx | 35 +++++++++++++++++---- panda/src/pgraphnodes/shaderGenerator.h | 1 + 7 files changed, 85 insertions(+), 6 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index b06e520fd3..1a39fd4ca6 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -57,6 +57,7 @@ #include "colorScaleAttrib.h" #include "clipPlaneAttrib.h" #include "fogAttrib.h" +#include "renderModeAttrib.h" #include "config_pstatclient.h" #include @@ -1508,6 +1509,33 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, } return &t; } + case Shader::SMO_attr_pointparams: { + const RenderModeAttrib *target_render_mode; + _target_rs->get_attrib_def(target_render_mode); + + PN_stdfloat thickness = target_render_mode->get_thickness(); + PN_stdfloat catten = thickness; + PN_stdfloat patten = 0.0f; + if (target_render_mode->get_perspective()) { + LVecBase2i pixel_size = _current_display_region->get_pixel_size(); + + LVector3 height(0.0f, thickness, 1.0f); + height = height * _projection_mat->get_mat(); + height = height * _internal_transform->get_scale()[1]; + PN_stdfloat s = height[1] * pixel_size[1]; + + if (_current_lens->is_orthographic()) { + catten = s; + patten = 0.0f; + } else { + catten = 0.0f; + patten = s; + } + } + + t.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, thickness, catten, patten, 0.0f); + return &t; + } default: nassertr(false /*should never get here*/, &LMatrix4::ident_mat()); return &LMatrix4::ident_mat(); diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 5d2886cf39..fdfe2f2902 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -487,6 +487,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexGenAttrib::get_class_slot())) { altered |= Shader::SSD_tex_gen; } + if (state_rs->get_attrib(RenderModeAttrib::get_class_slot()) != + target_rs->get_attrib(RenderModeAttrib::get_class_slot())) { + altered |= Shader::SSD_render_mode; + } _state_rs = target_rs; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 44a22b8c71..34d6c1a706 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -25,6 +25,7 @@ #include "fogAttrib.h" #include "lightAttrib.h" #include "clipPlaneAttrib.h" +#include "renderModeAttrib.h" #include "bamCache.h" using std::dec; @@ -2135,6 +2136,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexGenAttrib::get_class_slot())) { altered |= Shader::SSD_tex_gen; } + if (state_rs->get_attrib(RenderModeAttrib::get_class_slot()) != + target_rs->get_attrib(RenderModeAttrib::get_class_slot())) { + altered |= Shader::SSD_render_mode; + } _state_rs = target_rs; } diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 95235ba5a8..6e911dfd5e 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -497,6 +497,9 @@ cp_dependency(ShaderMatInput inp) { if (inp == SMO_texconst_i) { dep |= SSD_tex_gen; } + if (inp == SMO_attr_pointparams) { + dep |= SSD_render_mode | SSD_transform | SSD_frame; + } return dep; } @@ -1039,6 +1042,17 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) { bind._part[1] = SMO_identity; bind._arg[1] = nullptr; bind._index = atoi(pieces[1].c_str() + 5); + } else if (pieces[1] == "pointparams") { + if (!cp_errchk_parameter_float(p,3,4)) { + return false; + } + bind._id = p._id; + bind._piece = SMP_row3; + bind._func = SMF_first; + bind._part[0] = SMO_attr_pointparams; + bind._arg[0] = nullptr; + bind._part[1] = SMO_identity; + bind._arg[1] = nullptr; } else { cp_report_error(p,"Unknown attr parameter."); return false; diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 3dc9777b26..ef7d6ceef4 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -217,6 +217,9 @@ public: // Constant value of the TexGenAttrib of stage i. SMO_texconst_i, + // Point parameters + SMO_attr_pointparams, + SMO_INVALID }; @@ -325,6 +328,7 @@ public: SSD_texture = 0x1000, SSD_view_transform= 0x2000, SSD_tex_gen = 0x4000, + SSD_render_mode = 0x8000, }; enum ShaderBug { diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 6fd05e35e3..5c9acef6d4 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -38,6 +38,7 @@ #include "texture.h" #include "ambientLight.h" #include "directionalLight.h" +#include "renderModeAttrib.h" #include "rescaleNormalAttrib.h" #include "pointLight.h" #include "sphereLight.h" @@ -567,6 +568,12 @@ analyze_renderstate(ShaderKey &key, const RenderState *rs) { if (rs->get_attrib(fog) && !fog->is_off()) { key._fog_mode = (int)fog->get_fog()->get_mode() + 1; } + + // Hijack this field for the perspective render-mode flag. + const RenderModeAttrib *render_mode; + if (rs->get_attrib(render_mode) && render_mode->get_perspective()) { + key._fog_mode |= 0x10000; + } } /** @@ -754,6 +761,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { bool need_eye_position = key._lighting; bool need_eye_normal = !key._lights.empty() || ((key._outputs & AuxBitplaneAttrib::ABO_aux_normal) != 0); bool need_tangents = ((key._texture_flags & ShaderKey::TF_map_normal) != 0); + bool need_point_size = (key._fog_mode & 0x10000) != 0; // If we have binormal/tangent and eye position, we can pack eye normal in // the w channels of the others. @@ -877,7 +885,8 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t uniform float4x4 trans_model_to_view,\n"; eye_position_freg = alloc_freg(); text << "\t out float4 l_eye_position : " << eye_position_freg << ",\n"; - } else if (need_tangents) { + } + else if (need_tangents || need_point_size) { text << "\t uniform float4x4 trans_model_to_view,\n"; } if (need_eye_normal) { @@ -894,7 +903,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t uniform float4 mspos_view,\n"; text << "\t out float3 l_eyevec,\n"; } - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { hpos_freg = alloc_freg(); text << "\t out float4 l_hpos : " << hpos_freg << ",\n"; } @@ -934,6 +943,10 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t in uint4 vtx_transform_index : " << transform_index_vreg << ",\n"; } } + if (need_point_size) { + text << "\t uniform float3 attr_pointparams,\n"; + text << "\t out float l_point_size : PSIZE,\n"; + } text << "\t in float4 vtx_position : " << position_vreg << ",\n"; text << "\t out float4 l_position : POSITION,\n"; text << "\t uniform float4x4 mat_modelproj\n"; @@ -965,7 +978,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } text << "\t l_position = mul(mat_modelproj, vtx_position);\n"; - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { text << "\t l_hpos = l_position;\n"; } if (need_world_position) { @@ -977,6 +990,13 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (need_eye_position) { text << "\t l_eye_position = mul(trans_model_to_view, vtx_position);\n"; } + else if (need_point_size) { + text << "\t float4 l_eye_position = mul(trans_model_to_view, vtx_position);\n"; + } + if (need_point_size) { + text << "\t l_point_size = attr_pointparams.y + attr_pointparams.z / length(l_eye_position.xyz);\n"; + } + pmap::const_iterator it; for (it = texcoord_fregs.begin(); it != texcoord_fregs.end(); ++it) { // Pass through all texcoord inputs as-is. @@ -1022,7 +1042,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { // Fragment shader text << "void fshader(\n"; - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { text << "\t in float4 l_hpos : " << hpos_freg << ",\n"; text << "\t in uniform float4 attr_fog,\n"; text << "\t in uniform float4 attr_fogcolor,\n"; @@ -1717,8 +1737,8 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } // Apply fog. - if (key._fog_mode != 0) { - Fog::Mode fog_mode = (Fog::Mode)(key._fog_mode - 1); + if ((key._fog_mode & 0xffff) != 0) { + Fog::Mode fog_mode = (Fog::Mode)((key._fog_mode & 0xffff) - 1); switch (fog_mode) { case Fog::M_linear: text << "\t result.rgb = lerp(attr_fogcolor.rgb, result.rgb, saturate((attr_fog.z - l_hpos.z) * attr_fog.w));\n"; @@ -1759,6 +1779,9 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (key._disable_alpha_write) { shattr = DCAST(ShaderAttrib, shattr)->set_flag(ShaderAttrib::F_disable_alpha_write, true); } + if (need_point_size) { + shattr = DCAST(ShaderAttrib, shattr)->set_flag(ShaderAttrib::F_shader_point_size, true); + } reset_register_allocator(); diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index dd5b3456c5..749f25a35d 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -151,6 +151,7 @@ protected: bool _lighting; bool _have_separate_ambient; + // Also contains bit 0x10000 indicating perspective point mode int _fog_mode; int _outputs; From 67c413f089ed79d5cf590c79f5bd2043a029c26d Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:19:16 +0100 Subject: [PATCH 10/14] dxgsg9: Fix issues setting some kinds of automatic shader inputs --- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 20 ++++++------- panda/src/dxgsg9/dxShaderContext9.cxx | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 963cf96141..b4e2834a00 100644 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3139,6 +3139,7 @@ set_state_and_transform(const RenderState *target, } _target_rs = target; + int shader_deps = 0; determine_target_shader(); int alpha_test_slot = AlphaTestAttrib::get_class_slot(); @@ -3168,10 +3169,7 @@ set_state_and_transform(const RenderState *target, do_issue_color_scale(); _state_mask.set_bit(color_slot); _state_mask.set_bit(color_scale_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_color); - _current_shader_context->issue_parameters(this, Shader::SSD_colorscale); - } + shader_deps |= Shader::SSD_color | Shader::SSD_colorscale; } int cull_face_slot = CullFaceAttrib::get_class_slot(); @@ -3212,6 +3210,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_render_mode_pcollector); do_issue_render_mode(); _state_mask.set_bit(render_mode_slot); + shader_deps |= Shader::SSD_render_mode; } int rescale_normal_slot = RescaleNormalAttrib::get_class_slot(); @@ -3272,6 +3271,7 @@ set_state_and_transform(const RenderState *target, _state_mask.set_bit(texture_slot); _state_mask.set_bit(tex_matrix_slot); _state_mask.set_bit(tex_gen_slot); + shader_deps |= Shader::SSD_tex_matrix | Shader::SSD_tex_gen; } int material_slot = MaterialAttrib::get_class_slot(); @@ -3280,9 +3280,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_material_pcollector); do_issue_material(); _state_mask.set_bit(material_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_material); - } + shader_deps |= Shader::SSD_material; } int light_slot = LightAttrib::get_class_slot(); @@ -3307,9 +3305,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_fog_pcollector); do_issue_fog(); _state_mask.set_bit(fog_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_fog); - } + shader_deps |= Shader::SSD_fog; } int scissor_slot = ScissorAttrib::get_class_slot(); @@ -3320,6 +3316,10 @@ set_state_and_transform(const RenderState *target, _state_mask.set_bit(scissor_slot); } + if (_current_shader_context != nullptr && shader_deps != 0) { + _current_shader_context->issue_parameters(this, shader_deps); + } + _state_rs = _target_rs; } diff --git a/panda/src/dxgsg9/dxShaderContext9.cxx b/panda/src/dxgsg9/dxShaderContext9.cxx index a737c342bf..bd3dec1bc0 100644 --- a/panda/src/dxgsg9/dxShaderContext9.cxx +++ b/panda/src/dxgsg9/dxShaderContext9.cxx @@ -245,6 +245,7 @@ issue_parameters(GSG *gsg, int altered) { HRESULT hr; PN_stdfloat v [4]; LMatrix4f temp_matrix = LCAST(float, *val); + LMatrix3f temp_matrix3; hr = D3D_OK; @@ -306,6 +307,33 @@ issue_parameters(GSG *gsg, int altered) { hr = cgD3D9SetUniform(p, v); break; + case Shader::SMP_upper3x3: + // TRANSPOSE REQUIRED + temp_matrix3 = temp_matrix.get_upper_3(); + temp_matrix3.transpose_in_place(); + data = temp_matrix3.get_data(); + + hr = cgD3D9SetUniform(p, data); + break; + + case Shader::SMP_transpose3x3: + // NO TRANSPOSE REQUIRED + temp_matrix3 = temp_matrix.get_upper_3(); + data = temp_matrix3.get_data(); + + hr = cgD3D9SetUniform(p, data); + break; + + case Shader::SMP_cell15: + hr = cgD3D9SetUniform(p, data + 15); + continue; + case Shader::SMP_cell14: + hr = cgD3D9SetUniform(p, data + 14); + continue; + case Shader::SMP_cell13: + hr = cgD3D9SetUniform(p, data + 13); + continue; + default: dxgsg9_cat.error() << "issue_parameters () SMP parameter type not implemented " << spec._piece << "\n"; From 7a8e218da7447f489dd0264e4ad6667143186886 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:35:45 +0100 Subject: [PATCH 11/14] glgsg: Correctly handle 4-component texcoords in default shader --- .../glstuff/glGraphicsStateGuardian_src.cxx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 4de04bf814..0bb976eb25 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -171,23 +171,23 @@ static const string default_vshader = #endif "in vec4 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in vec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in vec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" #else "#version 100\n" "precision mediump float;\n" "attribute vec4 p3d_Vertex;\n" "attribute vec4 p3d_Color;\n" - "attribute vec2 p3d_MultiTexCoord0;\n" - "varying vec2 texcoord;\n" + "attribute vec4 p3d_MultiTexCoord0;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" #endif "uniform mat4 p3d_ModelViewProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" " gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;\n" - " texcoord = p3d_MultiTexCoord0;\n" + " texcoord = p3d_MultiTexCoord0.xyw;\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -203,15 +203,15 @@ static const string default_vshader_fp64 = "#extension GL_ARB_gpu_shader_fp64 : require\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = vec2(p3d_MultiTexCoord0);\n" + " texcoord = vec3(p3d_MultiTexCoord0.xyw);\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -220,15 +220,15 @@ static const string default_vshader_fp64_gl41 = "#version 410\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = vec2(p3d_MultiTexCoord0);\n" + " texcoord = vec3(p3d_MultiTexCoord0.xyw);\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; #endif @@ -240,7 +240,7 @@ static const string default_fshader = #else "#version 130\n" #endif - "in vec2 texcoord;\n" + "in vec3 texcoord;\n" "in vec4 color;\n" "out vec4 p3d_FragColor;\n" "uniform sampler2D p3d_Texture0;\n" @@ -248,18 +248,18 @@ static const string default_fshader = #else "#version 100\n" "precision mediump float;\n" - "varying vec2 texcoord;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" "uniform lowp sampler2D p3d_Texture0;\n" "uniform lowp vec4 p3d_TexAlphaOnly;\n" #endif "void main(void) {\n" #ifndef OPENGLES - " p3d_FragColor = texture(p3d_Texture0, texcoord);\n" + " p3d_FragColor = textureProj(p3d_Texture0, texcoord);\n" " p3d_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " p3d_FragColor *= color;\n" #else - " gl_FragColor = texture2D(p3d_Texture0, texcoord);\n" + " gl_FragColor = texture2DProj(p3d_Texture0, texcoord);\n" " gl_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " gl_FragColor *= color;\n" #endif From 8c5e2e74f5c88525e9451e1857aa026e792a83fa Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:03:33 +0100 Subject: [PATCH 12/14] cocoa: Fix undecorated setting ignored when switching off fullscreen --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 2063327f85..ea2ed0d085 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -918,8 +918,12 @@ set_properties_now(WindowProperties &properties) { _properties.set_fullscreen(false); // Force properties to be reset to their actual values - properties.set_undecorated(_properties.get_undecorated()); - properties.set_z_order(_properties.get_z_order()); + if (!properties.has_undecorated()) { + properties.set_undecorated(_properties.get_undecorated()); + } + if (!properties.has_z_order()) { + properties.set_z_order(_properties.get_z_order()); + } properties.clear_fullscreen(); } } From 76386bc4c044b2275bd52957c3298c3a18599b16 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:04:42 +0100 Subject: [PATCH 13/14] cocoa: Fix window sizing bug when simultaneously changing undecorated --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index ea2ed0d085..8517dd4136 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -940,6 +940,58 @@ set_properties_now(WindowProperties &properties) { properties.clear_minimized(); } + if (properties.has_title() && _window != nil) { + _properties.set_title(properties.get_title()); + [_window setTitle:[NSString stringWithUTF8String:properties.get_title().c_str()]]; + properties.clear_title(); + } + + if (properties.has_fixed_size() && _window != nil) { + _properties.set_fixed_size(properties.get_fixed_size()); + [_window setShowsResizeIndicator:!properties.get_fixed_size()]; + + if (!_properties.get_fullscreen()) { + // If our window is decorated, change the style mask to show or hide the + // resize button appropriately. However, if we're specifying the + // 'undecorated' property also, then we'll be setting the style mask + // about 25 LOC further down, so we won't need to bother setting it + // here. + if (!properties.has_undecorated() && !_properties.get_undecorated() && + [_window respondsToSelector:@selector(setStyleMask:)]) { + if (properties.get_fixed_size()) { + [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask ]; + } else { + [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask ]; + } + [_window makeFirstResponder:_view]; + } + } + + properties.clear_fixed_size(); + } + + if (properties.has_undecorated() && _window != nil && [_window respondsToSelector:@selector(setStyleMask:)]) { + _properties.set_undecorated(properties.get_undecorated()); + + if (!_properties.get_fullscreen()) { + if (properties.get_undecorated()) { + [_window setStyleMask: NSBorderlessWindowMask]; + } else if (_properties.get_fixed_size()) { + // Fixed size windows should not show the resize button. + [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask ]; + } else { + [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask ]; + } + [_window makeFirstResponder:_view]; + } + + properties.clear_undecorated(); + } + if (properties.has_size()) { int width = properties.get_x_size(); int height = properties.get_y_size(); @@ -1065,58 +1117,6 @@ set_properties_now(WindowProperties &properties) { properties.clear_origin(); } - if (properties.has_title() && _window != nil) { - _properties.set_title(properties.get_title()); - [_window setTitle:[NSString stringWithUTF8String:properties.get_title().c_str()]]; - properties.clear_title(); - } - - if (properties.has_fixed_size() && _window != nil) { - _properties.set_fixed_size(properties.get_fixed_size()); - [_window setShowsResizeIndicator:!properties.get_fixed_size()]; - - if (!_properties.get_fullscreen()) { - // If our window is decorated, change the style mask to show or hide the - // resize button appropriately. However, if we're specifying the - // 'undecorated' property also, then we'll be setting the style mask - // about 25 LOC further down, so we won't need to bother setting it - // here. - if (!properties.has_undecorated() && !_properties.get_undecorated() && - [_window respondsToSelector:@selector(setStyleMask:)]) { - if (properties.get_fixed_size()) { - [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask ]; - } else { - [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask ]; - } - [_window makeFirstResponder:_view]; - } - } - - properties.clear_fixed_size(); - } - - if (properties.has_undecorated() && _window != nil && [_window respondsToSelector:@selector(setStyleMask:)]) { - _properties.set_undecorated(properties.get_undecorated()); - - if (!_properties.get_fullscreen()) { - if (properties.get_undecorated()) { - [_window setStyleMask: NSBorderlessWindowMask]; - } else if (_properties.get_fixed_size()) { - // Fixed size windows should not show the resize button. - [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask ]; - } else { - [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask ]; - } - [_window makeFirstResponder:_view]; - } - - properties.clear_undecorated(); - } - if (properties.has_foreground() && !_properties.get_fullscreen() && _window != nil) { _properties.set_foreground(properties.get_foreground()); if (!_properties.get_minimized()) { From e696ac4046878b68b123d3b2eaa0ce5867b29a82 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:05:06 +0100 Subject: [PATCH 14/14] cocoa: Fix black bar when switching to fullscreen while z-order is top --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 8517dd4136..f65e97a0cc 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -851,7 +851,12 @@ set_properties_now(WindowProperties &properties) { if (switched) { if (_window != nil) { // For some reason, setting the style mask makes it give up its - // first-responder status. + // first-responder status. And for some reason, we need to first + // restore the window to normal level before we switch fullscreen, + // otherwise we may get a black bar if we're currently on Z_top. + if (_properties.get_z_order() != WindowProperties::Z_normal) { + [_window setLevel: NSNormalWindowLevel]; + } if ([_window respondsToSelector:@selector(setStyleMask:)]) { [_window setStyleMask:NSBorderlessWindowMask]; }