//----------------------------------------------------------------------- //----------------------------------------------------------------------- // file="FBOframe.cs" // Project: StgSharp // AuthorGroup: Nitload Space // Copyright (c) Nitload Space. All rights reserved. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the “Software”), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and // this permission notice shall be included in all copies // or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED “AS IS”, // WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //----------------------------------------------------------------------- //----------------------------------------------------------------------- using StgSharp.Controls; using StgSharp.Geometries; using StgSharp.Graphics; using StgSharp.Graphics.GL; using StgSharp.Logic; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StgSharp { public class fboFrame : glRenderStream { ElementBuffer ebo; TriggerButton button; Rectangle tex; ShaderProgram s; TextureGL t; Uniform texUniform; VertexArray vao; VertexBuffer vbo; internal TimeSpanProvider spanProvider; public fboFrame(ViewPort args, (int,int,int) cube) : base(args,cube) { } protected override string[] InputPortsName => [ "TextureInput" ]; protected override string[] OutputPortsName => [ "Output" ]; protected override void Deinit() { throw new NotImplementedException(); } protected override void Init() { //SetSizeLimit(800, 800, 800, 800); vbo = CreateVertexBuffer(2); vao = CreateVertexArray(1); ebo = CreateElementBuffer(1); Rectangle rec = new Rectangle( -0.9f, 0.9f, 0.9f, 0.9f, 0.9f, -0.9f, -0.9f, -0.9f ); /* Rectangle tex = new Rectangle( -0.8f, 0.8f, 0, 0.8f, 0.8f, 0, 0.8f, -0.8f, 0, -0.8f, -0.8f, 0 ); /**/ /**/ tex = new Rectangle( 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f ); /**/ s = CreateShaderProgram(); Shader vert = CreateShaderSegment(ShaderType.Vertex, 1); Shader frag = CreateShaderSegment(ShaderType.Fragment, 1); vert.Compile(0, Shader.FromCodeFile("Shader\\fbo.vert")); frag.Compile(0, Shader.FromCodeFile("Shader\\fbo.frag")); vert.AttachTo(0, s); frag.AttachTo(0, s); s.Link(); vao.Bind(0); ebo.Bind(0); ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw); vbo.Bind(0); vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw); VertexArray.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0); vbo.Bind(1); vbo.WriteVectorData(1, tex.VertexStream, BufferUsage.StaticDraw); VertexArray.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0); t = CreateTexture(1); t.Bind2D(0); t.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat); t.Set2dFilterProperty(Filter.Nearest, Filter.Nearest); TextureGL.Activate(TextureUnit.Unit0); texUniform = s.GetUniform("tex"); glFunc.SetUniformValue(texUniform, 0); ViewPortDesigner vpDesigner = new ViewPortDesigner(); vpDesigner.CreateKeyboardButtonGroup(null,null,null,null,null); button = vpDesigner.CreateKeyboardButton( rec,null,false ); } protected override void Main( in Dictionary input, in Dictionary output) { TexturePipeline p = input["TextureInput"].Args as TexturePipeline; Image i = (p ?? throw new Exception("Pipeline has null value")).Value; AnimationBuilder animation = new AnimationBuilder( (float f, out Polygon4 frame) => { frame = tex; return i; }, TimeFunction.One); button.Enable(animation); FrameBuffer.BindNull(); glFunc.ClearColor(0.4f, 0.1f, 0f, 1.0f); glFunc.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH); s.Use(); vao.Bind(0); foreach (PlainGeometryMesh item in button) { t.LoadTexture(0, item.TextureImage); } glFunc.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero); //glFunc.DrawElements(GeometryType.LINES, 6, TypeCode.UInt32, IntPtr.Zero); BlueprintPipeline.SkipAll(output); SwapBuffers(); } } }