diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 970c09c108..fe384776bd 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -687,11 +687,7 @@ handle_update_field() { PyObject_GetAttrString(_python_repository, "doId2do"); nassertr(doId2do != nullptr, false); - #ifdef USE_PYTHON_2_2_OR_EARLIER - PyObject *doId = PyInt_FromLong(do_id); - #else PyObject *doId = PyLong_FromUnsignedLong(do_id); - #endif PyObject *distobj = PyDict_GetItem(doId2do, doId); Py_DECREF(doId); Py_DECREF(doId2do); @@ -778,11 +774,7 @@ handle_update_field_owner() { PyObject_GetAttrString(_python_repository, "doId2ownerView"); nassertr(doId2ownerView != nullptr, false); - #ifdef USE_PYTHON_2_2_OR_EARLIER - PyObject *doId = PyInt_FromLong(do_id); - #else PyObject *doId = PyLong_FromUnsignedLong(do_id); - #endif // pass the update to the owner view first PyObject *distobjOV = PyDict_GetItem(doId2ownerView, doId); @@ -887,7 +879,7 @@ describe_message(std::ostream &out, const string &prefix, packer.set_unpack_data((const char *)dg.get_data(), dg.get_length(), false); CHANNEL_TYPE do_id; - int msg_type; + unsigned int msg_type; bool is_update = false; string full_prefix = "CR::" + prefix; @@ -913,7 +905,12 @@ describe_message(std::ostream &out, const string &prefix, #ifdef HAVE_PYTHON if (_python_repository != nullptr) { - PyObject *msgId = PyLong_FromLong(msg_type); +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); +#endif + + PyObject *msgId = PyLong_FromUnsignedLong(msg_type); nassertv(msgId != nullptr); PyObject *methodName = PyUnicode_FromString("_getMsgName"); nassertv(methodName != nullptr); @@ -927,6 +924,10 @@ describe_message(std::ostream &out, const string &prefix, Py_DECREF(methodName); Py_DECREF(msgId); Py_DECREF(result); + +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_Release(gstate); +#endif } #endif if (msgName.length() == 0) { @@ -945,15 +946,16 @@ describe_message(std::ostream &out, const string &prefix, #ifdef HAVE_PYTHON if (_python_repository != nullptr) { +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); +#endif + PyObject *doId2do = PyObject_GetAttrString(_python_repository, "doId2do"); nassertv(doId2do != nullptr); - #ifdef USE_PYTHON_2_2_OR_EARLIER - PyObject *doId = PyInt_FromLong(do_id); - #else PyObject *doId = PyLong_FromUnsignedLong(do_id); - #endif PyObject *distobj = PyDict_GetItem(doId2do, doId); Py_DECREF(doId); Py_DECREF(doId2do); @@ -969,6 +971,10 @@ describe_message(std::ostream &out, const string &prefix, dclass = (DCClass *)PyLong_AsVoidPtr(dclass_this); Py_DECREF(dclass_this); } + +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_Release(gstate); +#endif } #endif // HAVE_PYTHON diff --git a/models/icons/minusnode.gif b/models/icons/minusnode.gif index 24b7e916f7..22587539ad 100644 Binary files a/models/icons/minusnode.gif and b/models/icons/minusnode.gif differ diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 0730500a87..00a625f29f 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -1270,7 +1270,11 @@ do_switch_fullscreen(CGDisplayModeRef mode) { // Switch back to the mode we were in when we were still windowed. CGDisplaySetDisplayMode(_display, _windowed_mode, NULL); CGDisplayModeRelease(_windowed_mode); - CGDisplayRelease(_display); + if (CGDisplayIsMain(_display)) { + CGReleaseAllDisplays(); + } else { + CGDisplayRelease(_display); + } _windowed_mode = NULL; _context_needs_update = true; @@ -1285,14 +1289,31 @@ do_switch_fullscreen(CGDisplayModeRef mode) { _fullscreen_mode = mode; _context_needs_update = true; + // Display must be captured by the application before switching mode. + // If not, the change of mode and resolution will be applied on all the other applications, + // although they are no longer visible. + // This also leads to weird bugs when switching back to the desktop mode. CGError err; - err = CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL); - + if (CGDisplayIsMain(_display)) { + // In multidisplay setup, all the displays must be captured or the switch will be notified anyway. + err = CGCaptureAllDisplays(); + } else { + err = CGDisplayCapture(_display); + } if (err != kCGErrorSuccess) { return false; } - CGDisplayCapture(_display); + err = CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL); + + if (err != kCGErrorSuccess) { + if (CGDisplayIsMain(_display)) { + CGReleaseAllDisplays(); + } else { + CGDisplayRelease(_display); + } + return false; + } NSRect frame = [[[_view window] screen] frame]; if (cocoadisplay_cat.is_debug()) { diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 0a88529cbe..795579fbc9 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -3659,7 +3659,7 @@ ensure_generated_shader(const RenderState *state) { if (!_supports_basic_shaders) { return; } - _shader_generator = new ShaderGenerator(this); + _shader_generator = new ShaderGenerator(_shader_caps, _supports_shadow_filter); } if (state->_generated_shader == nullptr || state->_generated_shader_seq != _generated_shader_seq) { diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index d19fb1f967..260e687a8a 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -73,13 +73,33 @@ pack_combine(TextureStage::CombineSource src0, TextureStage::CombineOperand op0, static PStatCollector lookup_collector("*:Munge:ShaderGen:Lookup"); static PStatCollector synthesize_collector("*:Munge:ShaderGen:Synthesize"); +/** + * Create a ShaderGenerator. This has no state, except possibly to cache + * certain results. The given parameters contain information about the + * capabilities of the target for which the shader will be compiled. + */ +ShaderGenerator:: +ShaderGenerator(const Shader::ShaderCaps &caps, bool use_shadow_filter) : + _use_shadow_filter(use_shadow_filter) { + +#ifdef _WIN32 + // Check matches all OpenGL profiles + _use_generic_attr = (caps._active_vprofile <= 6151 || caps._active_vprofile >= 7000); +#else + _use_generic_attr = true; +#endif + + // Matches gp5fp and glslf profiles + _use_pointcoord = (caps._active_fprofile == 7017 || caps._active_fprofile == 7008); +} + /** * Create a ShaderGenerator. This has no state, except possibly to cache * certain results. The parameter that must be passed is the GSG to which the * shader generator belongs. */ ShaderGenerator:: -ShaderGenerator(const GraphicsStateGuardianBase *gsg) { +ShaderGenerator(const GraphicsStateGuardianBase *gsg) : _use_pointcoord(false) { // The ATTR# input semantics seem to map to generic vertex attributes in // both arbvp1 and glslv, which behave more consistently. However, they // don't exist in Direct3D 9. Use this silly little check for now. @@ -717,6 +737,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { const char *eye_position_freg = nullptr; const char *eye_normal_freg = nullptr; const char *hpos_freg = nullptr; + const char *pointcoord_freg = nullptr; const char *position_vreg; const char *transform_weight_vreg = nullptr; @@ -762,6 +783,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { 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; + bool need_point_coord = false; // If we have binormal/tangent and eye position, we can pack eye normal in // the w channels of the others. @@ -817,6 +839,9 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { case TexGenAttrib::M_eye_position: need_eye_position = true; break; + case TexGenAttrib::M_point_sprite: + need_point_coord = true; + break; default: break; } @@ -947,6 +972,13 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t uniform float3 attr_pointparams,\n"; text << "\t out float l_point_size : PSIZE,\n"; } + if (need_point_coord && !_use_pointcoord) { + if (!need_point_size) { + text << "\t uniform float3 attr_pointparams,\n"; + } + pointcoord_freg = alloc_freg(); + text << "\t out float3 l_pointcoord : " << pointcoord_freg << ",\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"; @@ -996,6 +1028,14 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (need_point_size) { text << "\t l_point_size = attr_pointparams.y + attr_pointparams.z / length(l_eye_position.xyz);\n"; } + if (need_point_coord && !_use_pointcoord) { + if (need_point_size) { + text << "\t l_pointcoord = float3(l_position.xy / (2.0f * l_position.w) + float2(0.5f, 0.5f), 1.0f / l_point_size);\n"; + } else { + // Static point size (non-perspective points) + text << "\t l_pointcoord = float3(l_position.xy / (2.0f * l_position.w) + float2(0.5f, 0.5f), 1.0f / attr_pointparams.x);\n"; + } + } pmap::const_iterator it; for (it = texcoord_fregs.begin(); it != texcoord_fregs.end(); ++it) { @@ -1047,6 +1087,17 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t in uniform float4 attr_fog,\n"; text << "\t in uniform float4 attr_fogcolor,\n"; } + if (need_point_coord) { + if (_use_pointcoord) { + // In OpenGL, we have point coordinates available in glslf and gp5fp. + text << "\t in float2 l_pointcoord : POINTCOORD,\n"; + } else { + // In DirectX 9, we need to calculate them from the fragment coordinates. + text << "\t in float3 l_pointcoord : " << pointcoord_freg << ",\n"; + text << "\t in float2 l_fragcoord : WPOS,\n"; + text << "\t in uniform float2 sys_windowsize,\n"; + } + } if (need_world_position) { text << "\t in float4 l_world_position : " << world_position_freg << ",\n"; } @@ -1207,6 +1258,16 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { case TexGenAttrib::M_eye_position: text << "\t float4 texcoord" << i << " = float4(l_eye_position.xyz, 1.0f);\n"; break; + case TexGenAttrib::M_point_sprite: + if (_use_pointcoord) { + text << "\t float4 texcoord" << i << " = float4(l_pointcoord, 0.0f, 1.0f);\n"; + } else { + if (!_use_generic_attr) { + text << "\t l_fragcoord.y = sys_windowsize.y - l_fragcoord.y;\n"; + } + text << "\t float4 texcoord" << i << " = float4((l_fragcoord - l_pointcoord.xy * sys_windowsize) * l_pointcoord.z * float2(1.0f, -1.0f) - float2(0.5f, 0.5f), 0.0f, 1.0f);\n"; + } + break; case TexGenAttrib::M_constant: text << "\t float4 texcoord" << i << " = texconst_" << i << ";\n"; break; diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index a41445d7ca..f23fe3b315 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -64,6 +64,9 @@ class GeomVertexAnimationSpec; * */ class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount { +public: + ShaderGenerator(const Shader::ShaderCaps &caps, bool use_shadow_filter); + PUBLISHED: ShaderGenerator(const GraphicsStateGuardianBase *gsg); virtual ~ShaderGenerator(); @@ -76,7 +79,8 @@ PUBLISHED: protected: // Shader register allocation: - bool _use_generic_attr; + bool _use_generic_attr : 1; + bool _use_pointcoord : 1; int _vcregs_used; int _fcregs_used; int _vtregs_used; diff --git a/panda/src/vision/arToolKit.cxx b/panda/src/vision/arToolKit.cxx index ed7d019680..cf328a2afd 100644 --- a/panda/src/vision/arToolKit.cxx +++ b/panda/src/vision/arToolKit.cxx @@ -475,7 +475,7 @@ analyze(Texture *tex, bool do_flip_texture) { } } - delete data; + delete[] data; } #endif // HAVE_ARTOOLKIT