04.10.2020
+ render pipeline system for more control about the renderering. + Log system + Framebuffer system ~ Default shader was moved to pipelines.
This commit is contained in:
parent
97e638d9d9
commit
820d6ce700
34 changed files with 660 additions and 106 deletions
|
|
@ -50,13 +50,11 @@ namespace SM2D.Drawing
|
|||
|
||||
public void Draw(DrawContext context)
|
||||
{
|
||||
if (_material.Shader == null) _material.Shader = Defaults.DefaultShader;
|
||||
|
||||
context.Material = _material;
|
||||
context.Mesh = Plate.Object;
|
||||
|
||||
context.Instances[0].ModelMatrix = Matrix4.CreateScale(context.WorldScale.X, context.WorldScale.Y, 1);
|
||||
_material.Shader.Draw(context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,13 +24,11 @@ namespace SM2D.Drawing
|
|||
_material.Tint = color;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
ApplyContext(ref context);
|
||||
context.Instances[0].ModelMatrix = Transform.GetMatrix();
|
||||
|
||||
_material.Shader.Draw(context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,14 +22,11 @@ namespace SM2D.Drawing
|
|||
set => _mesh = value;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
ApplyContext(ref context);
|
||||
|
||||
context.Instances[0].ModelMatrix = Transform.GetMatrix();
|
||||
|
||||
_material.Shader.Draw(context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Text;
|
||||
using SM.Base.Types;
|
||||
using SM2D.Scene;
|
||||
|
|
@ -14,15 +15,14 @@ namespace SM2D.Drawing
|
|||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
base.DrawContext(ref context);
|
||||
context.Instances = _instances;
|
||||
ApplyContext(ref context);
|
||||
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
|
||||
_material.Shader.Draw(context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
|
||||
public int ZIndex { get; set; }
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace SM2D.Drawing
|
|||
public static float MasterScale = .25f;
|
||||
|
||||
public float Scale = 1;
|
||||
public bool ManualSize = false;
|
||||
public Texture Texture
|
||||
{
|
||||
get => (Texture) _material.Texture;
|
||||
|
|
@ -28,16 +29,19 @@ namespace SM2D.Drawing
|
|||
public DrawTexture(Bitmap map) : this(map, Color4.White)
|
||||
{ }
|
||||
|
||||
public DrawTexture(Bitmap map, Color4 color)
|
||||
public DrawTexture(Bitmap map, Color4 color) : this((Texture)map, color)
|
||||
{ }
|
||||
|
||||
public DrawTexture(Texture texture, Color4 color)
|
||||
{
|
||||
_material.Texture = new Texture(map);
|
||||
_material.Texture = texture;
|
||||
_material.Tint = color;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
Transform.Size = new CVector2(Texture.Map.Width * MasterScale * Scale, Texture.Map.Height * MasterScale * Scale);
|
||||
base.Draw(context);
|
||||
if (!ManualSize) Transform.Size = new CVector2(Texture.Map.Width * MasterScale * Scale, Texture.Map.Height * MasterScale * Scale);
|
||||
base.DrawContext(ref context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,13 +5,14 @@ using OpenTK.Input;
|
|||
using SM.Base;
|
||||
using SM.Base.Controls;
|
||||
using SM2D.Controls;
|
||||
using SM2D.Pipelines;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Shader;
|
||||
using Vector2 = OpenTK.Vector2;
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public class GLWindow2D : GenericWindow<Scene.Scene, I2DShowItem, Camera>
|
||||
public class GLWindow2D : GenericWindow<Scene.Scene, Camera>
|
||||
{
|
||||
public Vector2? Scaling { get; set; }
|
||||
public Vector2 WorldScale => _worldScale;
|
||||
|
|
@ -25,13 +26,17 @@ namespace SM2D
|
|||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
Defaults.DefaultShader = new Default2DShader();
|
||||
|
||||
base.OnLoad(e);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
protected override void OnLoaded()
|
||||
{
|
||||
base.OnLoaded();
|
||||
SetRenderPipeline(new Basic2DPipeline());
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
|
|
|
|||
23
SMCode/SM2D/Pipelines/Basic2DPipeline.cs
Normal file
23
SMCode/SM2D/Pipelines/Basic2DPipeline.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM2D.Shader;
|
||||
|
||||
namespace SM2D.Pipelines
|
||||
{
|
||||
public class Basic2DPipeline : RenderPipeline<Scene.Scene>
|
||||
{
|
||||
protected override IShader _defaultShader { get; } = Default2DShader.Shader;
|
||||
|
||||
protected override void Render(ref DrawContext context, Scene.Scene scene)
|
||||
{
|
||||
base.Render(ref context, scene);
|
||||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
scene.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
<Compile Include="GLWindow2D.cs" />
|
||||
<Compile Include="Object\Polygon.cs" />
|
||||
<Compile Include="Object\PolygonVertex.cs" />
|
||||
<Compile Include="Pipelines\Basic2DPipeline.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scene\Camera.cs" />
|
||||
<Compile Include="Scene\I2DShowItem.cs" />
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace SM2D.Scene
|
|||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
Objects.Sort((x, y) => x.ZIndex - y.ZIndex);
|
||||
Sort((x, y) => x.ZIndex - y.ZIndex);
|
||||
|
||||
base.Draw(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using SM2D.Drawing;
|
|||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
public class Scene : GenericScene<Camera, I2DShowItem>
|
||||
public class Scene : GenericScene<Camera, ItemCollection, I2DShowItem>
|
||||
{
|
||||
public DrawBackground Background => (DrawBackground)_background;
|
||||
|
||||
|
|
@ -13,11 +13,5 @@ namespace SM2D.Scene
|
|||
{
|
||||
_background = new DrawBackground(Color4.Black);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
Objects.Sort((x,y) => x.ZIndex - y.ZIndex);
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,13 +8,15 @@ namespace SM2D.Shader
|
|||
{
|
||||
public class Default2DShader : GenericShader, IShader
|
||||
{
|
||||
protected override bool AutoCompile { get; } = true;
|
||||
public static Default2DShader Shader = new Default2DShader();
|
||||
|
||||
public Default2DShader() : base(new ShaderFileCollection(
|
||||
//protected override bool AutoCompile { get; } = true;
|
||||
|
||||
private Default2DShader() : base(new ShaderFileCollection(
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.vert"),
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.frag")))
|
||||
{
|
||||
|
||||
Load();
|
||||
}
|
||||
public void Draw(DrawContext context)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue