diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 4ea10a76f4..d0b4d4c9f1 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -1170,7 +1170,7 @@ find_display_modes(int width, int height) { // Get the current refresh rate and pixel encoding. CFStringRef current_pixel_encoding; - int refresh_rate; + double refresh_rate; mode = CGDisplayCopyDisplayMode(_display); // First check if the current mode is adequate. @@ -1204,7 +1204,7 @@ find_display_modes(int width, int height) { // the mode width and height but also actual pixel widh and height. if (CGDisplayModeGetWidth(mode) == width && CGDisplayModeGetHeight(mode) == height && - CGDisplayModeGetRefreshRate(mode) == refresh_rate && + (int)(CGDisplayModeGetRefreshRate(mode) + 0.5) == (int)(refresh_rate + 0.5) && #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_14 || (CGDisplayModeGetPixelWidth(mode) == expected_pixel_width && @@ -1212,7 +1212,12 @@ find_display_modes(int width, int height) { #endif CFStringCompare(pixel_encoding, current_pixel_encoding, 0) == kCFCompareEqualTo) { - CFArrayAppendValue(valid_modes, mode); + if (CGDisplayModeGetRefreshRate(mode) == refresh_rate) { + // Exact match for refresh rate, prioritize this. + CFArrayInsertValueAtIndex(valid_modes, 0, mode); + } else { + CFArrayAppendValue(valid_modes, mode); + } } CFRelease(pixel_encoding); } diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 0e848d9c1a..9afeab89e5 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -13074,22 +13074,22 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { image = tex->get_uncompressed_ram_image(); } + Texture::TextureType texture_type = tex->get_texture_type(); Texture::CompressionMode image_compression; if (image.is_null()) { image_compression = Texture::CM_off; } else { image_compression = tex->get_ram_image_compression(); - } - bool is_buffer_texture = tex->get_texture_type() == Texture::TT_buffer_texture; - if (is_buffer_texture || - !get_supports_compressed_texture_format(image_compression)) { - image = tex->get_uncompressed_ram_image(); - image_compression = Texture::CM_off; + if (texture_type == Texture::TT_buffer_texture || + !get_supports_compressed_texture_format(image_compression)) { + image = tex->get_uncompressed_ram_image(); + image_compression = Texture::CM_off; - // If this triggers, Panda cannot decompress the texture. Compile with - // libsquish support or precompress the texture. - nassertr(!image.is_null(), false); + // If this triggers, Panda cannot decompress the texture. Compile with + // libsquish support or precompress the texture. + nassertr(!image.is_null(), false); + } } int mipmap_bias = 0; @@ -13101,7 +13101,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { // If we'll use immutable texture storage, we have to pick a sized image // format. bool force_sized = (gl_immutable_texture_storage && _supports_tex_storage) || - (is_buffer_texture); + (texture_type == Texture::TT_buffer_texture); GLint internal_format = get_internal_image_format(tex, force_sized); GLint external_format = get_external_image_format(tex); @@ -13130,7 +13130,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { int max_dimension_y; int max_dimension_z; - switch (tex->get_texture_type()) { + switch (texture_type) { case Texture::TT_3d_texture: max_dimension_x = _max_3d_texture_dimension; max_dimension_y = _max_3d_texture_dimension; @@ -13235,7 +13235,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - GLenum target = get_texture_target(tex->get_texture_type()); + GLenum target = get_texture_target(texture_type); uses_mipmaps = (uses_mipmaps && !gl_ignore_mipmaps) || gl_force_mipmaps; #ifndef OPENGLES if (target == GL_TEXTURE_BUFFER) { @@ -13411,7 +13411,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { << ", uses_mipmaps = " << uses_mipmaps << "\n"; } - switch (tex->get_texture_type()) { + switch (texture_type) { case Texture::TT_buffer_texture: // Won't get here, but squelch compiler warning case Texture::TT_1d_texture: @@ -13459,7 +13459,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { } bool success = true; - if (tex->get_texture_type() == Texture::TT_cube_map) { + if (texture_type == Texture::TT_cube_map) { // A cube map must load six different 2-d images (which are stored as the // six pages of the system ram image). if (!_supports_cube_map) { diff --git a/tests/linmath/test_lvector2.py b/tests/linmath/test_lvector2.py index a51631fd8d..1f61887bc1 100644 --- a/tests/linmath/test_lvector2.py +++ b/tests/linmath/test_lvector2.py @@ -5,30 +5,6 @@ from panda3d import core import pytest -def test_round(): - original_vector = Vec2(2.3, -2.6) - - rounded_vector = round(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - - -def test_floor(): - original_vector = Vec2(2.3, -2.6) - - rounded_vector = floor(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - - -def test_ceil(): - original_vector = Vec2(2.3, -2.6) - - rounded_vector = ceil(original_vector) - assert rounded_vector.x == 3 - assert rounded_vector.y == -2 - - def test_vec2_creation(): assert Vec2(x=1, y=2) == Vec2(1, 2) == Vec2((1, 2)) @@ -120,8 +96,32 @@ def test_vec2_nan(): assert not Vec2D(-inf, 0).is_nan() +def test_vec2_round(): + original_vector = Vec2(2.3, -2.6) + + rounded_vector = round(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + + +def test_vec2_floor(): + original_vector = Vec2(2.3, -2.6) + + rounded_vector = floor(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + + +def test_vec2_ceil(): + original_vector = Vec2(2.3, -2.6) + + rounded_vector = ceil(original_vector) + assert rounded_vector.x == 3 + assert rounded_vector.y == -2 + + @pytest.mark.parametrize("type", (core.LVecBase2f, core.LVecBase2d, core.LVecBase2i)) -def test_vec4_floordiv(type): +def test_vec2_floordiv(type): with pytest.raises(ZeroDivisionError): type(1, 2) // 0 diff --git a/tests/linmath/test_lvector3.py b/tests/linmath/test_lvector3.py index 22636cc2d6..4ef45a246f 100644 --- a/tests/linmath/test_lvector3.py +++ b/tests/linmath/test_lvector3.py @@ -5,33 +5,6 @@ from panda3d import core import pytest -def test_round(): - original_vector = Vec3(2.3, -2.6, 3.5) - - rounded_vector = round(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - assert rounded_vector.z == 4 - - -def test_floor(): - original_vector = Vec3(2.3, -2.6, 3.5) - - rounded_vector = floor(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - assert rounded_vector.z == 3 - - -def test_ceil(): - original_vector = Vec3(2.3, -2.6, 3.5) - - rounded_vector = ceil(original_vector) - assert rounded_vector.x == 3 - assert rounded_vector.y == -2 - assert rounded_vector.z == 4 - - def test_vec3_creation(): assert Vec3(x=1, y=2, z=1) == Vec3(1, 2, 1) == Vec3((1, 2, 1)) @@ -105,6 +78,33 @@ def test_vec3_compare(): assert Vec3(0, 0, 1).compare_to(Vec3(0, 0, 1)) == 0 +def test_vec3_round(): + original_vector = Vec3(2.3, -2.6, 3.5) + + rounded_vector = round(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + assert rounded_vector.z == 4 + + +def test_vec3_floor(): + original_vector = Vec3(2.3, -2.6, 3.5) + + rounded_vector = floor(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + assert rounded_vector.z == 3 + + +def test_vec3_ceil(): + original_vector = Vec3(2.3, -2.6, 3.5) + + rounded_vector = ceil(original_vector) + assert rounded_vector.x == 3 + assert rounded_vector.y == -2 + assert rounded_vector.z == 4 + + @pytest.mark.parametrize("type", (core.LVecBase3f, core.LVecBase3d, core.LVecBase3i)) def test_vec3_floordiv(type): with pytest.raises(ZeroDivisionError): diff --git a/tests/linmath/test_lvector4.py b/tests/linmath/test_lvector4.py index 03355eb2c6..f51bd3f718 100644 --- a/tests/linmath/test_lvector4.py +++ b/tests/linmath/test_lvector4.py @@ -5,36 +5,6 @@ from panda3d import core import pytest -def test_round(): - original_vector = Vec4(2.3, -2.6, 3.5, 1) - - rounded_vector = round(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - assert rounded_vector.z == 4 - assert rounded_vector.w == 1 - - -def test_floor(): - original_vector = Vec4(2.3, -2.6, 3.5, 1) - - rounded_vector = floor(original_vector) - assert rounded_vector.x == 2 - assert rounded_vector.y == -3 - assert rounded_vector.z == 3 - assert rounded_vector.w == 1 - - -def test_ceil(): - original_vector = Vec4(2.3, -2.6, 3.5, 1) - - rounded_vector = ceil(original_vector) - assert rounded_vector.x == 3 - assert rounded_vector.y == -2 - assert rounded_vector.z == 4 - assert rounded_vector.w == 1 - - def test_vec4_creation(): assert Vec4(x=1, y=2, z=1, w=7) == Vec4(1, 2, 1, 7) == Vec4((1, 2, 1, 7)) @@ -121,6 +91,36 @@ def test_vec4_compare(): assert Vec4(0, 0, 0, 1).compare_to(Vec4(0, 0, 0, 1)) == 0 +def test_vec4_round(): + original_vector = Vec4(2.3, -2.6, 3.5, 1) + + rounded_vector = round(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + assert rounded_vector.z == 4 + assert rounded_vector.w == 1 + + +def test_vec4_floor(): + original_vector = Vec4(2.3, -2.6, 3.5, 1) + + rounded_vector = floor(original_vector) + assert rounded_vector.x == 2 + assert rounded_vector.y == -3 + assert rounded_vector.z == 3 + assert rounded_vector.w == 1 + + +def test_vec4_ceil(): + original_vector = Vec4(2.3, -2.6, 3.5, 1) + + rounded_vector = ceil(original_vector) + assert rounded_vector.x == 3 + assert rounded_vector.y == -2 + assert rounded_vector.z == 4 + assert rounded_vector.w == 1 + + @pytest.mark.parametrize("type", (core.LVecBase4f, core.LVecBase4d, core.LVecBase4i)) def test_vec4_floordiv(type): with pytest.raises(ZeroDivisionError):