Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter checks for FlxG.bitmap.maxTextureSize #3279

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions flixel/graphics/FlxGraphic.hx
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ class FlxGraphic implements IFlxDestroyable
bitmap = value;
width = bitmap.width;
height = bitmap.height;

#if FLX_OPENGL_AVAILABLE
var max:Int = FlxG.bitmap.maxTextureSize;
if (max != -1)
{
if (width > max || height > max)
FlxG.log.warn('Graphic dimensions (${width}x${height}) exceed the maximum allowed size (${max}x${max}), which may cause rendering issues.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of rendering issues will happen? I'm debating whether this should be an error or not

Copy link
Contributor Author

@ACrazyTown ACrazyTown Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding OpenGL won't upload the texture to the GPU at all and any attempts to render the texture will be replaced with a fallback texture (usually just black or whatever), probably should be an error yeah

}
#end
}

return value;
Expand Down
17 changes: 12 additions & 5 deletions flixel/system/frontEnds/BitmapFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import flixel.math.FlxRect;
import flixel.system.FlxAssets.FlxGraphicAsset;
import flixel.util.FlxColor;
import openfl.Assets;
#if !flash
#if FLX_OPENGL_AVAILABLE
import lime.graphics.opengl.GL;
#end

Expand All @@ -19,9 +19,13 @@ import lime.graphics.opengl.GL;
*/
class BitmapFrontEnd
{
#if !flash
#if FLX_OPENGL_AVAILABLE
/**
* Gets max texture size for native targets
* Returns the maximum allowed width and height (in pixels) for a texture.
* This value is only available on hardware-accelerated targets that use OpenGL.
* On unsupported targets, the returned value will always be -1.
*
* @see https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_TEXTURE_SIZE
*/
public var maxTextureSize(get, never):Int;
#end
Expand Down Expand Up @@ -391,10 +395,13 @@ class BitmapFrontEnd
}
}

#if !flash
#if FLX_OPENGL_AVAILABLE
function get_maxTextureSize():Int
{
return cast GL.getParameter(GL.MAX_TEXTURE_SIZE);
if (FlxG.stage.window.context.attributes.hardware)
return cast GL.getParameter(GL.MAX_TEXTURE_SIZE);

return -1;
}
#end

Expand Down
7 changes: 7 additions & 0 deletions flixel/system/macros/FlxDefines.hx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private enum HelperDefines
FLX_HEALTH;
FLX_NO_TRACK_POOLS;
FLX_NO_TRACK_GRAPHICS;
FLX_OPENGL_AVAILABLE;
}

class FlxDefines
Expand Down Expand Up @@ -251,6 +252,12 @@ class FlxDefines

if (defined(FLX_DEBUG))
define(FLX_TRACK_GRAPHICS);

#if (lime_opengl || lime_opengles || lime_webgl)
// FlxG.stage.window.context.attributes.hardware is not always defined during unit tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to check if FlxG.stage.window.context.attributes.hardware (or whatever part of it that fails) is defined rather than outright skipping it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If it's not defined in any other context I want it to fail loudly, and I don't think we can really unit test gl stuff right now

if (defined(FLX_NO_UNIT_TEST))
define(FLX_OPENGL_AVAILABLE);
#end

defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS);
}
Expand Down
Loading