2021-04-03

+ Added Field to DrawingBasis to enfore PrimitiveTypes
+ LastObject to context for Debugging
+ AppendRenderbuffer to Framebuffer

~ Added a depthbuffer to RenderPipeline.CreateWindowFramebuffer
~ Proper ZIndices over Z-Translation and DepthBuffer
~ Made "ShaderArguments["LineWidth"]" set the LineWidth even if the object isn't maked as LineMesh
~ Made that the SM2D.PolygonVertex can translate OpenTK.Vector2 by itself.
~ Made the SM2D.Transformation.ZIndex a CVector1 instead a float
This commit is contained in:
Michel Fedde 2021-03-04 22:17:03 +01:00
parent a7c71e7ea1
commit c6bf5c75bc
16 changed files with 114 additions and 26 deletions

View file

@ -1,10 +1,12 @@
#region usings
using System.Collections.Generic;
using OpenTK.Graphics.ES11;
using SM.Base;
using SM.Base.Scene;
using SM.Base.Windows;
using SM.OGL.Mesh;
using PrimitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType;
#endregion
@ -38,6 +40,8 @@ namespace SM.Base.Drawing
/// <inheritdoc />
public ICollection<string> Flags { get; set; }
public PrimitiveType? ForcedMeshType { get; set; }
/// <summary>
/// This value determents if the object should draw something.
/// </summary>
@ -68,7 +72,9 @@ namespace SM.Base.Drawing
/// <param name="context"></param>
protected virtual void DrawContext(ref DrawContext context)
{
context.ForcedType = ForcedMeshType;
context.TextureMatrix *= TextureTransform.GetMatrix();
context.LastObject = this;
}
}

View file

@ -122,7 +122,7 @@ namespace SM.Base.Scene
/// Draws only the background.
/// </summary>
/// <param name="context"></param>
public void DrawBackground(DrawContext context)
public virtual void DrawBackground(DrawContext context)
{
var backgroundDrawContext = context;
backgroundDrawContext.SetCamera(BackgroundCamera);
@ -133,7 +133,7 @@ namespace SM.Base.Scene
/// Draws only the main objects
/// </summary>
/// <param name="context"></param>
public void DrawMainObjects(DrawContext context)
public virtual void DrawMainObjects(DrawContext context)
{
if (!context.Window.ForceViewportCamera && Camera != null) context.SetCamera(Camera);
_objectCollection.Draw(context);
@ -143,7 +143,7 @@ namespace SM.Base.Scene
/// Draws only the HUD
/// </summary>
/// <param name="context"></param>
public void DrawHUD(DrawContext context)
public virtual void DrawHUD(DrawContext context)
{
context.SetCamera(HUDCamera);
_hud?.Draw(context);

View file

@ -41,6 +41,8 @@ namespace SM.Base.Drawing
if (context.Mesh is ILineMesh lineMesh)
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]);
if (context.Material.Blending)
{

View file

@ -57,7 +57,7 @@ namespace SM.Base.Drawing
uniforms["HasVColor"]
.SetUniform1(context.Mesh.Attributes.Has("color"));
DrawObject(context.Mesh);
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
}
static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context)
@ -86,7 +86,7 @@ namespace SM.Base.Drawing
shaderInstanceI++;
}
DrawObject(context.Mesh, shaderInstanceI);
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh, shaderInstanceI);
}
private string _vertexPreset;

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM.OGL.Mesh;
@ -11,12 +12,14 @@ namespace SM.Base.Windows
public IGenericWindow Window { get; internal set; }
public GenericScene Scene { get; internal set; }
public RenderPipeline RenderPipeline { get; internal set; }
public object LastObject { get; internal set; }
public GenericCamera UseCamera { get; internal set; }
public Matrix4 World => UseCamera.World;
public Matrix4 View => UseCamera.View;
public GenericMesh Mesh { get; set; }
public PrimitiveType? ForcedType { get; set; }
public Material Material { get; set; }
public MaterialShader Shader => Material.CustomShader ?? RenderPipeline.DefaultShader;

View file

@ -47,10 +47,13 @@ namespace SM.Base.Windows
DefaultShader ??= SMRenderer.DefaultMaterialShader;
}
public Framebuffer CreateWindowFramebuffer(int multisamples)
public Framebuffer CreateWindowFramebuffer(int multisamples = 0)
{
Framebuffer framebuffer = new Framebuffer(window: ConnectedWindow);
framebuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_LDR, multisamples));
RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
depthAttach.Multisample = multisamples;
framebuffer.AppendRenderbuffer(depthAttach);
return framebuffer;
}
}

View file

@ -114,6 +114,7 @@ namespace SM.Base.Windows
};
drawContext.SetCamera(window.ViewportCamera);
GL.DepthFunc(DepthFunction.Lequal);
window.CurrentRenderPipeline?.Render(ref drawContext);
}