From 37aca4cadf6e18d27f97ed96ddcf2cef89075504 Mon Sep 17 00:00:00 2001 From: Lily Date: Fri, 22 Nov 2024 17:34:19 +0300 Subject: [PATCH] matching with upstream --- project.xml | 7 +- .../backend/assets/AssetsLibraryList.hx | 72 +- source/funkin/backend/system/Main.hx | 7 +- source/funkin/backend/system/MainState.hx | 2 + .../backend/system/framerate/Framerate.hx | 10 +- source/funkin/menus/FreeplayState.hx | 15 +- source/funkin/menus/PauseSubState.hx | 2 +- source/funkin/menus/TitleState.hx | 7 +- source/funkin/options/Options.hx | 4 +- source/funkin/options/OptionsScreen.hx | 6 +- .../funkin/options/categories/MiscOptions.hx | 2 - source/openfl/display/Shader.hx | 985 ------------------ source/openfl/utils/Assets.hx | 1 - 13 files changed, 43 insertions(+), 1077 deletions(-) delete mode 100644 source/openfl/display/Shader.hx diff --git a/project.xml b/project.xml index 2bde23221..5bdf6eb21 100644 --- a/project.xml +++ b/project.xml @@ -92,7 +92,7 @@ - + @@ -184,8 +184,6 @@ - -
@@ -195,9 +193,6 @@ - - - diff --git a/source/funkin/backend/assets/AssetsLibraryList.hx b/source/funkin/backend/assets/AssetsLibraryList.hx index 0b578d842..7b5ef0696 100644 --- a/source/funkin/backend/assets/AssetsLibraryList.hx +++ b/source/funkin/backend/assets/AssetsLibraryList.hx @@ -1,11 +1,7 @@ package funkin.backend.assets; -import sys.FileSystem; import funkin.backend.assets.IModsAssetLibrary; import lime.utils.AssetLibrary; -import lime.utils.AssetType; - -using StringTools; class AssetsLibraryList extends AssetLibrary { public var libraries:Array = []; @@ -62,30 +58,14 @@ class AssetsLibraryList extends AssetLibrary { l = cast(l, openfl.utils.AssetLibrary).__proxy; } + // TODO: do base folder scanning #if MOD_SUPPORT - if (source == MODS || source == BOTH) { - if (l is IModsAssetLibrary) { - var lib = cast(l, IModsAssetLibrary); - for (e in lib.getFiles(folder)) - content.push(e); - } - } - #else - #if sys - if (source == SOURCE || source == BOTH) { - var fileStuffs = FileSystem.readDirectory(folder); - if (fileStuffs != null && fileStuffs.length > 0) { - for (e in fileStuffs) { - if (!FileSystem.isDirectory(folder + e.toString())) { - content.push(e); - } - } - } else { - Logs.trace('No files/folders found in the requested directory \'${folder}\'', WARNING, YELLOW); - } + if (l is IModsAssetLibrary) { + var lib = cast(l, IModsAssetLibrary); + for(e in lib.getFiles(folder)) + content.push(e); } #end - #end } return content; } @@ -102,30 +82,14 @@ class AssetsLibraryList extends AssetLibrary { l = cast(l, openfl.utils.AssetLibrary).__proxy; } + // TODO: do base folder scanning #if MOD_SUPPORT - if (source == MODS || source == BOTH) { - if (l is IModsAssetLibrary) { - var lib = cast(l, IModsAssetLibrary); - for (e in lib.getFolders(folder)) - content.push(e); - } - } - #else - #if sys - if (source == SOURCE || source == BOTH) { - var fileStuffs = FileSystem.readDirectory(folder); - if (fileStuffs != null && fileStuffs.length > 0) { - for (e in fileStuffs) { - if (FileSystem.isDirectory(folder + e.toString())) { - content.push(e); - } - } - } else { - Logs.trace('No files/folders found in the requested directory \'${folder}\'', WARNING, YELLOW); - } + if (l is IModsAssetLibrary) { + var lib = cast(l, IModsAssetLibrary); + for(e in lib.getFolders(folder)) + content.push(e); } #end - #end } return content; } @@ -198,24 +162,10 @@ class AssetsLibraryList extends AssetLibrary { libraries.insert(0, lib); return lib; } - - override public function list(type:String):Array { - var items = []; - - for(library in libraries) { - var libraryItems = library.list(type); - - if (libraryItems != null) { - items = items.concat(libraryItems); - } - } - - return items; - } } enum abstract AssetSource(Null) from Bool from Null to Null { var SOURCE = true; var MODS = false; var BOTH = null; -} \ No newline at end of file +} diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index fb3027849..78fd89f28 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -71,15 +71,17 @@ class Main extends Sprite CrashHandler.init(); - #if !html5 framerateSprite = new funkin.backend.system.framerate.Framerate(); #end + #if !web framerateSprite = new funkin.backend.system.framerate.Framerate(); #end addChild(game = new FunkinGame(gameWidth, gameHeight, MainState, Options.framerate, Options.framerate, skipSplash, startFullscreen)); #if android FlxG.android.preventDefaultKeys = [BACK]; #end - #if !html5 + #if !web addChild(framerateSprite); + #if mobile FlxG.stage.window.onResize.add((w:Int, h:Int) -> framerateSprite.setScale()); + #end SystemInfo.init(); #end } @@ -163,7 +165,6 @@ class Main extends Sprite Conductor.init(); AudioSwitchFix.init(); EventManager.init(); - FlxG.signals.preStateSwitch.add(onStateSwitch); FlxG.signals.postStateSwitch.add(onStateSwitchPost); diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index f5f078f6d..1acc6b5f9 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -20,7 +20,9 @@ class MainState extends FlxState { public static var betaWarningShown:Bool = false; public override function create() { super.create(); + #if mobile funkin.backend.system.Main.framerateSprite.setScale(); + #end if (!initiated) { Main.loadGameSettings(); diff --git a/source/funkin/backend/system/framerate/Framerate.hx b/source/funkin/backend/system/framerate/Framerate.hx index d4faeccca..a1c6c0fd3 100644 --- a/source/funkin/backend/system/framerate/Framerate.hx +++ b/source/funkin/backend/system/framerate/Framerate.hx @@ -121,7 +121,11 @@ class Framerate extends Sprite { #elseif ios for(camera in FlxG.cameras.list) { var pos = FlxG.mouse.getScreenPosition(camera); - if(pos.x >= 0 && pos.x <= 80 && pos.y >= 0 && pos.y <= 60) { + if (pos.x >= FlxG.game.x + 10 + offset.x && + pos.x <= FlxG.game.x + offset.x + 80 && + pos.y >= FlxG.game.y + 2 + offset.y && + pos.y <= FlxG.game.y + 2 + offset.y + 60) + { if(FlxG.mouse.justPressed) sillyTimer.start(0.4, (tmr:FlxTimer) -> debugMode = (debugMode + 1) % 3); @@ -163,9 +167,11 @@ class Framerate extends Sprite { } } + #if mobile public inline function setScale(?scale:Float){ if(scale == null) scale = Math.min(FlxG.stage.window.width / FlxG.width, FlxG.stage.window.height / FlxG.height); scaleX = scaleY = #if android (scale > 1 ? scale : 1) #else (scale < 1 ? scale : 1) #end; } -} \ No newline at end of file + #end +} diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 977bbf41b..118d1ac28 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -291,8 +291,7 @@ class FreeplayState extends MusicBeatState public function select() { updateCoopModes(); - if (songs[curSelected].difficulties.length <= 0) - return; + if (songs[curSelected].difficulties.length <= 0) return; var event = event("onSelect", EventManager.get(FreeplaySongSelectEvent).recycle(songs[curSelected].name, songs[curSelected].difficulties[curDifficulty], __opponentMode, __coopMode)); @@ -352,12 +351,12 @@ class FreeplayState extends MusicBeatState /** * Array containing all labels for Co-Op / Opponent modes. */ - public var coopLabels:Array = controls.touchC ? ['[X] Solo', '[X] Opponent Mode'] : + public var coopLabels:Array = controls.touchC ? ["[X] Solo", "[X] Opponent Mode"] : [ - '[TAB] Solo', - '[TAB] Opponent Mode', - '[TAB] Co-Op Mode', - '[TAB] Co-Op Mode (Switched)' + "[TAB] Solo", + "[TAB] Opponent Mode", + "[TAB] Co-Op Mode", + "[TAB] Co-Op Mode (Switched)" ]; /** @@ -468,4 +467,4 @@ class FreeplaySonglist { return songList; } -} \ No newline at end of file +} diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index 45a18a634..e1f885eac 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -157,7 +157,7 @@ class PauseSubState extends MusicBeatSubstate game.registerSmoothTransition(); FlxG.resetState(); case "Change Controls": - persistentUpdate = false; + persistentDraw = false; removeVirtualPad(); openSubState(new KeybindsOptions()); case "Change Options": diff --git a/source/funkin/menus/TitleState.hx b/source/funkin/menus/TitleState.hx index 52edf5506..4a5c2cbe9 100644 --- a/source/funkin/menus/TitleState.hx +++ b/source/funkin/menus/TitleState.hx @@ -119,13 +119,12 @@ class TitleState extends MusicBeatState { if (FlxG.keys.justPressed.F) FlxG.fullscreen = !FlxG.fullscreen; - var pressedEnter:Bool = controls.ACCEPT; + var pressedEnter:Bool = FlxG.keys.justPressed.ENTER; - if (controls.touchC) { + if (controls.touchC) for (touch in FlxG.touches.list) if (touch.justPressed) pressedEnter = true; - } var gamepad:FlxGamepad = FlxG.gamepads.lastActive; @@ -383,4 +382,4 @@ typedef TitleStateImage = { @:optional var scale:Null; @:optional var flipX:Null; @:optional var flipY:Null; -} \ No newline at end of file +} diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index d4a7934a1..7d0d0140f 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -38,7 +38,9 @@ class Options public static var lastLoadedMod:String = null; - // mobile options + /** + * MOBILE SETTINGS + */ #if mobile public static var screenTimeOut:Bool = false; #end diff --git a/source/funkin/options/OptionsScreen.hx b/source/funkin/options/OptionsScreen.hx index fb45061c6..77d3e1063 100644 --- a/source/funkin/options/OptionsScreen.hx +++ b/source/funkin/options/OptionsScreen.hx @@ -39,8 +39,8 @@ class OptionsScreen extends FlxTypedSpriteGroup { super.update(elapsed); var controls = PlayerSettings.solo.controls; - var wheel = FlxG.mouse.wheel; - changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0) - wheel); + + changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0) - FlxG.mouse.wheel); x = id * FlxG.width; for(k=>option in members) { if(option == null) continue; @@ -93,4 +93,4 @@ class OptionsScreen extends FlxTypedSpriteGroup { } public dynamic function onClose(o:OptionsScreen) {} -} \ No newline at end of file +} diff --git a/source/funkin/options/categories/MiscOptions.hx b/source/funkin/options/categories/MiscOptions.hx index 5da7dd85f..1287587d9 100644 --- a/source/funkin/options/categories/MiscOptions.hx +++ b/source/funkin/options/categories/MiscOptions.hx @@ -3,8 +3,6 @@ package funkin.options.categories; class MiscOptions extends OptionsScreen { public override function new() { - dpadMode = 'NONE'; - actionMode = 'A_B'; super("Miscellaneous", "Use this menu to reset save data or engine settings.", null, #if UPDATE_CHECKING 'UP_DOWN' #else 'NONE' #end, 'A_B'); #if UPDATE_CHECKING add(new Checkbox( diff --git a/source/openfl/display/Shader.hx b/source/openfl/display/Shader.hx deleted file mode 100644 index 2d779b759..000000000 --- a/source/openfl/display/Shader.hx +++ /dev/null @@ -1,985 +0,0 @@ -package openfl.display; - -#if !flash -import openfl.display3D._internal.GLProgram; -import openfl.display3D._internal.GLShader; -import openfl.display._internal.ShaderBuffer; -import openfl.utils._internal.Float32Array; -import openfl.utils._internal.Log; -import openfl.display3D.Context3D; -import openfl.display3D.Program3D; -import openfl.utils.ByteArray; - -/** - // TODO: Document GLSL Shaders - A Shader instance represents a Pixel Bender shader kernel in ActionScript. - To use a shader in your application, you create a Shader instance for it. - You then use that Shader instance in the appropriate way according to the - effect you want to create. For example, to use the shader as a filter, you - assign the Shader instance to the `shader` property of a ShaderFilter - object. - A shader defines a function that executes on all the pixels in an image, - one pixel at a time. The result of each call to the function is the output - color at that pixel coordinate in the image. A shader can specify one or - more input images, which are images whose content can be used in - determining the output of the function. A shader can also specify one or - more parameters, which are input values that can be used in calculating - the function output. In a single shader execution, the input and parameter - values are constant. The only thing that varies is the coordinate of the - pixel whose color is the function result. Shader function calls for - multiple output pixel coordinates execute in parallel to improve shader - execution performance. - - The shader bytecode can be loaded at run time using a URLLoader instance. - The following example demonstrates loading a shader bytecode file at run - time and linking it to a Shader instance. - - ```as3 - var loader:URLLoader = new URLLoader(); - loader.dataFormat = URLLoaderDataFormat.BINARY; - loader.addEventListener(Event.COMPLETE, onLoadComplete); - loader.load(new URLRequest("myShader.pbj")); - var shader:Shader; - - function onLoadComplete(event:Event):void { - // Create a new shader and set the loaded data as its bytecode - shader = new Shader(); - shader.byteCode = loader.data; - - // You can also pass the bytecode to the Shader() constructor like this: - // shader = new Shader(loader.data); - - // do something with the shader - } - ``` - - You can also embed the shader into the SWF at compile time using the - `[Embed]` metadata tag. The `[Embed]` metadata tag is only available if - you use the Flex SDK to compile the SWF. The `[Embed]` tag's `source` - parameter points to the shader file, and its `mimeType` parameter is - `"application/octet-stream"`, as in this example: - - ```as3 - [Embed(source="myShader.pbj", mimeType="application/octet-stream)] var MyShaderClass:Class; - - // ... - - // create a new shader and set the embedded shader as its bytecode var - shaderShader = new Shader(); - shader.byteCode = new MyShaderClass(); - - // You can also pass the bytecode to the Shader() constructor like this: - // var shader:Shader = new Shader(new MyShaderClass()); - - // do something with the shader - ``` - - In either case, you link the raw shader (the `URLLoader.data` property or - an instance of the `[Embed]` data class) to the Shader instance. As the - previous examples demonstrate, you can do this in two ways. You can pass - the shader bytecode as an argument to the `Shader()` constructor. - Alternatively, you can set it as the Shader instance's `byteCode` - property. - - Once a Shader instance is created, it can be used in one of several ways: - - * A shader fill: The output of the shader is used as a fill for content - drawn with the drawing API. Pass the Shader instance as an argument to the - `Graphics.beginShaderFill()` method. - * A shader filter: The output of the shader is used as a graphic filter - applied to a display object. Assign the Shader instance to the `shader` - property of a ShaderFilter instance. - * A blend mode: The output of the shader is rendered as the blending - between two overlapping display objects. Assign the Shader instance to the - `blendShader` property of the upper of the two display objects. - * Background shader processing: The shader executes in the background, - avoiding the possibility of freezing the display, and dispatches an event - when processing is complete. Assign the Shader instance to the `shader` - property of a ShaderJob instance. - - Shader fills, filters, and blends are not supported under GPU rendering. - - **Mobile Browser Support:** This feature is not supported in mobile - browsers. - - _Adobe AIR profile support:_ This feature is supported on all desktop operating - systems, but it is not supported on all mobile devices. It is not - supported on AIR for TV devices. See - [AIR Profile Support](https://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html) - for more information regarding API support across multiple profiles. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display3D.Context3D) -@:access(openfl.display3D.Program3D) -@:access(openfl.display.ShaderInput) -@:access(openfl.display.ShaderParameter) -// #if (!display && !macro) -#if !macro -@:autoBuild(openfl.utils._internal.ShaderMacro.build()) -#end -class Shader -{ - /** - The raw shader bytecode for this Shader instance. - **/ - public var byteCode(null, default):ByteArray; - - /** - Provides access to parameters, input images, and metadata for the - Shader instance. ShaderParameter objects representing parameters for - the shader, ShaderInput objects representing the input images for the - shader, and other values representing the shader's metadata are - dynamically added as properties of the `data` property object when the - Shader instance is created. Those properties can be used to introspect - the shader and to set parameter and input values. - For information about accessing and manipulating the dynamic - properties of the `data` object, see the ShaderData class description. - **/ - public var data(get, set):ShaderData; - - /** - Get or set the fragment source used when compiling with GLSL. - - This property is not available on the Flash target. - **/ - public var glFragmentSource(get, set):String; - - /** - The compiled GLProgram if available. - - This property is not available on the Flash target. - **/ - @SuppressWarnings("checkstyle:Dynamic") public var glProgram(default, null):GLProgram; - - /** - Get or set the vertex source used when compiling with GLSL. - - This property is not available on the Flash target. - **/ - public var glVertexSource(get, set):String; - - /** - The precision of math operations performed by the shader. - The set of possible values for the `precisionHint` property is defined - by the constants in the ShaderPrecision class. - - The default value is `ShaderPrecision.FULL`. Setting the precision to - `ShaderPrecision.FAST` can speed up math operations at the expense of - precision. - - Full precision mode (`ShaderPrecision.FULL`) computes all math - operations to the full width of the IEEE 32-bit floating standard and - provides consistent behavior on all platforms. In this mode, some math - operations such as trigonometric and exponential functions can be - slow. - - Fast precision mode (`ShaderPrecision.FAST`) is designed for maximum - performance but does not work consistently on different platforms and - individual CPU configurations. In many cases, this level of precision - is sufficient to create graphic effects without visible artifacts. - - The precision mode selection affects the following shader operations. - These operations are faster on an Intel processor with the SSE - instruction set: - - * `sin(x)` - * `cos(x)` - * `tan(x)` - * `asin(x)` - * `acos(x)` - * `atan(x)` - * `atan(x, y)` - * `exp(x)` - * `exp2(x)` - * `log(x)` - * `log2(x)` - * `pow(x, y)` - * `reciprocal(x)` - * `sqrt(x)` - **/ - public var precisionHint:ShaderPrecision; - - /** - The compiled Program3D if available. - - This property is not available on the Flash target. - **/ - public var program:Program3D; - - @:noCompletion private var __alpha:ShaderParameter; - @:noCompletion private var __bitmap:ShaderInput; - @:noCompletion private var __colorMultiplier:ShaderParameter; - @:noCompletion private var __colorOffset:ShaderParameter; - @:noCompletion private var __context:Context3D; - @:noCompletion private var __data:ShaderData; - @:noCompletion private var __glFragmentSource:String; - @:noCompletion private var __glSourceDirty:Bool; - @:noCompletion private var __glVertexSource:String; - @:noCompletion private var __hasColorTransform:ShaderParameter; - @:noCompletion private var __inputBitmapData:Array>; - @:noCompletion private var __isGenerated:Bool; - @:noCompletion private var __matrix:ShaderParameter; - @:noCompletion private var __numPasses:Int; - @:noCompletion private var __paramBool:Array>; - @:noCompletion private var __paramFloat:Array>; - @:noCompletion private var __paramInt:Array>; - @:noCompletion private var __position:ShaderParameter; - @:noCompletion private var __textureCoord:ShaderParameter; - @:noCompletion private var __texture:ShaderInput; - @:noCompletion private var __textureSize:ShaderParameter; - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(Shader.prototype, { - "data": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_data (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_data (v); }") - }, - "glFragmentSource": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_glFragmentSource (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_glFragmentSource (v); }") - }, - "glVertexSource": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_glVertexSource (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_glVertexSource (v); }") - }, - }); - } - #end - - /** - Creates a new Shader instance. - - @param code The raw shader bytecode to link to the Shader. - **/ - public function new(code:ByteArray = null) - { - byteCode = code; - precisionHint = FULL; - - __glSourceDirty = true; - __numPasses = 1; - __data = new ShaderData(code); - } - - @:noCompletion private function __clearUseArray():Void - { - for (parameter in __paramBool) - { - parameter.__useArray = false; - } - - for (parameter in __paramFloat) - { - parameter.__useArray = false; - } - - for (parameter in __paramInt) - { - parameter.__useArray = false; - } - } - - // private function __clone ():Shader { - // var classType = Type.getClass (this); - // var shader = Type.createInstance (classType, []); - // for (input in __inputBitmapData) { - // if (input.input != null) { - // var field = Reflect.field (shader.data, input.name); - // field.channels = input.channels; - // field.height = input.height; - // field.input = input.input; - // field.smoothing = input.smoothing; - // field.width = input.width; - // } - // } - // for (param in __paramBool) { - // if (param.value != null) { - // Reflect.field (shader.data, param.name).value = param.value.copy (); - // } - // } - // for (param in __paramFloat) { - // if (param.value != null) { - // Reflect.field (shader.data, param.name).value = param.value.copy (); - // } - // } - // for (param in __paramInt) { - // if (param.value != null) { - // Reflect.field (shader.data, param.name).value = param.value.copy (); - // } - // } - // return shader; - // } - @:noCompletion private function __createGLShader(source:String, type:Int):GLShader - { - var gl = __context.gl; - - var shader = gl.createShader(type); - gl.shaderSource(shader, source); - gl.compileShader(shader); - var shaderInfoLog = gl.getShaderInfoLog(shader); - var hasInfoLog = shaderInfoLog != null && StringTools.trim(shaderInfoLog) != ""; - var compileStatus = gl.getShaderParameter(shader, gl.COMPILE_STATUS); - - if (hasInfoLog || compileStatus == 0) - { - final startMessage = '${(compileStatus == 0) ? "Error" : "Info" } ${(type == gl.VERTEX_SHADER) ? "compiling vertex shader" : "compiling fragment shader"}'; - var message = startMessage; - message += "\n" + shaderInfoLog; - message += "\n" + source; - #if sys - if (compileStatus == 0) - { - try - { - if (!sys.FileSystem.exists('logs')) - sys.FileSystem.createDirectory('logs'); - - sys.io.File.saveContent('logs/' + 'ShaderCompileError.txt', '$message'); - } - catch (e:haxe.Exception) - Log.warn('Couldn\'t save error message. (${e.message})', null); - } - #end - if (compileStatus == 0) - #if (android && !macro) - android.Tools.showAlertDialog("Shader Compile Error!", message, {name: "OK", func: null}, null) - #elseif ios - openfl.Lib.application.window.alert('$message', 'Shader Compile Error!') - #else - Log.error(message) - #end; - else if (hasInfoLog) - Log.debug(message); - } - - return shader; - } - - @:noCompletion private function __createGLProgram(vertexSource:String, fragmentSource:String):GLProgram - { - var gl = __context.gl; - - var vertexShader = __createGLShader(vertexSource, gl.VERTEX_SHADER); - var fragmentShader = __createGLShader(fragmentSource, gl.FRAGMENT_SHADER); - - var program = gl.createProgram(); - - // Fix support for drivers that don't draw if attribute 0 is disabled - for (param in __paramFloat) - { - if (param.name.indexOf("Position") > -1 && StringTools.startsWith(param.name, "openfl_")) - { - gl.bindAttribLocation(program, 0, param.name); - break; - } - } - - gl.attachShader(program, vertexShader); - gl.attachShader(program, fragmentShader); - gl.linkProgram(program); - - if (gl.getProgramParameter(program, gl.LINK_STATUS) == 0) - { - var message = "Unable to initialize the shader program"; - message += "\n" + gl.getProgramInfoLog(program); - Log.error(message); - } - - return program; - } - - @:noCompletion private function __disable():Void - { - if (program != null) - { - __disableGL(); - } - } - - @:noCompletion private function __disableGL():Void - { - var gl = __context.gl; - - var textureCount = 0; - - for (input in __inputBitmapData) - { - input.__disableGL(__context, textureCount); - textureCount++; - if (textureCount == gl.MAX_TEXTURE_IMAGE_UNITS) - break; - } - - for (parameter in __paramBool) - { - parameter.__disableGL(__context); - } - - for (parameter in __paramFloat) - { - parameter.__disableGL(__context); - } - - for (parameter in __paramInt) - { - parameter.__disableGL(__context); - } - - __context.__bindGLArrayBuffer(null); - - #if lime - if (__context.__context.type == OPENGL) - { - gl.disable(gl.TEXTURE_2D); - } - #end - } - - @:noCompletion private function __enable():Void - { - __init(); - - if (program != null) - { - __enableGL(); - } - } - - @:noCompletion private function __enableGL():Void - { - var textureCount = 0; - - var gl = __context.gl; - - for (input in __inputBitmapData) - { - gl.uniform1i(input.index, textureCount); - textureCount++; - } - - #if lime - if (__context.__context.type == OPENGL && textureCount > 0) - { - gl.enable(gl.TEXTURE_2D); - } - #end - } - - @:noCompletion private function __init():Void - { - if (__data == null) - { - __data = cast new ShaderData(null); - } - - if (__glFragmentSource != null && __glVertexSource != null && (program == null || __glSourceDirty)) - { - __initGL(); - } - } - - @:noCompletion private function __initGL():Void - { - if (__glSourceDirty || __paramBool == null) - { - __glSourceDirty = false; - program = null; - - __inputBitmapData = new Array(); - __paramBool = new Array(); - __paramFloat = new Array(); - __paramInt = new Array(); - - __processGLData(glVertexSource, "attribute"); - __processGLData(glVertexSource, "uniform"); - __processGLData(glFragmentSource, "uniform"); - } - - if (__context != null && program == null) - { - var gl = __context.gl; - - #if (js && html5) - var prefix = (precisionHint == FULL ? "precision mediump float;\n" : "precision lowp float;\n"); - #else - var prefix = "#ifdef GL_ES\n" - + (precisionHint == FULL ? "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" - + "precision highp float;\n" - + "#else\n" - + "precision mediump float;\n" - + "#endif\n" : "precision lowp float;\n") - + "#endif\n\n"; - #end - - var vertex = prefix + glVertexSource; - var fragment = prefix + glFragmentSource; - - var id = vertex + fragment; - - if (__context.__programs.exists(id)) - { - program = __context.__programs.get(id); - } - else - { - program = __context.createProgram(GLSL); - - // TODO - // program.uploadSources (vertex, fragment); - program.__glProgram = __createGLProgram(vertex, fragment); - - __context.__programs.set(id, program); - } - - if (program != null) - { - glProgram = program.__glProgram; - - for (input in __inputBitmapData) - { - if (input.__isUniform) - { - input.index = gl.getUniformLocation(glProgram, input.name); - } - else - { - input.index = gl.getAttribLocation(glProgram, input.name); - } - } - - for (parameter in __paramBool) - { - if (parameter.__isUniform) - { - parameter.index = gl.getUniformLocation(glProgram, parameter.name); - } - else - { - parameter.index = gl.getAttribLocation(glProgram, parameter.name); - } - } - - for (parameter in __paramFloat) - { - if (parameter.__isUniform) - { - parameter.index = gl.getUniformLocation(glProgram, parameter.name); - } - else - { - parameter.index = gl.getAttribLocation(glProgram, parameter.name); - } - } - - for (parameter in __paramInt) - { - if (parameter.__isUniform) - { - parameter.index = gl.getUniformLocation(glProgram, parameter.name); - } - else - { - parameter.index = gl.getAttribLocation(glProgram, parameter.name); - } - } - } - } - } - - @:noCompletion private function __processGLData(source:String, storageType:String):Void - { - var lastMatch = 0, position, regex, name, type; - - if (storageType == "uniform") - { - regex = ~/uniform ([A-Za-z0-9]+) ([A-Za-z0-9_]+)/; - } - else - { - regex = ~/attribute ([A-Za-z0-9]+) ([A-Za-z0-9_]+)/; - } - - while (regex.matchSub(source, lastMatch)) - { - type = regex.matched(1); - name = regex.matched(2); - - if (StringTools.startsWith(name, "gl_")) - { - continue; - } - - var isUniform = (storageType == "uniform"); - - if (StringTools.startsWith(type, "sampler")) - { - var input = new ShaderInput(); - input.name = name; - input.__isUniform = isUniform; - __inputBitmapData.push(input); - - switch (name) - { - case "openfl_Texture": - __texture = input; - case "bitmap": - __bitmap = input; - default: - } - - Reflect.setField(__data, name, input); - if (__isGenerated) - Reflect.setField(this, name, input); - } - else if (!Reflect.hasField(__data, name) || Reflect.field(__data, name) == null) - { - var parameterType:ShaderParameterType = switch (type) - { - case "bool": BOOL; - case "double", "float": FLOAT; - case "int", "uint": INT; - case "bvec2": BOOL2; - case "bvec3": BOOL3; - case "bvec4": BOOL4; - case "ivec2", "uvec2": INT2; - case "ivec3", "uvec3": INT3; - case "ivec4", "uvec4": INT4; - case "vec2", "dvec2": FLOAT2; - case "vec3", "dvec3": FLOAT3; - case "vec4", "dvec4": FLOAT4; - case "mat2", "mat2x2": MATRIX2X2; - case "mat2x3": MATRIX2X3; - case "mat2x4": MATRIX2X4; - case "mat3x2": MATRIX3X2; - case "mat3", "mat3x3": MATRIX3X3; - case "mat3x4": MATRIX3X4; - case "mat4x2": MATRIX4X2; - case "mat4x3": MATRIX4X3; - case "mat4", "mat4x4": MATRIX4X4; - default: null; - } - - var length = switch (parameterType) - { - case BOOL2, INT2, FLOAT2: 2; - case BOOL3, INT3, FLOAT3: 3; - case BOOL4, INT4, FLOAT4, MATRIX2X2: 4; - case MATRIX3X3: 9; - case MATRIX4X4: 16; - default: 1; - } - - var arrayLength = switch (parameterType) - { - case MATRIX2X2: 2; - case MATRIX3X3: 3; - case MATRIX4X4: 4; - default: 1; - } - - switch (parameterType) - { - case BOOL, BOOL2, BOOL3, BOOL4: - var parameter = new ShaderParameter(); - parameter.name = name; - parameter.type = parameterType; - parameter.__arrayLength = arrayLength; - parameter.__isBool = true; - parameter.__isUniform = isUniform; - parameter.__length = length; - __paramBool.push(parameter); - - if (name == "openfl_HasColorTransform") - { - __hasColorTransform = parameter; - } - - Reflect.setField(__data, name, parameter); - if (__isGenerated) - Reflect.setField(this, name, parameter); - - case INT, INT2, INT3, INT4: - var parameter = new ShaderParameter(); - parameter.name = name; - parameter.type = parameterType; - parameter.__arrayLength = arrayLength; - parameter.__isInt = true; - parameter.__isUniform = isUniform; - parameter.__length = length; - __paramInt.push(parameter); - Reflect.setField(__data, name, parameter); - if (__isGenerated) - Reflect.setField(this, name, parameter); - - default: - var parameter = new ShaderParameter(); - parameter.name = name; - parameter.type = parameterType; - parameter.__arrayLength = arrayLength; - #if lime - if (arrayLength > 0) - parameter.__uniformMatrix = new Float32Array(arrayLength * arrayLength); - #end - parameter.__isFloat = true; - parameter.__isUniform = isUniform; - parameter.__length = length; - __paramFloat.push(parameter); - - if (StringTools.startsWith(name, "openfl_")) - { - switch (name) - { - case "openfl_Alpha": __alpha = parameter; - case "openfl_ColorMultiplier": __colorMultiplier = parameter; - case "openfl_ColorOffset": __colorOffset = parameter; - case "openfl_Matrix": __matrix = parameter; - case "openfl_Position": __position = parameter; - case "openfl_TextureCoord": __textureCoord = parameter; - case "openfl_TextureSize": __textureSize = parameter; - default: - } - } - - Reflect.setField(__data, name, parameter); - if (__isGenerated) - Reflect.setField(this, name, parameter); - } - } - - position = regex.matchedPos(); - lastMatch = position.pos + position.len; - } - } - - @:noCompletion private function __update():Void - { - if (program != null) - { - __updateGL(); - } - } - - @:noCompletion private function __updateFromBuffer(shaderBuffer:ShaderBuffer, bufferOffset:Int):Void - { - if (program != null) - { - __updateGLFromBuffer(shaderBuffer, bufferOffset); - } - } - - @:noCompletion private function __updateGL():Void - { - var textureCount = 0; - - for (input in __inputBitmapData) - { - input.__updateGL(__context, textureCount); - textureCount++; - } - - for (parameter in __paramBool) - { - parameter.__updateGL(__context); - } - - for (parameter in __paramFloat) - { - parameter.__updateGL(__context); - } - - for (parameter in __paramInt) - { - parameter.__updateGL(__context); - } - } - - @:noCompletion private function __updateGLFromBuffer(shaderBuffer:ShaderBuffer, bufferOffset:Int):Void - { - var textureCount = 0; - var input, inputData, inputFilter, inputMipFilter, inputWrap; - - for (i in 0...shaderBuffer.inputCount) - { - input = shaderBuffer.inputRefs[i]; - inputData = shaderBuffer.inputs[i]; - inputFilter = shaderBuffer.inputFilter[i]; - inputMipFilter = shaderBuffer.inputMipFilter[i]; - inputWrap = shaderBuffer.inputWrap[i]; - - if (inputData != null) - { - input.__updateGL(__context, textureCount, inputData, inputFilter, inputMipFilter, inputWrap); - textureCount++; - } - } - - var gl = __context.gl; - - if (shaderBuffer.paramDataLength > 0) - { - if (shaderBuffer.paramDataBuffer == null) - { - shaderBuffer.paramDataBuffer = gl.createBuffer(); - } - - // Log.verbose ("bind param data buffer (length: " + shaderBuffer.paramData.length + ") (" + shaderBuffer.paramCount + ")"); - - __context.__bindGLArrayBuffer(shaderBuffer.paramDataBuffer); - gl.bufferData(gl.ARRAY_BUFFER, shaderBuffer.paramData, gl.DYNAMIC_DRAW); - } - else - { - // Log.verbose ("bind buffer null"); - - __context.__bindGLArrayBuffer(null); - } - - var boolIndex = 0; - var floatIndex = 0; - var intIndex = 0; - - var boolCount = shaderBuffer.paramBoolCount; - var floatCount = shaderBuffer.paramFloatCount; - var paramData = shaderBuffer.paramData; - - var boolRef, floatRef, intRef, hasOverride; - var overrideBoolValue:Array = null, - overrideFloatValue:Array = null, - overrideIntValue:Array = null; - - for (i in 0...shaderBuffer.paramCount) - { - hasOverride = false; - - if (i < boolCount) - { - boolRef = shaderBuffer.paramRefs_Bool[boolIndex]; - - for (j in 0...shaderBuffer.overrideBoolCount) - { - if (boolRef.name == shaderBuffer.overrideBoolNames[j]) - { - overrideBoolValue = shaderBuffer.overrideBoolValues[j]; - hasOverride = true; - break; - } - } - - if (hasOverride) - { - boolRef.__updateGL(__context, overrideBoolValue); - } - else - { - boolRef.__updateGLFromBuffer(__context, paramData, shaderBuffer.paramPositions[i], shaderBuffer.paramLengths[i], bufferOffset); - } - - boolIndex++; - } - else if (i < boolCount + floatCount) - { - floatRef = shaderBuffer.paramRefs_Float[floatIndex]; - - for (j in 0...shaderBuffer.overrideFloatCount) - { - if (floatRef.name == shaderBuffer.overrideFloatNames[j]) - { - overrideFloatValue = shaderBuffer.overrideFloatValues[j]; - hasOverride = true; - break; - } - } - - if (hasOverride) - { - floatRef.__updateGL(__context, overrideFloatValue); - } - else - { - floatRef.__updateGLFromBuffer(__context, paramData, shaderBuffer.paramPositions[i], shaderBuffer.paramLengths[i], bufferOffset); - } - - floatIndex++; - } - else - { - intRef = shaderBuffer.paramRefs_Int[intIndex]; - - for (j in 0...shaderBuffer.overrideIntCount) - { - if (intRef.name == shaderBuffer.overrideIntNames[j]) - { - overrideIntValue = cast shaderBuffer.overrideIntValues[j]; - hasOverride = true; - break; - } - } - - if (hasOverride) - { - intRef.__updateGL(__context, overrideIntValue); - } - else - { - intRef.__updateGLFromBuffer(__context, paramData, shaderBuffer.paramPositions[i], shaderBuffer.paramLengths[i], bufferOffset); - } - - intIndex++; - } - } - } - - // Get & Set Methods - @:noCompletion private function get_data():ShaderData - { - if (__glSourceDirty || __data == null) - { - __init(); - } - - return __data; - } - - @:noCompletion private function set_data(value:ShaderData):ShaderData - { - return __data = cast value; - } - - @:noCompletion private function get_glFragmentSource():String - { - return __glFragmentSource; - } - - @:noCompletion private function set_glFragmentSource(value:String):String - { - if (value != __glFragmentSource) - { - __glSourceDirty = true; - } - - return __glFragmentSource = value; - } - - @:noCompletion private function get_glVertexSource():String - { - return __glVertexSource; - } - - @:noCompletion private function set_glVertexSource(value:String):String - { - if (value != __glVertexSource) - { - __glSourceDirty = true; - } - - return __glVertexSource = value; - } -} -#else -typedef Shader = flash.display.Shader; -#end diff --git a/source/openfl/utils/Assets.hx b/source/openfl/utils/Assets.hx index 13538288c..db92e5303 100644 --- a/source/openfl/utils/Assets.hx +++ b/source/openfl/utils/Assets.hx @@ -614,7 +614,6 @@ class Assets } else { - @:privateAccess LimeAssets.libraries.remove(name); _library = new AssetLibrary(); _library.__proxy = library; LimeAssets.registerLibrary(name, _library);