Skip to content

Commit 9da807b

Browse files
committed
Added delete functions for graphics objects which have to be called manually.
1 parent 2a28819 commit 9da807b

22 files changed

+78
-68
lines changed

Backends/HTML5/kha/graphics4/FragmentShader.hx

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ class FragmentShader {
1212
this.type = GL.FRAGMENT_SHADER;
1313
this.shader = null;
1414
}
15+
16+
public function delete(): Void {
17+
SystemImpl.gl.deleteShader(shader);
18+
shader = null;
19+
source = null;
20+
}
1521
}

Backends/HTML5/kha/graphics4/IndexBuffer.hx

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class IndexBuffer {
1717
data[indexCount - 1] = 0;
1818
}
1919

20+
public function delete(): Void {
21+
data = null;
22+
SystemImpl.gl.deleteBuffer(buffer);
23+
}
24+
2025
public function lock(): Array<Int> {
2126
return data;
2227
}

Backends/HTML5/kha/graphics4/PipelineState.hx

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class PipelineState extends PipelineStateBase {
1717
textures = new Array<String>();
1818
textureValues = new Array<Dynamic>();
1919
}
20+
21+
public function delete(): Void {
22+
SystemImpl.gl.deleteProgram(program);
23+
}
2024

2125
public function compile(): Void {
2226
compileShader(vertexShader);

Backends/HTML5/kha/graphics4/VertexShader.hx

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ class VertexShader {
1212
this.type = GL.VERTEX_SHADER;
1313
this.shader = null;
1414
}
15+
16+
public function delete(): Void {
17+
SystemImpl.gl.deleteShader(shader);
18+
shader = null;
19+
source = null;
20+
}
1521
}

Backends/Kore/kha/capture/Audio.hx

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package kha.capture;
2+
3+
import kha.audio2.Buffer;
4+
5+
class Audio {
6+
public static var audioCallback: Int->Buffer->Void;
7+
8+
public static function init(initialized: Void->Void, error: Void->Void): Void {
9+
error();
10+
}
11+
}

Backends/Kore/kha/graphics4/FragmentShader.hx

+3-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import kha.Blob;
1717
@:headerClassCode("Kore::Shader* shader;")
1818
class FragmentShader {
1919
public function new(source: Blob, file: String) {
20-
initFragmentShader(source);
21-
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
20+
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::FragmentShader);');
2221
}
2322

24-
@:void private static function destroy(shader: FragmentShader): Void {
25-
untyped __cpp__('delete shader->shader;');
26-
}
27-
28-
@:functionCode("
29-
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::FragmentShader);
30-
")
31-
private function initFragmentShader(source: Blob): Void {
32-
23+
public function delete(): Void {
24+
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
3325
}
3426
}

Backends/Kore/kha/graphics4/GeometryShader.hx

+3-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import kha.Blob;
1717
@:headerClassCode("Kore::Shader* shader;")
1818
class GeometryShader {
1919
public function new(source: Blob) {
20-
initGeometryShader(source);
21-
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
20+
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::GeometryShader);');
2221
}
2322

24-
@:void private static function destroy(shader: GeometryShader): Void {
25-
untyped __cpp__('delete shader->shader;');
26-
}
27-
28-
@:functionCode("
29-
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::GeometryShader);
30-
")
31-
private function initGeometryShader(source: Blob): Void {
32-
23+
public function delete(): Void {
24+
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
3325
}
3426
}

Backends/Kore/kha/graphics4/IndexBuffer.hx

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ class IndexBuffer {
1414
myCount = indexCount;
1515
data = new Array<Int>();
1616
data[myCount - 1] = 0;
17-
init(indexCount);
17+
untyped __cpp__('buffer = new Kore::IndexBuffer(indexCount);');
1818
}
1919

20-
@:functionCode('
21-
buffer = new Kore::IndexBuffer(count);
22-
')
23-
private function init(count: Int) {
24-
20+
public function delete(): Void {
21+
untyped __cpp__('delete buffer; buffer = nullptr;');
2522
}
2623

2724
public function lock(): Array<Int> {

Backends/Kore/kha/graphics4/PipelineState.hx

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ import kha.graphics4.VertexStructure;
1515
class PipelineState extends PipelineStateBase {
1616
public function new() {
1717
super();
18-
init();
18+
untyped __cpp__('program = new Kore::Program;');
1919
}
2020

21-
@:functionCode('
22-
program = new Kore::Program();
23-
')
24-
private function init(): Void {
25-
21+
public function delete(): Void {
22+
untyped __cpp__('delete program; program = nullptr;');
2623
}
2724

2825
@:functionCode('

Backends/Kore/kha/graphics4/TesselationControlShader.hx

+3-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import kha.Blob;
1717
@:headerClassCode("Kore::Shader* shader;")
1818
class TesselationControlShader {
1919
public function new(source: Blob) {
20-
initTesselationControlShader(source);
21-
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
20+
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationControlShader);');
2221
}
2322

24-
@:void private static function destroy(shader: TesselationControlShader): Void {
25-
untyped __cpp__('delete shader->shader;');
26-
}
27-
28-
@:functionCode("
29-
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationControlShader);
30-
")
31-
private function initTesselationControlShader(source: Blob): Void {
32-
23+
public function delete(): Void {
24+
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
3325
}
3426
}

Backends/Kore/kha/graphics4/TesselationEvaluationShader.hx

+3-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import kha.Blob;
1717
@:headerClassCode("Kore::Shader* shader;")
1818
class TesselationEvaluationShader {
1919
public function new(source: Blob) {
20-
initTesselationEvaluationShader(source);
21-
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
20+
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationEvaluationShader);');
2221
}
2322

24-
@:void private static function destroy(shader: TesselationEvaluationShader): Void {
25-
untyped __cpp__('delete shader->shader;');
26-
}
27-
28-
@:functionCode("
29-
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationEvaluationShader);
30-
")
31-
private function initTesselationEvaluationShader(source: Blob): Void {
32-
23+
public function delete(): Void {
24+
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
3325
}
3426
}

Backends/Kore/kha/graphics4/VertexBuffer.hx

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class VertexBuffer {
2020
var a: VertexElement = new VertexElement("a", VertexData.Float2); //to generate include
2121
}
2222

23+
public function delete(): Void {
24+
untyped __cpp__('delete buffer; buffer = nullptr;');
25+
}
26+
2327
@:functionCode("
2428
Kore::VertexStructure structure2;
2529
for (int i = 0; i < structure->size(); ++i) {

Backends/Kore/kha/graphics4/VertexShader.hx

+3-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import kha.Blob;
1717
@:headerClassCode("Kore::Shader* shader;")
1818
class VertexShader {
1919
public function new(source: Blob, file: String) {
20-
initVertexShader(source);
21-
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
20+
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::VertexShader);');
2221
}
2322

24-
@:void private static function destroy(shader: VertexShader): Void {
25-
untyped __cpp__('delete shader->shader;');
26-
}
27-
28-
@:functionCode("
29-
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::VertexShader);
30-
")
31-
private function initVertexShader(source: Blob): Void {
32-
23+
public function delete(): Void {
24+
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
3325
}
3426
}

Sources/kha/graphics4/FragmentShader.hx

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import kha.Blob;
44

55
extern class FragmentShader {
66
public function new(source: Blob);
7+
public function delete(): Void;
78
}

Sources/kha/graphics4/GeometryShader.hx

+5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import kha.Blob;
55
#if cpp
66
extern class GeometryShader {
77
public function new(source: Blob);
8+
public function delete(): Void;
89
}
910
#else
1011
class GeometryShader {
1112
public function new(source: Blob) {
1213

1314
}
15+
16+
public function delete(): Void {
17+
18+
}
1419
}
1520
#end

Sources/kha/graphics4/IndexBuffer.hx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kha.graphics4;
22

33
extern class IndexBuffer {
44
public function new(indexCount: Int, usage: Usage, canRead: Bool = false);
5+
public function delete(): Void;
56
public function lock(): Array<Int>;
67
public function unlock(): Void;
78
public function set(): Void;

Sources/kha/graphics4/PipelineState.hx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kha.graphics4;
22

33
extern class PipelineState extends PipelineStateBase {
44
public function new();
5+
public function delete(): Void;
56
public function compile(): Void;
67
public function getConstantLocation(name: String): ConstantLocation;
78
public function getTextureUnit(name: String): TextureUnit;

Sources/kha/graphics4/TesselationControlShader.hx

+5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import kha.Blob;
55
#if cpp
66
extern class TesselationControlShader {
77
public function new(source: Blob);
8+
public function delete();
89
}
910
#else
1011
class TesselationControlShader {
1112
public function new(source: Blob) {
1213

1314
}
15+
16+
public function delete(): Void {
17+
18+
}
1419
}
1520
#end

Sources/kha/graphics4/TesselationEvaluationShader.hx

+5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import kha.Blob;
55
#if cpp
66
extern class TesselationEvaluationShader {
77
public function new(source: Blob);
8+
public function delete();
89
}
910
#else
1011
class TesselationEvaluationShader {
1112
public function new(source: Blob) {
1213

1314
}
15+
16+
public function delete(): Void {
17+
18+
}
1419
}
1520
#end

Sources/kha/graphics4/VertexBuffer.hx

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kha.arrays.Float32Array;
44

55
extern class VertexBuffer {
66
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false);
7+
public function delete(): Void;
78
public function lock(?start: Int, ?count: Int): Float32Array;
89
public function unlock(): Void;
910
public function count(): Int;

Sources/kha/graphics4/VertexShader.hx

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import kha.Blob;
44

55
extern class VertexShader {
66
public function new(source: Blob);
7+
public function delete(): Void;
78
}

0 commit comments

Comments
 (0)