Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hl] Add hl.Bytes.fromNativeArray #11745

Conversation

yuxiaomao
Copy link
Contributor

Trying to address heap issues in #11568
It compile now but is still getting runtime access violation in game.

Here is heaps patch

diff --git a/h3d/impl/GlDriver.hx b/h3d/impl/GlDriver.hx
index 697672fc..3223e975 100644
--- a/h3d/impl/GlDriver.hx
+++ b/h3d/impl/GlDriver.hx
@@ -596,7 +596,8 @@ class GlDriver extends Driver {
 		case Globals:
 			if( s.globals != null ) {
 				#if hl
-				gl.uniform4fv(s.globals, streamData(hl.Bytes.getArray(buf.globals.toData()), 0, s.shader.globalsSize * 16), 0, s.shader.globalsSize * 4);
+				var bytes = #if (haxe_ver < 5.0) hl.Bytes.getArray(buf.globals.toData()) #else hl.Bytes.getNativeArray(buf.globals.toData()) #end;
+				gl.uniform4fv(s.globals, streamData(bytes, 0, s.shader.globalsSize * 16), 0, s.shader.globalsSize * 4);
 				#else
 				var a = buf.globals.subarray(0, s.shader.globalsSize * 4);
 				gl.uniform4fv(s.globals, a);
@@ -605,7 +606,8 @@ class GlDriver extends Driver {
 		case Params:
 			if( s.params != null ) {
 				#if hl
-				gl.uniform4fv(s.params, streamData(hl.Bytes.getArray(buf.params.toData()), 0, s.shader.paramsSize * 16), 0, s.shader.paramsSize * 4);
+				var bytes = #if (haxe_ver < 5.0) hl.Bytes.getArray(buf.params.toData()) #else hl.Bytes.getNativeArray(buf.params.toData()) #end;
+				gl.uniform4fv(s.params, streamData(bytes, 0, s.shader.paramsSize * 16), 0, s.shader.paramsSize * 4);
 				#else
 				var a = buf.params.subarray(0, s.shader.paramsSize * 4);
 				gl.uniform4fv(s.params, a);
diff --git a/h3d/impl/RenderContext.hx b/h3d/impl/RenderContext.hx
index a8751e06..50c92873 100644
--- a/h3d/impl/RenderContext.hx
+++ b/h3d/impl/RenderContext.hx
@@ -178,8 +178,10 @@ class RenderContext {
 	}
 
 	inline function getPtr( data : h3d.shader.Buffers.ShaderBufferData ) {
-		#if hl
+		#if (hl && haxe_ver < 5.0)
 		return (hl.Bytes.getArray((cast data : Array<Single>)) : hl.BytesAccess<hl.F32>);
+		#elseif hl
+		return (hl.Bytes.getNativeArray(data.toData()) : hl.BytesAccess<hl.F32>);
 		#else
 		return data;
 		#end
diff --git a/hxd/fmt/hmd/Library.hx b/hxd/fmt/hmd/Library.hx
index 80148527..14293ab8 100644
--- a/hxd/fmt/hmd/Library.hx
+++ b/hxd/fmt/hmd/Library.hx
@@ -257,7 +257,7 @@ class Library {
 				}
 				buf.indexes[i] = rid - 1;
 			}
-			#if neko
+			#if (neko || (hl && haxe_ver >= 5.0 ))
 			buf.vertexes = haxe.ds.Vector.fromArrayCopy(vertexes.getNative());
 			#else
 			buf.vertexes = haxe.ds.Vector.fromData(vertexes.getNative());

@yuxiaomao
Copy link
Contributor Author

Got some tips from Nicolas and it seems that hl.NativeArray -> hl.Bytes should be implemented at VM side. Let me check that later.

@yuxiaomao yuxiaomao closed this Aug 2, 2024
@yuxiaomao yuxiaomao deleted the dev-hl-vectornative branch August 2, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant