Skip to content

Commit

Permalink
all downhill from here
Browse files Browse the repository at this point in the history
  • Loading branch information
liu7d7 committed Nov 20, 2022
0 parents commit cf7422c
Show file tree
Hide file tree
Showing 41 changed files with 2,511 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
13 changes: 13 additions & 0 deletions .idea/.idea.shdr/.idea/.gitignore

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

7 changes: 7 additions & 0 deletions .idea/.idea.shdr/.idea/discord.xml

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

4 changes: 4 additions & 0 deletions .idea/.idea.shdr/.idea/encodings.xml

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

8 changes: 8 additions & 0 deletions .idea/.idea.shdr/.idea/indexLayout.xml

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

2 changes: 2 additions & 0 deletions before.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xcopy "C:\Users\richard may clarkson\RiderProjects\shdr\shdr\Resource" "C:\Users\richard may clarkson\RiderProjects\shdr\shdr\bin\Debug\net6.0\Resource" /E /H /C /R /Q /Y
xcopy "C:\Users\richard may clarkson\RiderProjects\shdr\shdr\Resource" "C:\Users\richard may clarkson\RiderProjects\shdr\shdr\bin\Release\net6.0\Resource" /E /H /C /R /Q /Y
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
16 changes: 16 additions & 0 deletions shdr.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shdr", "shdr\shdr.csproj", "{5F7BB6FD-5D0B-4E3A-8D87-295F9802F734}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F7BB6FD-5D0B-4E3A-8D87-295F9802F734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F7BB6FD-5D0B-4E3A-8D87-295F9802F734}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F7BB6FD-5D0B-4E3A-8D87-295F9802F734}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F7BB6FD-5D0B-4E3A-8D87-295F9802F734}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions shdr.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="__" Suffix="" Style="aa_bb" /&gt;</s:String>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Users\richard may clarkson\RiderProjects\shdr\shdr\bin\Debug\net6.0\NAudio.Core.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
136 changes: 136 additions & 0 deletions shdr/Engine/Fbo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using OpenTK.Graphics.OpenGL4;

namespace shdr.Engine
{
public class __fbo
{
private static int _active;
private static readonly Dictionary<int, __fbo> _frames = new();
private readonly bool _useDepth;
private int _colorAttachment;
private int _depthAttachment;
public int handle;
private int _height;
private int _width;

public __fbo(int width, int height)
{
_width = width;
_height = height;
_useDepth = false;
handle = -1;
init();
_frames[handle] = this;
}

public __fbo(int width, int height, bool useDepth)
{
_width = width;
_height = height;
_useDepth = useDepth;
handle = -1;
init();
_frames[handle] = this;
}

private void dispose()
{
GL.DeleteFramebuffer(handle);
GL.DeleteTexture(_colorAttachment);
if (_useDepth) GL.DeleteTexture(_depthAttachment);
}

private void init()
{
if (handle != -1) dispose();

handle = GL.GenFramebuffer();
bind();
_colorAttachment = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, _colorAttachment);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
(int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
(int)TextureWrapMode.ClampToBorder);
GL.TexStorage2D(TextureTarget2d.Texture2D, 1, SizedInternalFormat.Rgba8, _width, _height);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0,
TextureTarget.Texture2D, _colorAttachment, 0);
if (_useDepth)
{
_depthAttachment = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, _depthAttachment);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
(int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
(int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureCompareMode,
(int)TextureCompareMode.None);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
(int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
(int)TextureWrapMode.ClampToEdge);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, _width, _height, 0,
PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment,
TextureTarget.Texture2D, _depthAttachment, 0);
}

FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (status != FramebufferErrorCode.FramebufferComplete)
throw new Exception(
$"Incomplete Framebuffer! {status} should be {FramebufferErrorCode.FramebufferComplete}");

unbind();
}

private void _resize(int width, int height)
{
_width = width;
_height = height;
init();
}

public static void resize(int width, int height)
{
foreach (KeyValuePair<int, __fbo> frame in _frames) frame.Value._resize(width, height);
}

public void bind_color(TextureUnit unit)
{
GL.ActiveTexture(unit);
GL.BindTexture(TextureTarget.Texture2D, _colorAttachment);
}

public int bind_depth(TextureUnit unit)
{
if (!_useDepth) throw new Exception("Trying to bind depth texture of a framebuffer without depth!");
GL.ActiveTexture(unit);
GL.BindTexture(TextureTarget.Texture2D, _depthAttachment);
return _depthAttachment;
}

public void bind()
{
if (handle == _active) return;
GL.BindFramebuffer(FramebufferTarget.Framebuffer, handle);
_active = handle;
}

public void blit(int handle = 0)
{
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, this.handle);
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, handle);
GL.BlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height, ClearBufferMask.ColorBufferBit,
BlitFramebufferFilter.Nearest);
unbind();
}

public static void unbind()
{
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
_active = 0;
}
}
}
Loading

0 comments on commit cf7422c

Please sign in to comment.