forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
143
Kha/Backends/Kinc-HL/kha/graphics4/CubeMap.hx
Normal file
143
Kha/Backends/Kinc-HL/kha/graphics4/CubeMap.hx
Normal file
@ -0,0 +1,143 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
class CubeMap implements Canvas implements Resource {
|
||||
public var _texture: Pointer;
|
||||
public var _renderTarget: Pointer;
|
||||
|
||||
var format: TextureFormat;
|
||||
var graphics4: kha.graphics4.Graphics;
|
||||
|
||||
function new() {}
|
||||
|
||||
public static function createRenderTarget(size: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = null): CubeMap {
|
||||
return create2(size, format == null ? TextureFormat.RGBA32 : format, false, true, depthStencil);
|
||||
}
|
||||
|
||||
public static function create2(size: Int, format: TextureFormat, readable: Bool, renderTarget: Bool, depthStencil: DepthStencilFormat): CubeMap {
|
||||
var cubeMap = new CubeMap();
|
||||
cubeMap.format = format;
|
||||
if (renderTarget)
|
||||
cubeMap.initRenderTarget(size, getDepthBufferBits(depthStencil), getRenderTargetFormat(format), getStencilBufferBits(depthStencil));
|
||||
return cubeMap;
|
||||
}
|
||||
|
||||
function initRenderTarget(cubeMapSize: Int, depthBufferBits: Int, format: Int, stencilBufferBits: Int): Void {
|
||||
_renderTarget = kinc_cubemap_create(cubeMapSize, depthBufferBits, format, stencilBufferBits);
|
||||
_texture = null;
|
||||
}
|
||||
|
||||
static function getRenderTargetFormat(format: TextureFormat): Int {
|
||||
switch (format) {
|
||||
case RGBA32: // Target32Bit
|
||||
return 0;
|
||||
case RGBA64: // Target64BitFloat
|
||||
return 1;
|
||||
case RGBA128: // Target128BitFloat
|
||||
return 3;
|
||||
case DEPTH16: // Target16BitDepth
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static function getDepthBufferBits(depthAndStencil: DepthStencilFormat): Int {
|
||||
return switch (depthAndStencil) {
|
||||
case NoDepthAndStencil: -1;
|
||||
case DepthOnly: 24;
|
||||
case DepthAutoStencilAuto: 24;
|
||||
case Depth24Stencil8: 24;
|
||||
case Depth32Stencil8: 32;
|
||||
case Depth16: 16;
|
||||
}
|
||||
}
|
||||
|
||||
static function getStencilBufferBits(depthAndStencil: DepthStencilFormat): Int {
|
||||
return switch (depthAndStencil) {
|
||||
case NoDepthAndStencil: -1;
|
||||
case DepthOnly: -1;
|
||||
case DepthAutoStencilAuto: 8;
|
||||
case Depth24Stencil8: 8;
|
||||
case Depth32Stencil8: 8;
|
||||
case Depth16: 0;
|
||||
}
|
||||
}
|
||||
|
||||
static function getTextureFormat(format: TextureFormat): Int {
|
||||
switch (format) {
|
||||
case RGBA32:
|
||||
return 0;
|
||||
case RGBA128:
|
||||
return 3;
|
||||
case RGBA64:
|
||||
return 4;
|
||||
case A32:
|
||||
return 5;
|
||||
default:
|
||||
return 1; // Grey 8
|
||||
}
|
||||
}
|
||||
|
||||
public function unload(): Void {}
|
||||
|
||||
public function lock(level: Int = 0): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(): Void {}
|
||||
|
||||
public var width(get, never): Int;
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return _texture != null ? kinc_cubemap_texture_get_width(_texture) : kinc_cubemap_target_get_width(_renderTarget);
|
||||
}
|
||||
|
||||
function get_height(): Int {
|
||||
return _texture != null ? kinc_cubemap_texture_get_height(_texture) : kinc_cubemap_target_get_height(_renderTarget);
|
||||
}
|
||||
|
||||
public var g1(get, never): kha.graphics1.Graphics;
|
||||
|
||||
function get_g1(): kha.graphics1.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g2(get, never): kha.graphics2.Graphics;
|
||||
|
||||
function get_g2(): kha.graphics2.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g4(get, never): kha.graphics4.Graphics;
|
||||
|
||||
function get_g4(): kha.graphics4.Graphics {
|
||||
if (graphics4 == null) {
|
||||
graphics4 = new kha.korehl.graphics4.Graphics(this);
|
||||
}
|
||||
return graphics4;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_cubemap_create") static function kinc_cubemap_create(cubeMapSize: Int, depthBufferBits: Int, format: Int,
|
||||
stencilBufferBits: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_cubemap_texture_get_width") static function kinc_cubemap_texture_get_width(texture: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_cubemap_texture_get_height") static function kinc_cubemap_texture_get_height(texture: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_cubemap_target_get_width") static function kinc_cubemap_target_get_width(target: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_cubemap_target_get_height") static function kinc_cubemap_target_get_height(target: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
31
Kha/Backends/Kinc-HL/kha/graphics4/FragmentShader.hx
Normal file
31
Kha/Backends/Kinc-HL/kha/graphics4/FragmentShader.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class FragmentShader {
|
||||
public var _shader: Pointer;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
initShader(sources[0]);
|
||||
}
|
||||
|
||||
function initShader(source: Blob): Void {
|
||||
_shader = kinc_create_fragmentshader(source.bytes.getData(), source.bytes.getData().length);
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): FragmentShader {
|
||||
var sh = new FragmentShader(null, null);
|
||||
sh._shader = kinc_fragmentshader_from_source(StringHelper.convert(source));
|
||||
return sh;
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_fragmentshader") static function kinc_create_fragmentshader(data: hl.Bytes, length: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_fragmentshader_from_source") static function kinc_fragmentshader_from_source(source: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
}
|
31
Kha/Backends/Kinc-HL/kha/graphics4/GeometryShader.hx
Normal file
31
Kha/Backends/Kinc-HL/kha/graphics4/GeometryShader.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class GeometryShader {
|
||||
public var _shader: Pointer;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
initShader(sources[0]);
|
||||
}
|
||||
|
||||
function initShader(source: Blob): Void {
|
||||
_shader = kinc_create_geometryshader(source.bytes.getData(), source.bytes.getData().length);
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): GeometryShader {
|
||||
var sh = new GeometryShader(null, null);
|
||||
sh._shader = kinc_geometryshader_from_source(StringHelper.convert(source));
|
||||
return sh;
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_geometryshader") static function kinc_create_geometryshader(data: hl.Bytes, length: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_geometryshader_from_source") static function kinc_geometryshader_from_source(source: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
}
|
49
Kha/Backends/Kinc-HL/kha/graphics4/IndexBuffer.hx
Normal file
49
Kha/Backends/Kinc-HL/kha/graphics4/IndexBuffer.hx
Normal file
@ -0,0 +1,49 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesData;
|
||||
|
||||
class IndexBuffer {
|
||||
public var _buffer: Pointer;
|
||||
|
||||
var myCount: Int;
|
||||
|
||||
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {
|
||||
myCount = indexCount;
|
||||
_buffer = kinc_create_indexbuffer(indexCount);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
kinc_delete_indexbuffer(_buffer);
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): kha.arrays.Uint32Array {
|
||||
if (start == null)
|
||||
start = 0;
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
return cast new kha.arrays.ByteArray(kinc_indexbuffer_lock(_buffer, start, count), 0, count * 4);
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
if (count == null)
|
||||
count = this.count();
|
||||
kinc_indexbuffer_unlock(_buffer, count);
|
||||
}
|
||||
|
||||
public function count(): Int {
|
||||
return myCount;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_create_indexbuffer") static function kinc_create_indexbuffer(count: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_delete_indexbuffer") static function kinc_delete_indexbuffer(buffer: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_indexbuffer_lock") static function kinc_indexbuffer_lock(buffer: Pointer, start: Int, count: Int): hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_indexbuffer_unlock") static function kinc_indexbuffer_unlock(buffer: Pointer, count: Int): Void {}
|
||||
}
|
168
Kha/Backends/Kinc-HL/kha/graphics4/PipelineState.hx
Normal file
168
Kha/Backends/Kinc-HL/kha/graphics4/PipelineState.hx
Normal file
@ -0,0 +1,168 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.graphics4.FragmentShader;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexElement;
|
||||
import kha.graphics4.VertexShader;
|
||||
import kha.graphics4.VertexStructure;
|
||||
|
||||
class PipelineState extends PipelineStateBase {
|
||||
var _pipeline: Pointer;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
function init(): Void {
|
||||
_pipeline = kinc_create_pipeline();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
kinc_delete_pipeline(_pipeline);
|
||||
}
|
||||
|
||||
function linkWithStructures2(structure0: VertexStructure, structure1: VertexStructure, structure2: VertexStructure, structure3: VertexStructure,
|
||||
count: Int): Void {
|
||||
kinc_pipeline_set_vertex_shader(_pipeline, vertexShader._shader);
|
||||
kinc_pipeline_set_fragment_shader(_pipeline, fragmentShader._shader);
|
||||
if (geometryShader != null)
|
||||
kinc_pipeline_set_geometry_shader(_pipeline, geometryShader._shader);
|
||||
if (tessellationControlShader != null)
|
||||
kinc_pipeline_set_tesscontrol_shader(_pipeline, tessellationControlShader._shader);
|
||||
if (tessellationEvaluationShader != null)
|
||||
kinc_pipeline_set_tesseval_shader(_pipeline, tessellationEvaluationShader._shader);
|
||||
|
||||
var structures = [structure0, structure1, structure2, structure3];
|
||||
var kinc_structures: Array<Pointer> = [];
|
||||
|
||||
for (i in 0...count) {
|
||||
var kinc_structure = VertexBuffer.kinc_create_vertexstructure(structures[i].instanced);
|
||||
kinc_structures.push(kinc_structure);
|
||||
for (j in 0...structures[i].size()) {
|
||||
var vertexElement = structures[i].get(j);
|
||||
VertexBuffer.kinc_vertexstructure_add(kinc_structure, StringHelper.convert(vertexElement.name),
|
||||
VertexBuffer.convertVertexDataToKinc(vertexElement.data));
|
||||
}
|
||||
}
|
||||
|
||||
kinc_pipeline_compile(_pipeline, kinc_structures[0], count > 1 ? kinc_structures[1] : null, count > 2 ? kinc_structures[2] : null,
|
||||
count > 3 ? kinc_structures[3] : null);
|
||||
}
|
||||
|
||||
static function getDepthBufferBits(depthAndStencil: DepthStencilFormat): Int {
|
||||
return switch (depthAndStencil) {
|
||||
case NoDepthAndStencil: 0;
|
||||
case DepthOnly: 24;
|
||||
case DepthAutoStencilAuto: 24;
|
||||
case Depth24Stencil8: 24;
|
||||
case Depth32Stencil8: 32;
|
||||
case Depth16: 16;
|
||||
}
|
||||
}
|
||||
|
||||
static function getStencilBufferBits(depthAndStencil: DepthStencilFormat): Int {
|
||||
return switch (depthAndStencil) {
|
||||
case NoDepthAndStencil: 0;
|
||||
case DepthOnly: 0;
|
||||
case DepthAutoStencilAuto: 8;
|
||||
case Depth24Stencil8: 8;
|
||||
case Depth32Stencil8: 8;
|
||||
case Depth16: 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(): Void {
|
||||
var stencilReferenceValue = 0;
|
||||
switch (this.stencilReferenceValue) {
|
||||
case Static(value):
|
||||
stencilReferenceValue = value;
|
||||
default:
|
||||
}
|
||||
kinc_pipeline_set_states(_pipeline, cullMode, depthMode, stencilFrontMode, stencilFrontBothPass, stencilFrontDepthFail, stencilFrontFail,
|
||||
stencilBackMode, stencilBackBothPass, stencilBackDepthFail, stencilBackFail, getBlendFunc(blendSource), getBlendFunc(blendDestination),
|
||||
getBlendFunc(alphaBlendSource), getBlendFunc(alphaBlendDestination), depthWrite, stencilReferenceValue, stencilReadMask, stencilWriteMask,
|
||||
colorWriteMaskRed, colorWriteMaskGreen, colorWriteMaskBlue, colorWriteMaskAlpha, colorAttachmentCount, colorAttachments[0], colorAttachments[1],
|
||||
colorAttachments[2], colorAttachments[3], colorAttachments[4], colorAttachments[5], colorAttachments[6], colorAttachments[7],
|
||||
getDepthBufferBits(depthStencilAttachment), getStencilBufferBits(depthStencilAttachment), conservativeRasterization);
|
||||
linkWithStructures2(inputLayout.length > 0 ? inputLayout[0] : null, inputLayout.length > 1 ? inputLayout[1] : null,
|
||||
inputLayout.length > 2 ? inputLayout[2] : null, inputLayout.length > 3 ? inputLayout[3] : null, inputLayout.length);
|
||||
}
|
||||
|
||||
public function getConstantLocation(name: String): kha.graphics4.ConstantLocation {
|
||||
return new kha.korehl.graphics4.ConstantLocation(kinc_pipeline_get_constantlocation(_pipeline, StringHelper.convert(name)));
|
||||
}
|
||||
|
||||
public function getTextureUnit(name: String): kha.graphics4.TextureUnit {
|
||||
return new kha.korehl.graphics4.TextureUnit(kinc_pipeline_get_textureunit(_pipeline, StringHelper.convert(name)));
|
||||
}
|
||||
|
||||
static function getBlendFunc(factor: BlendingFactor): Int {
|
||||
switch (factor) {
|
||||
case BlendOne, Undefined:
|
||||
return 0;
|
||||
case BlendZero:
|
||||
return 1;
|
||||
case SourceAlpha:
|
||||
return 2;
|
||||
case DestinationAlpha:
|
||||
return 3;
|
||||
case InverseSourceAlpha:
|
||||
return 4;
|
||||
case InverseDestinationAlpha:
|
||||
return 5;
|
||||
case SourceColor:
|
||||
return 6;
|
||||
case DestinationColor:
|
||||
return 7;
|
||||
case InverseSourceColor:
|
||||
return 8;
|
||||
case InverseDestinationColor:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function set(): Void {
|
||||
kinc_pipeline_set(_pipeline);
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_create_pipeline") static function kinc_create_pipeline(): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_delete_pipeline") static function kinc_delete_pipeline(pipeline: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_fragment_shader") static function kinc_pipeline_set_fragment_shader(pipeline: Pointer, shader: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_vertex_shader") static function kinc_pipeline_set_vertex_shader(pipeline: Pointer, shader: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_geometry_shader") static function kinc_pipeline_set_geometry_shader(pipeline: Pointer, shader: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_tesscontrol_shader") static function kinc_pipeline_set_tesscontrol_shader(pipeline: Pointer, shader: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_tesseval_shader") static function kinc_pipeline_set_tesseval_shader(pipeline: Pointer, shader: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_compile") static function kinc_pipeline_compile(pipeline: Pointer, structure0: Pointer, structure1: Pointer,
|
||||
structure2: Pointer, structure3: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_get_constantlocation") static function kinc_pipeline_get_constantlocation(pipeline: Pointer, name: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_get_textureunit") static function kinc_pipeline_get_textureunit(pipeline: Pointer, name: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set_states") static function kinc_pipeline_set_states(pipeline: Pointer, cullMode: Int, depthMode: Int,
|
||||
stencilFrontMode: Int, stencilFrontBothPass: Int, stencilFrontDepthFail: Int, stencilFrontFail: Int, stencilBackMode: Int, stencilBackBothPass: Int,
|
||||
stencilBackDepthFail: Int, stencilBackFail: Int, blendSource: Int, blendDestination: Int, alphaBlendSource: Int, alphaBlendDestination: Int,
|
||||
depthWrite: Bool, stencilReferenceValue: Int, stencilReadMask: Int, stencilWriteMask: Int, colorWriteMaskRed: Bool, colorWriteMaskGreen: Bool,
|
||||
colorWriteMaskBlue: Bool, colorWriteMaskAlpha: Bool, colorAttachmentCount: Int, colorAttachment0: TextureFormat, colorAttachment1: TextureFormat,
|
||||
colorAttachment2: TextureFormat, colorAttachment3: TextureFormat, colorAttachment4: TextureFormat, colorAttachment5: TextureFormat,
|
||||
colorAttachment6: TextureFormat, colorAttachment7: TextureFormat, depthAttachmentBits: Int, stencilAttachmentBits: Int,
|
||||
conservativeRasterization: Bool): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_pipeline_set") static function kinc_pipeline_set(pipeline: Pointer): Void {}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
|
||||
class TessellationControlShader {
|
||||
public var _shader: Pointer;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
initShader(sources[0]);
|
||||
}
|
||||
|
||||
function initShader(source: Blob): Void {
|
||||
_shader = kinc_create_tesscontrolshader(source.bytes.getData(), source.bytes.getData().length);
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): TessellationControlShader {
|
||||
var sh = new TessellationControlShader(null, null);
|
||||
sh._shader = kinc_tesscontrolshader_from_source(StringHelper.convert(source));
|
||||
return sh;
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_tesscontrolshader") static function kinc_create_tesscontrolshader(data: hl.Bytes, length: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_tesscontrolshader_from_source") static function kinc_tesscontrolshader_from_source(source: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class TessellationEvaluationShader {
|
||||
public var _shader: Pointer;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
initShader(sources[0]);
|
||||
}
|
||||
|
||||
function initShader(source: Blob): Void {
|
||||
_shader = kinc_create_tessevalshader(source.bytes.getData(), source.bytes.getData().length);
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): TessellationEvaluationShader {
|
||||
var sh = new TessellationEvaluationShader(null, null);
|
||||
sh._shader = kinc_tessevalshader_from_source(StringHelper.convert(source));
|
||||
return sh;
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_tessevalshader") static function kinc_create_tessevalshader(data: hl.Bytes, length: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_tessevalshader_from_source") static function kinc_tessevalshader_from_source(source: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
}
|
115
Kha/Backends/Kinc-HL/kha/graphics4/VertexBuffer.hx
Normal file
115
Kha/Backends/Kinc-HL/kha/graphics4/VertexBuffer.hx
Normal file
@ -0,0 +1,115 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.arrays.ByteArray;
|
||||
import kha.arrays.Float32Array;
|
||||
import kha.arrays.Int16Array;
|
||||
import kha.graphics4.VertexData;
|
||||
import kha.graphics4.VertexElement;
|
||||
import kha.graphics4.VertexStructure;
|
||||
|
||||
class VertexBuffer {
|
||||
public var _buffer: Pointer;
|
||||
|
||||
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false) {
|
||||
var structure2 = kinc_create_vertexstructure(structure.instanced);
|
||||
for (i in 0...structure.size()) {
|
||||
var vertexElement = structure.get(i);
|
||||
kinc_vertexstructure_add(structure2, StringHelper.convert(vertexElement.name), convertVertexDataToKinc(vertexElement.data));
|
||||
}
|
||||
_buffer = kinc_create_vertexbuffer(vertexCount, structure2, usage, instanceDataStepRate);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
kinc_delete_vertexbuffer(_buffer);
|
||||
}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Float32Array {
|
||||
return cast new ByteArray(kinc_vertexbuffer_lock(_buffer), 0, this.count() * stride());
|
||||
}
|
||||
|
||||
public function lockInt16(?start: Int, ?count: Int): Int16Array {
|
||||
return cast new ByteArray(kinc_vertexbuffer_lock(_buffer), 0, this.count() * stride());
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {
|
||||
kinc_vertexbuffer_unlock(_buffer, count == null ? this.count() : count);
|
||||
}
|
||||
|
||||
public function stride(): Int {
|
||||
return kinc_vertexbuffer_stride(_buffer);
|
||||
}
|
||||
|
||||
public function count(): Int {
|
||||
return kinc_vertexbuffer_count(_buffer);
|
||||
}
|
||||
|
||||
/** Convert Kha vertex data enum values to Kinc enum values **/
|
||||
public static inline function convertVertexDataToKinc(data: VertexData): Int {
|
||||
return switch (data) {
|
||||
case Float32_1X: 1; // KINC_G4_VERTEX_DATA_F32_1X
|
||||
case Float32_2X: 2; // KINC_G4_VERTEX_DATA_F32_2X
|
||||
case Float32_3X: 3; // KINC_G4_VERTEX_DATA_F32_3X
|
||||
case Float32_4X: 4; // KINC_G4_VERTEX_DATA_F32_4X
|
||||
case Float32_4X4: 5; // KINC_G4_VERTEX_DATA_F32_4X4
|
||||
case Int8_1X: 6; // KINC_G4_VERTEX_DATA_I8_1X
|
||||
case UInt8_1X: 7; // KINC_G4_VERTEX_DATA_U8_1X
|
||||
case Int8_1X_Normalized: 8; // KINC_G4_VERTEX_DATA_I8_1X_NORMALIZED
|
||||
case UInt8_1X_Normalized: 9; // KINC_G4_VERTEX_DATA_U8_1X_NORMALIZED
|
||||
case Int8_2X: 10; // KINC_G4_VERTEX_DATA_I8_2X
|
||||
case UInt8_2X: 11; // KINC_G4_VERTEX_DATA_U8_2X
|
||||
case Int8_2X_Normalized: 12; // KINC_G4_VERTEX_DATA_I8_2X_NORMALIZED
|
||||
case UInt8_2X_Normalized: 13; // KINC_G4_VERTEX_DATA_U8_2X_NORMALIZED
|
||||
case Int8_4X: 14; // KINC_G4_VERTEX_DATA_I8_4X
|
||||
case UInt8_4X: 15; // KINC_G4_VERTEX_DATA_U8_4X
|
||||
case Int8_4X_Normalized: 16; // KINC_G4_VERTEX_DATA_I8_4X_NORMALIZED
|
||||
case UInt8_4X_Normalized: 17; // KINC_G4_VERTEX_DATA_U8_4X_NORMALIZED
|
||||
case Int16_1X: 18; // KINC_G4_VERTEX_DATA_I16_1X
|
||||
case UInt16_1X: 19; // KINC_G4_VERTEX_DATA_U16_1X
|
||||
case Int16_1X_Normalized: 20; // KINC_G4_VERTEX_DATA_I16_1X_NORMALIZED
|
||||
case UInt16_1X_Normalized: 21; // KINC_G4_VERTEX_DATA_U16_1X_NORMALIZED
|
||||
case Int16_2X: 22; // KINC_G4_VERTEX_DATA_I16_2X
|
||||
case UInt16_2X: 23; // KINC_G4_VERTEX_DATA_U16_2X
|
||||
case Int16_2X_Normalized: 24; // KINC_G4_VERTEX_DATA_I16_2X_NORMALIZED
|
||||
case UInt16_2X_Normalized: 25; // KINC_G4_VERTEX_DATA_U16_2X_NORMALIZED
|
||||
case Int16_4X: 26; // KINC_G4_VERTEX_DATA_I16_4X
|
||||
case UInt16_4X: 27; // KINC_G4_VERTEX_DATA_U16_4X
|
||||
case Int16_4X_Normalized: 28; // KINC_G4_VERTEX_DATA_I16_4X_NORMALIZED
|
||||
case UInt16_4X_Normalized: 29; // KINC_G4_VERTEX_DATA_U16_4X_NORMALIZED
|
||||
case Int32_1X: 30; // KINC_G4_VERTEX_DATA_I32_1X
|
||||
case UInt32_1X: 31; // KINC_G4_VERTEX_DATA_U32_1X
|
||||
case Int32_2X: 32; // KINC_G4_VERTEX_DATA_I32_2X
|
||||
case UInt32_2X: 33; // KINC_G4_VERTEX_DATA_U32_2X
|
||||
case Int32_3X: 34; // KINC_G4_VERTEX_DATA_I32_3X
|
||||
case UInt32_3X: 35; // KINC_G4_VERTEX_DATA_U32_3X
|
||||
case Int32_4X: 36; // KINC_G4_VERTEX_DATA_I32_4X
|
||||
case UInt32_4X: 37; // KINC_G4_VERTEX_DATA_U32_4X
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_create_vertexstructure") public static function kinc_create_vertexstructure(instanced: Bool): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_vertexstructure_add") public static function kinc_vertexstructure_add(structure: Pointer, name: hl.Bytes, data: Int): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_vertexbuffer") static function kinc_create_vertexbuffer(vertexCount: Int, structure: Pointer, usage: Int,
|
||||
stepRate: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_delete_vertexbuffer") static function kinc_delete_vertexbuffer(buffer: Pointer): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_vertexbuffer_lock") static function kinc_vertexbuffer_lock(buffer: Pointer): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_vertexbuffer_unlock") static function kinc_vertexbuffer_unlock(buffer: Pointer, count: Int): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_vertexbuffer_stride") static function kinc_vertexbuffer_stride(buffer: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_vertexbuffer_count") static function kinc_vertexbuffer_count(buffer: Pointer): Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
31
Kha/Backends/Kinc-HL/kha/graphics4/VertexShader.hx
Normal file
31
Kha/Backends/Kinc-HL/kha/graphics4/VertexShader.hx
Normal file
@ -0,0 +1,31 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class VertexShader {
|
||||
public var _shader: Pointer;
|
||||
|
||||
public function new(sources: Array<Blob>, files: Array<String>) {
|
||||
initShader(sources[0]);
|
||||
}
|
||||
|
||||
function initShader(source: Blob): Void {
|
||||
_shader = kinc_create_vertexshader(source.bytes.getData(), source.bytes.getData().length);
|
||||
}
|
||||
|
||||
public static function fromSource(source: String): VertexShader {
|
||||
var sh = new VertexShader(null, null);
|
||||
sh._shader = kinc_vertexshader_from_source(StringHelper.convert(source));
|
||||
return sh;
|
||||
}
|
||||
|
||||
public function delete(): Void {}
|
||||
|
||||
@:hlNative("std", "kinc_create_vertexshader") static function kinc_create_vertexshader(data: hl.Bytes, length: Int): Pointer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "kinc_vertexshader_from_source") static function kinc_vertexshader_from_source(source: hl.Bytes): Pointer {
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user