mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 01:49:07 -07:00
agalVersion option in ShaderProgram constructor
This commit is contained in:
@@ -1,57 +1,60 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
* If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
|
||||
* You may add additional accurate notices of copyright ownership.
|
||||
*
|
||||
* It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/
|
||||
* */
|
||||
|
||||
package alternativa.engine3d.materials {
|
||||
import alternativa.engine3d.alternativa3d;
|
||||
import alternativa.engine3d.materials.compiler.Linker;
|
||||
|
||||
import flash.display3D.Context3D;
|
||||
import flash.display3D.Program3D;
|
||||
|
||||
use namespace alternativa3d;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public class ShaderProgram {
|
||||
|
||||
public var program:Program3D;
|
||||
|
||||
public var vertexShader:Linker;
|
||||
public var fragmentShader:Linker;
|
||||
|
||||
public function ShaderProgram(vertexShader:Linker, fragmentShader:Linker) {
|
||||
this.vertexShader = vertexShader;
|
||||
this.fragmentShader = fragmentShader;
|
||||
}
|
||||
|
||||
public function upload(context3D:Context3D):void {
|
||||
if (program != null) program.dispose();
|
||||
if (vertexShader != null && fragmentShader != null) {
|
||||
vertexShader.link();
|
||||
fragmentShader.link();
|
||||
program = context3D.createProgram();
|
||||
try {
|
||||
program.upload(vertexShader.data, fragmentShader.data);
|
||||
} catch (e:Error) {
|
||||
throw (e);
|
||||
}
|
||||
} else {
|
||||
program = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():void {
|
||||
if (program != null) {
|
||||
program.dispose();
|
||||
program = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
* If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
|
||||
* You may add additional accurate notices of copyright ownership.
|
||||
*
|
||||
* It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/
|
||||
* */
|
||||
|
||||
package alternativa.engine3d.materials {
|
||||
|
||||
import alternativa.engine3d.alternativa3d;
|
||||
import alternativa.engine3d.materials.compiler.Linker;
|
||||
|
||||
import flash.display3D.Context3D;
|
||||
import flash.display3D.Program3D;
|
||||
|
||||
use namespace alternativa3d;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public class ShaderProgram {
|
||||
|
||||
public var program:Program3D;
|
||||
|
||||
public var vertexShader:Linker;
|
||||
public var fragmentShader:Linker;
|
||||
public var agalVersion:uint;
|
||||
|
||||
public function ShaderProgram(vertexShader:Linker, fragmentShader:Linker, agalVersion:uint = 1) {
|
||||
this.vertexShader = vertexShader;
|
||||
this.fragmentShader = fragmentShader;
|
||||
this.agalVersion = agalVersion;
|
||||
}
|
||||
|
||||
public function upload(context3D:Context3D):void {
|
||||
if (program != null) program.dispose();
|
||||
if (vertexShader != null && fragmentShader != null) {
|
||||
vertexShader.link(agalVersion);
|
||||
fragmentShader.link(agalVersion);
|
||||
program = context3D.createProgram();
|
||||
try {
|
||||
program.upload(vertexShader.data, fragmentShader.data);
|
||||
} catch (e:Error) {
|
||||
throw (e);
|
||||
}
|
||||
} else {
|
||||
program = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():void {
|
||||
if (program != null) {
|
||||
program.dispose();
|
||||
program = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user