mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Use static D3D11 device and context
This commit is contained in:
@@ -74,15 +74,12 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class BlendState : RefCounter
|
||||
{
|
||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected BlendStateDescription _desc;
|
||||
|
||||
public BlendStateDescription Description => _desc;
|
||||
|
||||
public this(GraphicsContext context, BlendStateDescription desc)
|
||||
public this(BlendStateDescription desc)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
_desc = desc;
|
||||
|
||||
PlatformCreateBlendState();
|
||||
|
||||
@@ -83,24 +83,17 @@ namespace GlitchyEngine.Renderer
|
||||
/// Represents a buffer containing binary data on the GPU.
|
||||
public class Buffer : RefCounter
|
||||
{
|
||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected BufferDescription _description;
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
|
||||
public BufferDescription Description => _description;
|
||||
|
||||
protected this(GraphicsContext context)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
|
||||
protected this() { }
|
||||
|
||||
/**
|
||||
* Creates a new instance of a Buffer.
|
||||
* @param description The buffer description.
|
||||
*/
|
||||
public this(GraphicsContext context, BufferDescription description) : this(context)
|
||||
public this(BufferDescription description)
|
||||
{
|
||||
_description = description;
|
||||
}
|
||||
@@ -162,10 +155,9 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
/**
|
||||
* Creates a new instance of a Buffer<T>
|
||||
* @param context The graphics context.
|
||||
* @param description Describes the Buffer. Note: description.Size is ignored, as it will always be sizeof(T).
|
||||
*/
|
||||
public this(GraphicsContext context, BufferDescription description) : base(context)
|
||||
public this(BufferDescription description)
|
||||
{
|
||||
_description = description;
|
||||
_description.Size = (uint32)sizeof(T);
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public BufferVariableCollection Variables => _variables;
|
||||
|
||||
protected this(GraphicsContext context) : base(context) {}
|
||||
protected this() {}
|
||||
|
||||
protected internal void AddVariable(BufferVariable ownVariable)
|
||||
{
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public static bool DrawEntityTransforms = true;
|
||||
|
||||
public static void Init(GraphicsContext context)
|
||||
public static void Init()
|
||||
{
|
||||
CreateCoordinateCross(context);
|
||||
CreateCoordinateCross();
|
||||
}
|
||||
|
||||
private static void CreateCoordinateCross(GraphicsContext context)
|
||||
private static void CreateCoordinateCross()
|
||||
{
|
||||
CoordinateCross = new GeometryBinding(context);
|
||||
CoordinateCross = new GeometryBinding();
|
||||
//CoordinateCross.PrimitiveTopology
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ namespace GlitchyEngine.Renderer
|
||||
// TODO: add all features.
|
||||
public class DepthStencilTarget : RefCounter
|
||||
{
|
||||
protected internal GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected uint32 _width, _height;
|
||||
protected DepthStencilFormat _format;
|
||||
|
||||
@@ -23,11 +21,10 @@ namespace GlitchyEngine.Renderer
|
||||
public uint32 Height => _height;
|
||||
public DepthStencilFormat Format => _format;
|
||||
|
||||
public this(GraphicsContext context, uint32 width, uint32 height, DepthStencilFormat format = .D32_Float)
|
||||
public this(uint32 width, uint32 height, DepthStencilFormat format = .D32_Float)
|
||||
{
|
||||
Log.EngineLogger.Assert(format != .None, "DepthStencilFormat None is only valid for RenderTarget");
|
||||
|
||||
_context = context..AddRef();
|
||||
_width = width;
|
||||
_height = height;
|
||||
_format = format;
|
||||
@@ -36,9 +33,5 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
protected extern void PlatformCreate();
|
||||
|
||||
public extern void Bind();
|
||||
|
||||
public extern void Clear(float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,12 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
public class EffectLibrary
|
||||
{
|
||||
private GraphicsContext _context ~ _?.ReleaseRef();
|
||||
private Dictionary<String, Effect> _effects = new .() ~ delete _;
|
||||
|
||||
private List<String> _ownedStrings = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
public this(GraphicsContext context)
|
||||
public this()
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
@@ -63,7 +61,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library.");
|
||||
|
||||
Effect effect = new Effect(_context, filepath, name);
|
||||
Effect effect = new Effect(filepath, name);
|
||||
Add(effect);
|
||||
|
||||
return effect;
|
||||
@@ -92,7 +90,6 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class Effect : RefCounter
|
||||
{
|
||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
||||
internal VertexShader _vs ~ _?.ReleaseRef();
|
||||
internal PixelShader _ps ~ _?.ReleaseRef();
|
||||
protected String _name ~ delete _;
|
||||
@@ -104,8 +101,6 @@ namespace GlitchyEngine.Renderer
|
||||
typealias TextureEntry = (Texture Texture, ShaderTextureCollection.ResourceEntry* VsSlot, ShaderTextureCollection.ResourceEntry* PsSlot);
|
||||
Dictionary<String, TextureEntry> _textures ~ delete _;
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
|
||||
public Dictionary<String, TextureEntry> Textures => _textures;
|
||||
|
||||
public VertexShader VertexShader
|
||||
@@ -140,9 +135,8 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, String filename, String vsEntry, String psEntry, String shaderName = null)
|
||||
public this(String filename, String vsEntry, String psEntry, String shaderName = null)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
CompileFromFile(filename, vsEntry, psEntry);
|
||||
|
||||
if(shaderName == null)
|
||||
@@ -156,10 +150,8 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, String filename, String shaderName = null)
|
||||
public this(String filename, String shaderName = null)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
|
||||
String fileContent = scope String();
|
||||
String vsName = scope String();
|
||||
String psName = scope String();
|
||||
@@ -243,10 +235,10 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
private void CompileFromFile(String filename, String vsEntry, String psEntry)
|
||||
{
|
||||
let vs = Shader.FromFile!<VertexShader>(_context, filename, vsEntry);
|
||||
let vs = Shader.FromFile!<VertexShader>(filename, vsEntry);
|
||||
VertexShader = vs;
|
||||
vs.ReleaseRef();
|
||||
let ps = Shader.FromFile!<PixelShader>(_context, filename, psEntry);
|
||||
let ps = Shader.FromFile!<PixelShader>(filename, psEntry);
|
||||
PixelShader = ps;
|
||||
ps.ReleaseRef();
|
||||
}
|
||||
@@ -254,10 +246,10 @@ namespace GlitchyEngine.Renderer
|
||||
private void Compile(String fileContent, String vsEntry, String psEntry)
|
||||
{
|
||||
// TODO: vsEntry and psEntry could be empty (which is a valid case.)
|
||||
let vs = new VertexShader(_context, fileContent, vsEntry);
|
||||
let vs = new VertexShader(fileContent, vsEntry);
|
||||
VertexShader = vs;
|
||||
vs.ReleaseRef();
|
||||
let ps = new PixelShader(_context, fileContent, psEntry);
|
||||
let ps = new PixelShader(fileContent, psEntry);
|
||||
PixelShader = ps;
|
||||
ps.ReleaseRef();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
public class GeometryBinding : RefCounter
|
||||
{
|
||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
internal List<VertexBufferBinding> _vertexBuffers = new .() ~ delete _;
|
||||
internal IndexBuffer _indexBuffer ~ _?.ReleaseRef();
|
||||
internal VertexLayout _vertexLayout ~ _?.ReleaseRef();
|
||||
@@ -19,9 +17,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public bool IsIndexed => _indexBuffer != null;
|
||||
|
||||
public this(GraphicsContext context)
|
||||
public this()
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
@@ -120,8 +117,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected extern void PlatformSetIndexBuffer(IndexBuffer indexBuffer);
|
||||
|
||||
public extern void Bind(GraphicsContext context = null);
|
||||
public extern void Bind();
|
||||
|
||||
public extern void Unbind(GraphicsContext context = null);
|
||||
public extern void Unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ namespace GlitchyEngine.Renderer
|
||||
private RasterizerState _currentRasterizerState;
|
||||
|
||||
public extern SwapChain SwapChain {get;}
|
||||
|
||||
|
||||
protected extern void PlatformConstruct();
|
||||
|
||||
/**
|
||||
* The maximum number of simultaneous rendertargets supported.
|
||||
*/
|
||||
@@ -17,6 +19,13 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public extern void Init();
|
||||
|
||||
/** @brief Sets a depthtarget.
|
||||
* @BindRenderTargets has to be called in order to bind the rendertargets.
|
||||
* @param renderTarget The render target to set. If null, the backbuffer will be set.
|
||||
* @param slot The slot to which the rendertarget will be bound. If 0 the depth buffer of the current render target will be set. If it has no depthbuffer the current will be unset.
|
||||
*/
|
||||
public extern void SetDepthStencilTarget(DepthStencilTarget target);
|
||||
|
||||
/** @brief Sets a rendertarget to the given slot.
|
||||
* @BindRenderTargets has to be called in order to bind the rendertargets.
|
||||
* @param renderTarget The render target to set. If null, the backbuffer will be set.
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace GlitchyEngine.Renderer
|
||||
public uint32 IndexCount => _indexCount;
|
||||
public IndexFormat Format => _format;
|
||||
|
||||
public this(GraphicsContext context, uint32 indexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None, IndexFormat indexFormat = .Index16Bit) : base(context)
|
||||
public this(uint32 indexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None, IndexFormat indexFormat = .Index16Bit)
|
||||
{
|
||||
_indexCount = indexCount;
|
||||
_format = indexFormat;
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace GlitchyEngine.Renderer
|
||||
public class PixelShader : Shader
|
||||
{
|
||||
[AllowAppend]
|
||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(context, source, entryPoint, macros) { }
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(source, entryPoint, macros) { }
|
||||
|
||||
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
||||
}
|
||||
|
||||
@@ -54,17 +54,10 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class RasterizerState : RefCounter
|
||||
{
|
||||
internal GraphicsContext _context ~ _?.ReleaseRef();
|
||||
private RasterizerStateDescription _description;
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
public RasterizerStateDescription Description => _description;
|
||||
|
||||
protected this(GraphicsContext context)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
|
||||
public extern this(GraphicsContext context, RasterizerStateDescription description);
|
||||
public extern this(RasterizerStateDescription description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class RenderTarget2D : RefCounter
|
||||
{
|
||||
internal GraphicsContext _context;
|
||||
|
||||
private RenderTarget2DDescription _description;
|
||||
|
||||
public RenderTarget2DDescription Description => _description;
|
||||
@@ -63,9 +61,8 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, RenderTarget2DDescription description)
|
||||
public this(RenderTarget2DDescription description)
|
||||
{
|
||||
_context = context;
|
||||
_description = description;
|
||||
|
||||
ApplyChanges();
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
_context = context..AddRef();
|
||||
/*
|
||||
_sceneConstants = new Buffer<SceneConstants>(_context, .(0, .Constant, .Dynamic, .Write));
|
||||
_sceneConstants = new Buffer<SceneConstants>(.(0, .Constant, .Dynamic, .Write));
|
||||
_sceneConstants.Update();
|
||||
|
||||
_objectConstants = new Buffer<ObjectConstants>(_context, .(0, .Constant, .Dynamic, .Write));
|
||||
_objectConstants = new Buffer<ObjectConstants>(.(0, .Constant, .Dynamic, .Write));
|
||||
_objectConstants.Update();
|
||||
*/
|
||||
|
||||
@@ -53,23 +53,23 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
LineEffect = effectLibrary.Load("content\\Shaders\\lineShader.hlsl");
|
||||
|
||||
LineGeometry = new GeometryBinding(_context);
|
||||
LineGeometry = new GeometryBinding();
|
||||
LineGeometry.SetPrimitiveTopology(.LineList);
|
||||
|
||||
Vector4[2] vertices = .(.Zero, .Zero);
|
||||
LineVertices = new VertexBuffer(_context, sizeof(Vector4), 2, .Dynamic, .Write);
|
||||
LineVertices = new VertexBuffer(sizeof(Vector4), 2, .Dynamic, .Write);
|
||||
LineVertices.SetData<Vector4>(vertices, 0, .WriteDiscard);
|
||||
LineGeometry.SetVertexBufferSlot(LineVertices, 0);
|
||||
|
||||
uint16[2] indices = .(0, 1);
|
||||
IndexBuffer indexBuffer = new IndexBuffer(_context, 2, .Immutable);
|
||||
IndexBuffer indexBuffer = new IndexBuffer(2, .Immutable);
|
||||
indexBuffer.SetData(indices);
|
||||
LineGeometry.SetIndexBuffer(indexBuffer);
|
||||
indexBuffer.ReleaseRef();
|
||||
|
||||
VertexElement[] vertexElements = new VertexElement[1];
|
||||
vertexElements[0] = .(.R32G32B32_Float, "POSITION");
|
||||
VertexLayout layout = new VertexLayout(_context, vertexElements, true, LineEffect.VertexShader);
|
||||
VertexLayout layout = new VertexLayout(vertexElements, true, LineEffect.VertexShader);
|
||||
LineGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
||||
}
|
||||
|
||||
|
||||
@@ -107,15 +107,15 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
private static void InitEffect()
|
||||
{
|
||||
s_textureColorEffect = new Effect(Renderer._context, "content\\Shaders\\textureColor.hlsl");
|
||||
s_batchEffect = new Effect(Renderer._context, "content\\Shaders\\spritebatch.hlsl");
|
||||
s_textureColorEffect = new Effect("content\\Shaders\\textureColor.hlsl");
|
||||
s_batchEffect = new Effect("content\\Shaders\\spritebatch.hlsl");
|
||||
}
|
||||
|
||||
private static void InitGeometry()
|
||||
{
|
||||
VertexLayout layout = new VertexLayout(Renderer._context, QuadVertex.VertexElements, false, s_textureColorEffect.VertexShader);
|
||||
VertexLayout layout = new VertexLayout(QuadVertex.VertexElements, false, s_textureColorEffect.VertexShader);
|
||||
|
||||
VertexBuffer quadVertices = new VertexBuffer(Renderer._context, typeof(QuadVertex), 4, .Immutable);
|
||||
VertexBuffer quadVertices = new VertexBuffer(typeof(QuadVertex), 4, .Immutable);
|
||||
|
||||
QuadVertex[4] vertices = .(
|
||||
.(-0.5f,-0.5f, 0, 1),
|
||||
@@ -126,7 +126,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
quadVertices.SetData(vertices);
|
||||
|
||||
IndexBuffer quadIndices = new IndexBuffer(Renderer._context, 6, .Immutable);
|
||||
IndexBuffer quadIndices = new IndexBuffer(6, .Immutable);
|
||||
|
||||
uint16[6] indices = .(
|
||||
0, 1, 2,
|
||||
@@ -135,7 +135,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
quadIndices.SetData(indices);
|
||||
|
||||
s_quadGeometry = new GeometryBinding(Renderer._context);
|
||||
s_quadGeometry = new GeometryBinding();
|
||||
s_quadGeometry.SetVertexLayout(layout..ReleaseRefNoDelete());
|
||||
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
|
||||
s_quadGeometry.SetVertexBufferSlot(quadVertices, 0);
|
||||
@@ -147,7 +147,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
private static void InitInstancingGeometry()
|
||||
{
|
||||
s_instanceBuffer = new VertexBuffer(Renderer._context, typeof(BatchVertex), 1024, .Dynamic, .Write);
|
||||
s_instanceBuffer = new VertexBuffer(typeof(BatchVertex), 1024, .Dynamic, .Write);
|
||||
s_instanceBuffer.SetData(0);
|
||||
|
||||
VertexElement[] vertexElements = new .(
|
||||
@@ -162,9 +162,9 @@ namespace GlitchyEngine.Renderer
|
||||
VertexElement(.R32G32B32A32_Float, "TEXCOORD", false, 1, 1, (.)-1, .PerInstanceData, 1)
|
||||
);
|
||||
|
||||
VertexLayout batchLayout = new VertexLayout(Renderer._context, vertexElements, true, s_batchEffect.VertexShader);
|
||||
VertexLayout batchLayout = new VertexLayout(vertexElements, true, s_batchEffect.VertexShader);
|
||||
|
||||
s_batchBinding = new GeometryBinding(Renderer._context);
|
||||
s_batchBinding = new GeometryBinding();
|
||||
s_batchBinding.SetVertexLayout(batchLayout..ReleaseRefNoDelete());
|
||||
s_batchBinding.SetPrimitiveTopology(.TriangleList);
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace GlitchyEngine.Renderer
|
||||
Usage = .Immutable,
|
||||
CpuAccess = .None
|
||||
};
|
||||
s_whiteTexture = new Texture2D(Renderer._context, tex2Ddesc);
|
||||
s_whiteTexture = new Texture2D(tex2Ddesc);
|
||||
|
||||
Color color = .White;
|
||||
s_whiteTexture.SetData(&color);
|
||||
@@ -304,7 +304,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
s_currentEffect.Bind(Renderer._context);
|
||||
s_batchBinding.InstanceCount = s_setInstances;
|
||||
s_batchBinding.Bind(Renderer._context);
|
||||
s_batchBinding.Bind();
|
||||
RenderCommand.DrawIndexedInstanced(s_batchBinding);
|
||||
|
||||
s_setInstances = 0;
|
||||
@@ -389,7 +389,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
s_textureColorEffect.Bind(Renderer._context);
|
||||
|
||||
s_quadGeometry.Bind(Renderer._context);
|
||||
s_quadGeometry.Bind();
|
||||
RenderCommand.DrawIndexed(s_quadGeometry);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,8 +153,6 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public static class SamplerStateManager
|
||||
{
|
||||
static GraphicsContext _context;
|
||||
|
||||
static Dictionary<SamplerStateDescription, SamplerState> _samplers;
|
||||
|
||||
public static SamplerState PointClamp;
|
||||
@@ -164,9 +162,8 @@ namespace GlitchyEngine.Renderer
|
||||
public static SamplerState AnisotropicClamp;
|
||||
public static SamplerState AnisotropicWrap;
|
||||
|
||||
public static void Init(GraphicsContext context)
|
||||
public static void Init()
|
||||
{
|
||||
_context = context..AddRef();
|
||||
_samplers = new .();
|
||||
|
||||
// Init point samplers
|
||||
@@ -240,8 +237,6 @@ namespace GlitchyEngine.Renderer
|
||||
AnisotropicClamp.ReleaseRef();
|
||||
AnisotropicWrap.ReleaseRef();
|
||||
|
||||
_context?.ReleaseRef();
|
||||
|
||||
delete _samplers;
|
||||
_samplers = null;
|
||||
}
|
||||
@@ -261,7 +256,7 @@ namespace GlitchyEngine.Renderer
|
||||
return sampler..AddRef();
|
||||
}
|
||||
|
||||
SamplerState newState = new SamplerState(_context, desc);
|
||||
SamplerState newState = new SamplerState(desc);
|
||||
ManageSampler(newState);
|
||||
|
||||
return newState;
|
||||
@@ -288,8 +283,6 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class SamplerState : RefCounter
|
||||
{
|
||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected SamplerStateDescription _desc;
|
||||
|
||||
[Inline]
|
||||
@@ -304,12 +297,7 @@ namespace GlitchyEngine.Renderer
|
||||
[Inline]
|
||||
public SamplerStateDescription Description => _desc;
|
||||
|
||||
protected this(GraphicsContext context)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, SamplerStateDescription desc) : this(context)
|
||||
public this(SamplerStateDescription desc)
|
||||
{
|
||||
_desc = desc;
|
||||
|
||||
|
||||
@@ -21,27 +21,22 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public abstract class Shader : RefCounter
|
||||
{
|
||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected BufferCollection _buffers ~ delete _;//:append _;
|
||||
|
||||
protected ShaderTextureCollection _textures ~ delete _;
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
|
||||
public BufferCollection Buffers => _buffers;
|
||||
|
||||
public ShaderTextureCollection Textures => _textures;
|
||||
|
||||
[AllowAppend]
|
||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
{
|
||||
// Todo: append as soon as it's fixed.
|
||||
//let buffers = new BufferCollection();
|
||||
_buffers = new BufferCollection();
|
||||
_textures = new ShaderTextureCollection();
|
||||
|
||||
_context = context..AddRef();
|
||||
CompileFromSource(source, entryPoint);
|
||||
}
|
||||
|
||||
@@ -50,12 +45,12 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
}
|
||||
|
||||
public static mixin FromFile<T>(GraphicsContext context, String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
|
||||
public static mixin FromFile<T>(String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
|
||||
{
|
||||
String fileContent = new String();
|
||||
|
||||
File.ReadAllText(fileName, fileContent, true);
|
||||
T shader = new T(context, fileContent, entryPoint, macros);
|
||||
T shader = new T(fileContent, entryPoint, macros);
|
||||
|
||||
delete fileContent;
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace GlitchyEngine.Renderer.Text
|
||||
public bool IsRendered = false;
|
||||
}
|
||||
|
||||
private GraphicsContext _context ~ _.ReleaseRef();
|
||||
internal FT_Face _face ~ FreeType.Done_Face(_face);
|
||||
|
||||
private Font _fallback ~ _?.ReleaseRef();
|
||||
@@ -106,13 +105,11 @@ namespace GlitchyEngine.Renderer.Text
|
||||
return (double(value) / 64.0);
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, String fontPath, uint32 fontSize, bool hasColor = true, char32 firstChar = '\0', uint32 charCount = 128, int32 faceIndex = 0)
|
||||
public this(String fontPath, uint32 fontSize, bool hasColor = true, char32 firstChar = '\0', uint32 charCount = 128, int32 faceIndex = 0)
|
||||
{
|
||||
// Make sure the fontrenderer is initialized (Font only cares about freetype)
|
||||
FontRenderer.Init();
|
||||
|
||||
_context = context..AddRef();
|
||||
|
||||
// Set default sampler
|
||||
Sampler = null;
|
||||
|
||||
@@ -317,7 +314,7 @@ namespace GlitchyEngine.Renderer.Text
|
||||
desc.CpuAccess = .None;
|
||||
desc.Usage = .Default;
|
||||
|
||||
_atlas = new Texture2D(_context, desc);
|
||||
_atlas = new Texture2D(desc);
|
||||
_atlas.SamplerState = _sampler;
|
||||
|
||||
if(oldAtlas != null)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace GlitchyEngine.Renderer.Text
|
||||
|
||||
InitFreetype();
|
||||
|
||||
_msdfEffect = new Effect(Renderer._context, "content\\Shaders\\msdfShader.hlsl");
|
||||
_msdfEffect = new Effect("content\\Shaders\\msdfShader.hlsl");
|
||||
|
||||
s_isInitialized = true;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,8 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
public abstract class Texture : RefCounter
|
||||
{
|
||||
protected GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected SamplerState _samplerState ~ _?.ReleaseRef();
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
|
||||
public SamplerState SamplerState
|
||||
{
|
||||
get => _samplerState;
|
||||
@@ -41,11 +37,6 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
protected extern void ImplBind(uint32 slot);
|
||||
|
||||
protected this(GraphicsContext context)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
}
|
||||
}
|
||||
|
||||
public struct Texture2DDesc
|
||||
@@ -69,15 +60,13 @@ namespace GlitchyEngine.Renderer
|
||||
public override extern uint32 ArraySize {get;}
|
||||
public override extern uint32 MipLevels {get;}
|
||||
|
||||
protected this(GraphicsContext context) : base(context) {}
|
||||
|
||||
public this(GraphicsContext context, String path) : base(context)
|
||||
public this(String path)
|
||||
{
|
||||
this._path = new String(path);
|
||||
LoadTexturePlatform();
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, Texture2DDesc desc) : base(context)
|
||||
public this(Texture2DDesc desc)
|
||||
{
|
||||
PrepareTexturePlatform(desc, false);
|
||||
}
|
||||
@@ -132,9 +121,7 @@ namespace GlitchyEngine.Renderer
|
||||
public override extern uint32 ArraySize {get;}
|
||||
public override extern uint32 MipLevels {get;}
|
||||
|
||||
protected this(GraphicsContext context) : base(context) {}
|
||||
|
||||
public this(GraphicsContext context, String path) : base(context)
|
||||
public this(String path)
|
||||
{
|
||||
this._path = new String(path);
|
||||
LoadTexturePlatform();
|
||||
|
||||
@@ -25,13 +25,13 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public VertexBufferBinding Binding => _defaultBinding;
|
||||
|
||||
public this(GraphicsContext context, Type vertexType, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) :
|
||||
this(context, (.)vertexType.Stride, vertexCount, usage, cpuAccess)
|
||||
public this(Type vertexType, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) :
|
||||
this((.)vertexType.Stride, vertexCount, usage, cpuAccess)
|
||||
{
|
||||
_vertexType = vertexType;
|
||||
}
|
||||
|
||||
public this(GraphicsContext context, uint32 vertexStride, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None) : base(context)
|
||||
public this(uint32 vertexStride, uint32 vertexCount, Usage usage = .Default, CPUAccessFlags cpuAccess = .None)
|
||||
{
|
||||
_vertexType = null;
|
||||
|
||||
|
||||
@@ -81,24 +81,11 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public class VertexLayout : RefCounter
|
||||
{
|
||||
private GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
private VertexElement[] _elements;
|
||||
private bool _ownsElements;
|
||||
|
||||
public GraphicsContext Context => _context;
|
||||
|
||||
public VertexElement[] Elements => _elements;
|
||||
|
||||
public this(GraphicsContext context, VertexElement[] elements, bool ownsElements, VertexShader vertexShader)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
_elements = elements;
|
||||
_ownsElements = ownsElements;
|
||||
|
||||
CreateNativeLayout();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
if(_ownsElements)
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace GlitchyEngine.Renderer
|
||||
public class VertexShader : Shader
|
||||
{
|
||||
[AllowAppend]
|
||||
public this(GraphicsContext context, String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(context, source, entryPoint, macros) { }
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(source, entryPoint, macros) { }
|
||||
|
||||
public override extern void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user