-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from Jakub-Krakowiak/feature/rgl-terrain
Added terrain heightmap and trees to RGL
- Loading branch information
Showing
8 changed files
with
627 additions
and
273 deletions.
There are no files selected for viewing
401 changes: 320 additions & 81 deletions
401
Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLMeshObject.cs
Large diffs are not rendered by default.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLMeshSharingManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace RGLUnityPlugin | ||
{ | ||
public class RGLMeshSharingManager | ||
{ | ||
private static Dictionary<int, RGLMesh> sharedMeshes = new Dictionary<int, RGLMesh>(); // <Identifier, RGLMesh> | ||
private static Dictionary<int, int> sharedMeshesUsageCount = new Dictionary<int, int>(); // <RGLMesh Identifier, count> | ||
|
||
public static RGLMesh RegisterRGLMeshInstance(Mesh unityMesh) | ||
{ | ||
var meshId = unityMesh.GetInstanceID(); | ||
if (!sharedMeshes.ContainsKey(meshId)) | ||
{ | ||
var rglMesh = new RGLMesh(meshId, unityMesh); | ||
sharedMeshes.Add(meshId, rglMesh); | ||
sharedMeshesUsageCount.Add(meshId, 1); | ||
} | ||
else | ||
{ | ||
sharedMeshesUsageCount[meshId]++; | ||
} | ||
|
||
return sharedMeshes[meshId]; | ||
} | ||
|
||
public static void UnregisterRGLMeshInstance(RGLMesh rglMesh) | ||
{ | ||
var meshId = rglMesh.Identifier; | ||
if (sharedMeshes[meshId] is null) | ||
{ | ||
Debug.LogWarning($"Trying to unregister absent in RGLMeshSharingManager mesh of id: {meshId}, ignoring request"); | ||
return; | ||
} | ||
|
||
sharedMeshesUsageCount[meshId]--; | ||
if (sharedMeshesUsageCount[meshId] == 0) | ||
{ | ||
sharedMeshes[meshId].DestroyInRGL(); | ||
sharedMeshes.Remove(meshId); | ||
sharedMeshesUsageCount.Remove(meshId); | ||
} | ||
} | ||
|
||
public static void Clear() | ||
{ | ||
foreach (var mesh in sharedMeshes) | ||
{ | ||
mesh.Value.DestroyInRGL(); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLMeshSharingManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLTextureManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace RGLUnityPlugin | ||
{ | ||
public class RGLTextureSharingManager | ||
{ | ||
private static Dictionary<int, RGLTexture> sharedTextures = new Dictionary<int, RGLTexture>(); // <Identifier, RGLTexture> | ||
private static Dictionary<int, int> sharedTexturesUsageCount = new Dictionary<int, int>(); // <RGLTexture Identifier, count> | ||
|
||
public static RGLTexture RegisterRGLTextureInstance(Texture2D texture) | ||
{ | ||
var textureID = texture.GetInstanceID(); | ||
|
||
if(!sharedTextures.ContainsKey(textureID)) | ||
{ | ||
var rglTextureToAdd = new RGLTexture(texture, textureID); | ||
sharedTextures.Add(textureID, rglTextureToAdd); | ||
sharedTexturesUsageCount.Add(textureID, 0); | ||
} | ||
|
||
sharedTexturesUsageCount[textureID] += 1; | ||
|
||
return sharedTextures[textureID]; | ||
} | ||
|
||
public static void UnregisterRGLTextureInstance(RGLTexture rglTexture) | ||
{ | ||
var textureId = rglTexture.Identifier; | ||
if (sharedTextures[textureId] is null) | ||
{ | ||
Debug.LogWarning($"Trying to unregister absent in RGLTextureSharingManager texture of id: {textureId}, ignoring request"); | ||
return; | ||
} | ||
|
||
sharedTexturesUsageCount[textureId]--; | ||
if (sharedTexturesUsageCount[textureId] == 0) | ||
{ | ||
sharedTextures[textureId].DestroyInRGL(); | ||
sharedTextures.Remove(textureId); | ||
sharedTextures.Remove(textureId); | ||
} | ||
} | ||
|
||
public static void Clear() | ||
{ | ||
foreach (var mesh in sharedTextures) | ||
{ | ||
mesh.Value.DestroyInRGL(); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLTextureManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.