Skip to content

Commit

Permalink
Merge pull request #173 from Jakub-Krakowiak/feature/rgl-terrain
Browse files Browse the repository at this point in the history
Added terrain heightmap and trees to RGL
  • Loading branch information
mackierx111 authored Sep 7, 2023
2 parents 0401631 + 21bc4ce commit 41872f9
Show file tree
Hide file tree
Showing 8 changed files with 627 additions and 273 deletions.
401 changes: 320 additions & 81 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLMeshObject.cs

Large diffs are not rendered by default.

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();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41872f9

Please sign in to comment.