/** * Add a new blend mode. * * @param name The name of the blend mode * @param vertex The path of the vertex file. * @param fragment The path of the fragment file. * @return The program shader. */ public static FlxShaderProgram addBlendMode(String name, String vertex, String fragment) { FlxShaderProgram shader; if (FlxG._cache.containsAsset(name, FlxShaderProgram.class)) shader = FlxG._cache.load(name, FlxShaderProgram.class); else shader = FlxG.loadShader(name, vertex, fragment); return shader; }
/** * Creates a shader program from the default vertex and blend mode. You may want to create the * shader during <code>FlxState.create()</code> and apply it later to the * * @param name The name of the blend mode, e.g. <code>BlendModeGL20.ADD</code>. * @return The program shader that is created. */ public static FlxShaderProgram createProgram(String name) { FlxShaderProgram shader; if (FlxG._cache.containsAsset(name, FlxShaderProgram.class)) shader = FlxG._cache.load(name, FlxShaderProgram.class); else { shader = FlxG.loadShader(name, VERTEX, name); IFlxShaderProgram callback = new IFlxShaderProgram() { @Override public void loadShaderSettings(ShaderProgram shader) { shader.begin(); if (shader.hasUniform("u_texture")) shader.setUniformi("u_texture", 1); if (shader.hasUniform("u_texture1")) shader.setUniformi("u_texture1", 2); shader.end(); // TODO: set texture coordinates } }; callback.loadShaderSettings(shader); shader.callback = callback; } return shader; }