package kha.js.graphics4;
import js.html.webgl.GL2;
import kha.graphics4.StencilValue;
import kha.arrays.Float32Array;
import kha.arrays.Int32Array;
import js.html.webgl.GL;
import kha.graphics4.BlendingFactor;
import kha.graphics4.BlendingOperation;
import kha.graphics4.CompareMode;
import kha.graphics4.CubeMap;
import kha.graphics4.CullMode;
import kha.graphics4.IndexBuffer;
import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState;
import kha.graphics4.StencilAction;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.Usage;
import kha.graphics4.VertexBuffer;
import kha.graphics4.VertexStructure;
import kha.Image;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.WebGLImage;
class Graphics implements kha.graphics4.Graphics {
var currentPipeline: PipelineState = null;
var depthTest: Bool = false;
var depthMask: Bool = false;
var colorMaskRed: Bool = true;
var colorMaskGreen: Bool = true;
var colorMaskBlue: Bool = true;
var colorMaskAlpha: Bool = true;
var indicesCount: Int;
var renderTarget: Canvas;
var renderTargetFrameBuffer: Dynamic;
var renderTargetMSAA: Dynamic;
var renderTargetTexture: Dynamic;
var isCubeMap: Bool = false;
var isDepthAttachment: Bool = false;
var instancedExtension: Dynamic;
var blendMinMaxExtension: Dynamic;
static var current: Graphics = null;
static var useVertexAttributes: Int = 0;
public function new(renderTarget: Canvas = null) {
this.renderTarget = renderTarget;
init();
if (SystemImpl.gl2) {
instancedExtension = true;
}
else {
instancedExtension = SystemImpl.gl.getExtension("ANGLE_instanced_arrays");
blendMinMaxExtension = SystemImpl.gl.getExtension("EXT_blend_minmax");
}
}
function init() {
if (renderTarget == null)
return;
isCubeMap = Std.isOfType(renderTarget, CubeMap);
if (isCubeMap) {
var cubeMap: CubeMap = cast(renderTarget, CubeMap);
renderTargetFrameBuffer = cubeMap.frameBuffer;
renderTargetTexture = cubeMap.texture;
isDepthAttachment = cubeMap.isDepthAttachment;
}
else {
var image: WebGLImage = cast(renderTarget, WebGLImage);
renderTargetFrameBuffer = image.frameBuffer;
renderTargetMSAA = image.MSAAFrameBuffer;
renderTargetTexture = image.texture;
}
}
public function begin(additionalRenderTargets: Array