Skip to content

Commit

Permalink
Added delete functions for graphics objects which have to be called m…
Browse files Browse the repository at this point in the history
…anually.
  • Loading branch information
RobDangerous committed Jul 3, 2016
1 parent 2a28819 commit 9da807b
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 68 deletions.
6 changes: 6 additions & 0 deletions Backends/HTML5/kha/graphics4/FragmentShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class FragmentShader {
this.type = GL.FRAGMENT_SHADER;
this.shader = null;
}

public function delete(): Void {
SystemImpl.gl.deleteShader(shader);
shader = null;
source = null;
}
}
5 changes: 5 additions & 0 deletions Backends/HTML5/kha/graphics4/IndexBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class IndexBuffer {
data[indexCount - 1] = 0;
}

public function delete(): Void {
data = null;
SystemImpl.gl.deleteBuffer(buffer);
}

public function lock(): Array<Int> {
return data;
}
Expand Down
4 changes: 4 additions & 0 deletions Backends/HTML5/kha/graphics4/PipelineState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class PipelineState extends PipelineStateBase {
textures = new Array<String>();
textureValues = new Array<Dynamic>();
}

public function delete(): Void {
SystemImpl.gl.deleteProgram(program);
}

public function compile(): Void {
compileShader(vertexShader);
Expand Down
6 changes: 6 additions & 0 deletions Backends/HTML5/kha/graphics4/VertexShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class VertexShader {
this.type = GL.VERTEX_SHADER;
this.shader = null;
}

public function delete(): Void {
SystemImpl.gl.deleteShader(shader);
shader = null;
source = null;
}
}
11 changes: 11 additions & 0 deletions Backends/Kore/kha/capture/Audio.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kha.capture;

import kha.audio2.Buffer;

class Audio {
public static var audioCallback: Int->Buffer->Void;

public static function init(initialized: Void->Void, error: Void->Void): Void {
error();
}
}
14 changes: 3 additions & 11 deletions Backends/Kore/kha/graphics4/FragmentShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import kha.Blob;
@:headerClassCode("Kore::Shader* shader;")
class FragmentShader {
public function new(source: Blob, file: String) {
initFragmentShader(source);
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::FragmentShader);');
}

@:void private static function destroy(shader: FragmentShader): Void {
untyped __cpp__('delete shader->shader;');
}

@:functionCode("
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::FragmentShader);
")
private function initFragmentShader(source: Blob): Void {

public function delete(): Void {
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
}
}
14 changes: 3 additions & 11 deletions Backends/Kore/kha/graphics4/GeometryShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import kha.Blob;
@:headerClassCode("Kore::Shader* shader;")
class GeometryShader {
public function new(source: Blob) {
initGeometryShader(source);
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::GeometryShader);');
}

@:void private static function destroy(shader: GeometryShader): Void {
untyped __cpp__('delete shader->shader;');
}

@:functionCode("
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::GeometryShader);
")
private function initGeometryShader(source: Blob): Void {

public function delete(): Void {
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
}
}
9 changes: 3 additions & 6 deletions Backends/Kore/kha/graphics4/IndexBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ class IndexBuffer {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
init(indexCount);
untyped __cpp__('buffer = new Kore::IndexBuffer(indexCount);');
}

@:functionCode('
buffer = new Kore::IndexBuffer(count);
')
private function init(count: Int) {

public function delete(): Void {
untyped __cpp__('delete buffer; buffer = nullptr;');
}

public function lock(): Array<Int> {
Expand Down
9 changes: 3 additions & 6 deletions Backends/Kore/kha/graphics4/PipelineState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import kha.graphics4.VertexStructure;
class PipelineState extends PipelineStateBase {
public function new() {
super();
init();
untyped __cpp__('program = new Kore::Program;');
}

@:functionCode('
program = new Kore::Program();
')
private function init(): Void {

public function delete(): Void {
untyped __cpp__('delete program; program = nullptr;');
}

@:functionCode('
Expand Down
14 changes: 3 additions & 11 deletions Backends/Kore/kha/graphics4/TesselationControlShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import kha.Blob;
@:headerClassCode("Kore::Shader* shader;")
class TesselationControlShader {
public function new(source: Blob) {
initTesselationControlShader(source);
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationControlShader);');
}

@:void private static function destroy(shader: TesselationControlShader): Void {
untyped __cpp__('delete shader->shader;');
}

@:functionCode("
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationControlShader);
")
private function initTesselationControlShader(source: Blob): Void {

public function delete(): Void {
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
}
}
14 changes: 3 additions & 11 deletions Backends/Kore/kha/graphics4/TesselationEvaluationShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import kha.Blob;
@:headerClassCode("Kore::Shader* shader;")
class TesselationEvaluationShader {
public function new(source: Blob) {
initTesselationEvaluationShader(source);
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationEvaluationShader);');
}

@:void private static function destroy(shader: TesselationEvaluationShader): Void {
untyped __cpp__('delete shader->shader;');
}

@:functionCode("
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::TesselationEvaluationShader);
")
private function initTesselationEvaluationShader(source: Blob): Void {

public function delete(): Void {
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
}
}
4 changes: 4 additions & 0 deletions Backends/Kore/kha/graphics4/VertexBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class VertexBuffer {
var a: VertexElement = new VertexElement("a", VertexData.Float2); //to generate include
}

public function delete(): Void {
untyped __cpp__('delete buffer; buffer = nullptr;');
}

@:functionCode("
Kore::VertexStructure structure2;
for (int i = 0; i < structure->size(); ++i) {
Expand Down
14 changes: 3 additions & 11 deletions Backends/Kore/kha/graphics4/VertexShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ import kha.Blob;
@:headerClassCode("Kore::Shader* shader;")
class VertexShader {
public function new(source: Blob, file: String) {
initVertexShader(source);
//cpp.vm.Gc.setFinalizer(this, cpp.Function.fromStaticFunction(destroy)); // TODO
untyped __cpp__('shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::VertexShader);');
}

@:void private static function destroy(shader: VertexShader): Void {
untyped __cpp__('delete shader->shader;');
}

@:functionCode("
shader = new Kore::Shader(source->bytes->b->Pointer(), source->get_length(), Kore::VertexShader);
")
private function initVertexShader(source: Blob): Void {

public function delete(): Void {
untyped __cpp__('delete shader->shader; shader->shader = nullptr;');
}
}
2 changes: 1 addition & 1 deletion Kore
1 change: 1 addition & 0 deletions Sources/kha/graphics4/FragmentShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import kha.Blob;

extern class FragmentShader {
public function new(source: Blob);
public function delete(): Void;
}
5 changes: 5 additions & 0 deletions Sources/kha/graphics4/GeometryShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import kha.Blob;
#if cpp
extern class GeometryShader {
public function new(source: Blob);
public function delete(): Void;
}
#else
class GeometryShader {
public function new(source: Blob) {

}

public function delete(): Void {

}
}
#end
1 change: 1 addition & 0 deletions Sources/kha/graphics4/IndexBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kha.graphics4;

extern class IndexBuffer {
public function new(indexCount: Int, usage: Usage, canRead: Bool = false);
public function delete(): Void;
public function lock(): Array<Int>;
public function unlock(): Void;
public function set(): Void;
Expand Down
1 change: 1 addition & 0 deletions Sources/kha/graphics4/PipelineState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kha.graphics4;

extern class PipelineState extends PipelineStateBase {
public function new();
public function delete(): Void;
public function compile(): Void;
public function getConstantLocation(name: String): ConstantLocation;
public function getTextureUnit(name: String): TextureUnit;
Expand Down
5 changes: 5 additions & 0 deletions Sources/kha/graphics4/TesselationControlShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import kha.Blob;
#if cpp
extern class TesselationControlShader {
public function new(source: Blob);
public function delete();
}
#else
class TesselationControlShader {
public function new(source: Blob) {

}

public function delete(): Void {

}
}
#end
5 changes: 5 additions & 0 deletions Sources/kha/graphics4/TesselationEvaluationShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import kha.Blob;
#if cpp
extern class TesselationEvaluationShader {
public function new(source: Blob);
public function delete();
}
#else
class TesselationEvaluationShader {
public function new(source: Blob) {

}

public function delete(): Void {

}
}
#end
1 change: 1 addition & 0 deletions Sources/kha/graphics4/VertexBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kha.arrays.Float32Array;

extern class VertexBuffer {
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, instanceDataStepRate: Int = 0, canRead: Bool = false);
public function delete(): Void;
public function lock(?start: Int, ?count: Int): Float32Array;
public function unlock(): Void;
public function count(): Int;
Expand Down
1 change: 1 addition & 0 deletions Sources/kha/graphics4/VertexShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import kha.Blob;

extern class VertexShader {
public function new(source: Blob);
public function delete(): Void;
}

0 comments on commit 9da807b

Please sign in to comment.