Skip to content

Commit e4bf4ed

Browse files
author
LoneWandererProductions
committed
Sync RenderEngine which is a bit improved now
1 parent ac042be commit e4bf4ed

14 files changed

Lines changed: 313 additions & 77 deletions

‎RenderEngine/Enums/PostProcessFilter.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public enum PostProcessFilter
3838
/// </summary>
3939
Grayscale = 4
4040
}
41-
}
41+
}

‎RenderEngine/GLResourceManager.cs‎

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,65 @@ public sealed class GlResourceManager : IDisposable
115115
{ 10018, ("Steel", "Directional brushed steel metal surface with specular grit.") },
116116
{ 10019, ("Latex", "Glossy latex surface with steep specular falloff.") },
117117
{ 10020, ("Leather", "Pebbled organic skin pores and warped wrinkles.") },
118-
{ 10021, ("PolishedSteel", "High-gloss chrome reflective steel surface.") }
118+
{ 10021, ("PolishedSteel", "High-gloss chrome reflective steel surface.") },
119+
{ 10022, ("LeafCloud", "Volumetric leaf cloud texture for bushes and tree canopies.") },
120+
{
121+
10023,
122+
("VolumetricLeafCloud",
123+
"Smooth volumetric leaf cloud texture with rounded leaf puffs and distinct canopy gaps.")
124+
},
125+
{ 10024, ("TerrainGrass", "Smooth low-noise terrain grass texture with macro color transitions.") },
126+
{ 10025, ("TerrainDirt", "Soft muted terrain dirt texture with smooth soil transitions.") },
127+
{
128+
10026,
129+
("MountainRock", "Mountain rock texture with macro height contours and directional slope shading.")
130+
},
131+
{
132+
10027,
133+
("DungeonSandstone", "Layered dungeon sandstone texture with domain-warped sedimentary strata.")
134+
},
135+
{ 10028, ("DungeonSandstoneFlat", "Flat soft-blended dungeon sandstone terrain texture.") },
136+
{ 10029, ("RawIron", "Raw cast iron texture with fine surface pitting and micro-grit.") },
137+
{ 10030, ("WroughtIron", "Wrought iron texture with subtle hammer marks and forged cellular facets.") },
138+
{ 10031, ("RustedIron", "Rusted corroded iron texture with domain-warped oxidation layer.") },
139+
{ 10032, ("DesertSand", "Desert sand texture with gentle directional wind ripples.") },
140+
{ 10033, ("DesertSandFlat", "Flat soft-blended desert sand terrain texture for beds and background areas.") }
119141
};
142+
120143
// --- PROCEDURAL LAZY LOADING INTEGRATION PASS ---
121144

145+
/// <summary>
146+
/// Initializes a new instance of the <see cref="GlResourceManager"/> class.
147+
/// </summary>
148+
public GlResourceManager()
149+
{
150+
_lazyNoiseGen = new NoiseGenerator(256, 256);
151+
}
152+
153+
/// <summary>
154+
/// Sets the base resolution for dynamic procedural texture baking.
155+
/// </summary>
156+
/// <param name="width">Pixel width (e.g., 256, 512, 1024).</param>
157+
/// <param name="height">Pixel height (e.g., 256, 512, 1024).</param>
158+
/// <param name="clearExistingCache">If set to <c>true</c>, purges existing GL handles so textures re-bake at the new resolution.</param>
159+
public void SetProceduralResolution(int width, int height, bool clearExistingCache = false)
160+
{
161+
_procWidth = width;
162+
_procHeight = height;
163+
_lazyNoiseGen = new NoiseGenerator(width, height);
164+
165+
if (clearExistingCache)
166+
{
167+
foreach (var handle in _bakedProceduralCache.Values)
168+
{
169+
GL.DeleteTexture(handle);
170+
_allTrackedHandles.Remove(handle);
171+
}
172+
173+
_bakedProceduralCache.Clear();
174+
}
175+
}
176+
122177
/// <summary>
123178
/// Configures the base resolution and noise algorithm context used for dynamic on-demand baking.
124179
/// </summary>
@@ -200,7 +255,7 @@ private int LazyBakeTexture(int id)
200255
10003 => TextureMathEngine.GenerateWood(_procWidth, _procHeight, _lazyNoiseGen),
201256
10004 => TextureMathEngine.GenerateWave(_procWidth, _procHeight, _lazyNoiseGen),
202257
10005 => TextureMathEngine.GenerateCrosshatch(_procWidth, _procHeight, lineSpacing: 32,
203-
lineThickness: 2),
258+
lineThickness: 2, bgR: 245, bgG: 238, bgB: 220, bgA: 255),
204259
10006 => TextureMathEngine.GenerateConcrete(_procWidth, _procHeight, _lazyNoiseGen),
205260
10007 => TextureMathEngine.GenerateCanvas(_procWidth, _procHeight, lineSpacing: 8, lineThickness: 1),
206261
10008 => TextureFactory.GenerateTreeBark(_procWidth, _procHeight, _lazyNoiseGen),
@@ -217,6 +272,18 @@ private int LazyBakeTexture(int id)
217272
10019 => TextureFactory.GenerateLatex(_procWidth, _procHeight, _lazyNoiseGen),
218273
10020 => TextureFactory.GenerateLeather(_procWidth, _procHeight, _lazyNoiseGen),
219274
10021 => TextureFactory.GeneratePolishedSteel(_procWidth, _procHeight, _lazyNoiseGen),
275+
10022 => TextureFactory.GenerateLeafCloud(_procWidth, _procHeight, _lazyNoiseGen),
276+
10023 => TextureFactory.GenerateVolumetricLeafCloud(_procWidth, _procHeight, _lazyNoiseGen),
277+
10024 => TextureFactory.GenerateTerrainGrass(_procWidth, _procHeight, _lazyNoiseGen),
278+
10025 => TextureFactory.GenerateTerrainDirt(_procWidth, _procHeight, _lazyNoiseGen),
279+
10026 => TextureFactory.GenerateMountainRock(_procWidth, _procHeight, _lazyNoiseGen),
280+
10027 => TextureFactory.GenerateDungeonSandstone(_procWidth, _procHeight, _lazyNoiseGen),
281+
10028 => TextureFactory.GenerateDungeonSandstoneFlat(_procWidth, _procHeight, _lazyNoiseGen),
282+
10029 => TextureFactory.GenerateRawIron(_procWidth, _procHeight, _lazyNoiseGen),
283+
10030 => TextureFactory.GenerateWroughtIron(_procWidth, _procHeight, _lazyNoiseGen),
284+
10031 => TextureFactory.GenerateRustedIron(_procWidth, _procHeight, _lazyNoiseGen),
285+
10032 => TextureFactory.GenerateDesertSand(_procWidth, _procHeight, _lazyNoiseGen),
286+
10033 => TextureFactory.GenerateDesertSandFlat(_procWidth, _procHeight, _lazyNoiseGen),
220287
_ => null
221288
};
222289

@@ -467,24 +534,24 @@ public int GetShaderProgram(ShaderTypeApp appType)
467534
vertexSrc = ShaderResource.TexturedQuad2DVertexShader;
468535
fragmentSrc = ShaderResource.TexturedQuad2DFragmentShader;
469536
break;
470-
case ShaderTypeApp.PhongLighting: // UNUSED for now
537+
case ShaderTypeApp.PhongLighting:
471538
vertexSrc = ShaderResource.PhongLightingVertexShader;
472539
fragmentSrc = ShaderResource.PhongLightingFragmentShader;
473540
break;
474-
case ShaderTypeApp.Instancing: // UNUSED for now
541+
case ShaderTypeApp.Instancing:
475542
vertexSrc = ShaderResource.InstancingVertexShader;
476543
fragmentSrc = ShaderResource.InstancingFragmentShader;
477544
break;
478545
case ShaderTypeApp.PostProcessing: // Now active for Painterly & Stylized Filters
479546
vertexSrc = ShaderResource.PostProcessingVertexShader;
480547
fragmentSrc = ShaderResource.PostProcessingFragmentShader;
481548
break;
482-
case ShaderTypeApp.WaterRipple: // UNUSED for now
549+
case ShaderTypeApp.WaterRipple:
483550
vertexSrc = ShaderResource.WaterRippleVertexShader;
484551
fragmentSrc = ShaderResource.WaterRippleFragmentShader;
485552
break;
486553

487-
case ShaderTypeApp.VolumetricFog: // UNUSED for now
554+
case ShaderTypeApp.VolumetricFog:
488555
vertexSrc = ShaderResource.VolumetricFogVertexShader;
489556
fragmentSrc = ShaderResource.VolumetricFogFragmentShader;
490557
break;

‎RenderEngine/Geometry2DBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@ internal static (float x, float y, int r, int g, int b, int a)[] BuildCircleOutl
197197
return pts;
198198
}
199199
}
200-
}
200+
}

‎RenderEngine/GpuMesh.cs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ public void UploadSolid(IntPtr dataPointer, int floatCount, bool isDynamic = fal
157157
GL.BindVertexArray(0);
158158
}
159159

160+
/// <summary>
161+
/// Resets this instance.
162+
/// </summary>
163+
public void Reset()
164+
{
165+
SolidVertexCount = 0;
166+
Ranges.Clear();
167+
}
168+
160169
/// <inheritdoc/>
161170
public void Dispose()
162171
{
@@ -189,4 +198,4 @@ public void Dispose()
189198
Ranges.Clear();
190199
}
191200
}
192-
}
201+
}

‎RenderEngine/GpuMeshPool.cs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: RenderEngine
4+
* FILE: GpuMeshPool.cs
5+
* PURPOSE: Pools persistent GpuMesh instances to eliminate GPU buffer allocation stalls.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using System;
10+
using System.Collections.Generic;
11+
12+
namespace RenderEngine
13+
{
14+
/// <summary>
15+
/// Manages reusable <see cref="GpuMesh"/> instances to avoid driver VAO/VBO handle churn.
16+
/// </summary>
17+
public sealed class GpuMeshPool : IDisposable
18+
{
19+
private readonly Stack<GpuMesh> _pool = new();
20+
21+
/// <summary>
22+
/// Rents a recycled mesh from the pool, or creates a new one if empty.
23+
/// </summary>
24+
public GpuMesh Rent()
25+
{
26+
if (_pool.Count > 0)
27+
{
28+
var mesh = _pool.Pop();
29+
mesh.Reset();
30+
return mesh;
31+
}
32+
33+
return new GpuMesh();
34+
}
35+
36+
/// <summary>
37+
/// Returns a mesh to the pool for reuse without disposing its GPU handles.
38+
/// </summary>
39+
public void Return(GpuMesh? mesh)
40+
{
41+
if (mesh == null) return;
42+
mesh.Reset();
43+
_pool.Push(mesh);
44+
}
45+
46+
/// <summary>
47+
/// Disposes all pooled GPU resources.
48+
/// </summary>
49+
public void Dispose()
50+
{
51+
while (_pool.Count > 0)
52+
{
53+
_pool.Pop().Dispose();
54+
}
55+
}
56+
}
57+
}

‎RenderEngine/OpenTKHelper.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,4 @@ internal static bool IsOpenGlCompatible(int requiredMajor = 4, int requiredMinor
299299
return _glVersion >= new Version(requiredMajor, requiredMinor);
300300
}
301301
}
302-
}
302+
}

‎RenderEngine/RenderBatch.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,4 @@ public void AddHostAction(Action action)
268268
HostActions.Add(action);
269269
}
270270
}
271-
}
271+
}

‎RenderEngine/RenderEngine.csproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<ProjectReference Include="..\Extended.Unmanaged\Extended.Unmanaged.csproj" />
2727
<ProjectReference Include="..\Imaging.Objects\Imaging.Objects.csproj" />
2828
<ProjectReference Include="..\Imaging.Texture\Imaging.Texture.csproj" />
29-
<ProjectReference Include="..\Mathematics\Mathematics.csproj" />
3029
</ItemGroup>
3130

3231
</Project>

‎RenderEngine/RenderResource.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ internal static class RenderResource
3838
/// </summary>
3939
internal const string ErrorLayerSizeMismatch = "Layer size mismatch.";
4040
}
41-
}
41+
}

‎RenderEngine/ShaderResources.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,4 @@ void main() {
571571
FragColor = vec4(uFogColor * fogFactor, 1.0);
572572
}";
573573
}
574-
}
574+
}

0 commit comments

Comments
 (0)