// add a shader, under a name, indicate if at end, and if allowed to end join
        private void AddItem(IGLProgramShader prog, string name, IGLRenderableItem r, bool atend, bool allowendjoin)
        {
            Tuple <IGLProgramShader, List <Tuple <string, IGLRenderableItem> > > shaderpos = null;

            if (atend)                                                                                         // must be at end
            {
                if (allowendjoin && renderables.Count > 0 && renderables[renderables.Count - 1].Item1 == prog) // if its the last one, we can add to it, otherwise we must make new
                {
                    shaderpos = renderables[renderables.Count - 1];
                }
            }
            else
            {
                shaderpos = renderables.Find(x => x.Item1 == prog); // find the shader, may be null
            }
            if (shaderpos == null)
            {
                renderables.Add(new Tuple <IGLProgramShader, List <Tuple <string, IGLRenderableItem> > >(prog, r == null ? null : new List <Tuple <string, IGLRenderableItem> >()));
                shaderpos = renderables[renderables.Count - 1];
            }

            if (r != null)
            {
                shaderpos.Item2.Add(new Tuple <string, IGLRenderableItem>(name, r));
            }
        }
        /// <summary>Remove the shader/render item</summary>
        public bool Remove(IGLProgramShader prog, IGLRenderableItem r)
        {
            Tuple <IGLProgramShader, List <Tuple <string, IGLRenderableItem> > > found = renderables.Find(x => x.Item1 == prog); // find the shader

            if (found != null)
            {
                var list = found.Item2;                                             // list of tuples of <name,RI>
                var i    = list.FindIndex(x => Object.ReferenceEquals(x.Item2, r)); // find renderable in list

                if (i >= 0)
                {
                    byname.Remove(list[i].Item1);   // remove name
                    list.RemoveAt(i);

                    //foreach (var s in renderables[prog]) System.Diagnostics.Debug.WriteLine($"left .. {prog.Name} {s.Item1}");

                    if (list.Count == 0)       // if nothing more in shader
                    {
                        //System.Diagnostics.Debug.WriteLine($"remove shader {prog.Name}");
                        renderables.Remove(found);           // remove shader
                    }
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        private void ControllerDraw(Controller3D mc, ulong unused)
        {
            ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc);        // set the matrix unform block to the controller 3d matrix calc.

            IGLRenderableItem       i = rObjects["DYNGRIDRENDER"];
            DynamicGridVertexShader s = items.PLShader("PLGRIDVertShader") as DynamicGridVertexShader;

            if (Math.Abs(lasteyedistance - gl3dcontroller.MatrixCalc.EyeDistance) > 10)     // a little histerisis
            {
                i.InstanceCount = s.ComputeGridSize(gl3dcontroller.MatrixCalc.EyeDistance, out lastgridwidth);
                lasteyedistance = gl3dcontroller.MatrixCalc.EyeDistance;
            }

            s.SetUniforms(gl3dcontroller.MatrixCalc.LookAt, lastgridwidth, i.InstanceCount);

            DynamicGridCoordVertexShader bs = items.PLShader("PLGRIDBitmapVertShader") as DynamicGridCoordVertexShader;

            bs.ComputeUniforms(lastgridwidth, gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.CameraDirection, Color.Yellow, Color.Transparent);

            solmarker.Position = gl3dcontroller.MatrixCalc.LookAt;
            solmarker.Scale    = gl3dcontroller.MatrixCalc.EyeDistance / 20;

            rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc);

            this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor;
        }
 /// <summary>Add a shader and renderable item to the list</summary>
 /// <param name="prog">Shader program</param>
 /// <param name="name">Name of renderable item, may be null in which case it will automatically be named</param>
 /// <param name="renderableitem">The render to execute under this shader</param>
 /// <param name="atend">Force the render to be the last in the current queue. If false, and a shader already is in the queue, then its placed at the end of that shader list.</param>
 public void Add(IGLProgramShader prog, string name, IGLRenderableItem renderableitem, bool atend = false)
 {
     System.Diagnostics.Debug.Assert(renderableitem != null);
     name = EnsureName(name, prog, renderableitem);
     //System.Diagnostics.Debug.WriteLine($"Add render {prog.Name} {name}");
     AddItem(prog, name, renderableitem, atend, true);
     byname.Add(name, renderableitem);
 }
 private Tuple <IGLProgramShader, int> Find(IGLRenderableItem r)        // find r in list
 {
     foreach (var kvp in renderables)
     {
         if (kvp.Item2 != null)          // this may be null if its a shader operation or compute shader
         {
             var i = kvp.Item2.FindIndex(x => Object.ReferenceEquals(x.Item2, r));
             if (i >= 0)
             {
                 return(new Tuple <IGLProgramShader, int>(kvp.Item1, i));
             }
         }
     }
     return(null);
 }
示例#6
0
            public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)     // called per renderable item..
            {
                GLOFC.GLStatics.Check();

                if (texture.Id >= 0)
                {
                    if (texture.MipMapAutoGenNeeded)
                    {
                        texture.GenMipMapTextures();
                        texture.MipMapAutoGenNeeded = false;
                    }

                    texture.Bind(1);
                    GLOFC.GLStatics.Check();
                }
            }
示例#7
0
        /// <summary>Bind data to uniforms </summary>
        public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)
        {
            int sid = shader.GetShader(ShaderType.VertexShader).Id;

            GL.ProgramUniformMatrix4(sid, TransformUniform, false, ref transform);

            if (lookatangle)
            {
                Vector2 res = pos.AzEl(c.EyePosition, false);
                System.Diagnostics.Debug.WriteLine("Object Bind eye " + c.EyePosition + " to " + pos + " az " + res.Y.Degrees() + " inc " + res.X.Degrees());
                Matrix4 tx2 = Matrix4.Identity;
                tx2 *= Matrix4.CreateRotationX((-res.X));
                tx2 *= Matrix4.CreateRotationY(((float)Math.PI + res.Y));
                GL.ProgramUniformMatrix4(sid, LookAtUniform, false, ref tx2);
            }

            GLStatics.Check();
        }
示例#8
0
        private void ControllerDraw(Controller3D c3d, ulong unused)
        {
            ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc);        // set the matrix unform block to the controller 3d matrix calc.

            IGLRenderableItem       i = rObjects["DYNGRIDRENDER"];
            DynamicGridVertexShader s = items.PLShader("PLGRIDVertShader") as DynamicGridVertexShader;

            if (Math.Abs(lasteyedistance - gl3dcontroller.MatrixCalc.EyeDistance) > 10)     // a little histerisis
            {
                i.InstanceCount = s.ComputeGridSize(gl3dcontroller.MatrixCalc.EyeDistance, out lastgridwidth);
                lasteyedistance = gl3dcontroller.MatrixCalc.EyeDistance;
            }

            s.SetUniforms(gl3dcontroller.MatrixCalc.LookAt, lastgridwidth, i.InstanceCount);

            float dist = c3d.MatrixCalc.EyeDistance;
            float d1   = dist - lastgridwidth;
            float suc  = d1 / (9.0f * lastgridwidth);
            float cf   = 1.0f - suc.Clamp(0f, 1f);
            float a    = 0.7f * cf;

            float coordfade = lastgridwidth == 10000 ? (0.7f - (c3d.MatrixCalc.EyeDistance / 20000).Clamp(0.0f, 0.7f)) : 0.7f;
            Color coordscol = Color.FromArgb(coordfade < 0.05 ? 0 : 150, Color.Cyan);

            System.Diagnostics.Debug.WriteLine("Dist {0} grid {1} suc {2} cf {3} a {4} coord {5} {6}", dist, lastgridwidth, suc, cf, a, coordfade, coordscol);

            DynamicGridCoordVertexShader bs = items.PLShader("PLGRIDBitmapVertShader") as DynamicGridCoordVertexShader;

            bs.ComputeUniforms(lastgridwidth, gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.CameraDirection, coordscol, Color.Transparent);

            if (galaxy != null)
            {
                galaxy.InstanceCount = volumetricblock.Set(gl3dcontroller.MatrixCalc, boundingbox, 50.0f);        // set up the volumentric uniform

                IGLProgramShader p = items.Shader("Galaxy");
                var fsgalaxy       = p.GetShader(OpenTK.Graphics.OpenGL4.ShaderType.FragmentShader) as GalaxyFragmentPipeline;
                fsgalaxy.SetFader(c3d.MatrixCalc.EyeDistance);
            }

            rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc);


            this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " dir " + gl3dcontroller.PosCamera.CameraDirection + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance + " Zoom " + gl3dcontroller.PosCamera.ZoomFactor;
        }
示例#9
0
 /// <summary>Bind to Vector4 Position and ColorIndex to uniforms </summary>
 public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)
 {
     GL.ProgramUniform4(shader.GetShader(ShaderType.VertexShader).Id, PositionBind, new Vector4(WorldPosition.X, WorldPosition.Y, WorldPosition.Z, ColorIndex));
 }
示例#10
0
 /// <summary>Bind color data to uniform </summary>
 public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)
 {
     GL.ProgramUniform4(shader.GetShader(ShaderType.FragmentShader).Id, ColorBind, col.ToVector4());
     GLStatics.Check();
 }
示例#11
0
 /// <summary>Bind textures </summary>
 public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)
 {
     GL.BindTextures(TextureBind, Textures.Length, Textures);
 }
示例#12
0
 /// <summary>Bind data to uniforms </summary>
 public override void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c)
 {
     base.Bind(ri, shader, c);
     Texture.Bind(TextureBind);
     GLStatics.Check();
 }
 /// <summary>Add a shader and renderable item to the list</summary>
 /// <param name="prog">Shader program</param>
 /// <param name="renderableitem">The render to execute under this shader</param>
 /// <param name="atend">Force the render to be the last in the current queue. If false, and a shader already is in the queue, then its placed at the end of that shader list.</param>
 public void Add(IGLProgramShader prog, IGLRenderableItem renderableitem, bool atend = false)
 {
     System.Diagnostics.Debug.Assert(renderableitem != null);
     AddItem(prog, EnsureName(null, prog, renderableitem), renderableitem, atend, true);
 }
 private new  void Add(IGLProgramShader prog, IGLRenderableItem r, bool atend = false)
 {
     System.Diagnostics.Debug.Assert(false, "Cannot add a normal shader to a compute shader list");
 }
 private string EnsureName(string name, IGLProgramShader prog, IGLRenderableItem r)
 {
     return(name.HasChars() ? name : (prog.GetType().Name + ":" + r.GetType().Name + " # " + (unnamed++).ToStringInvariant()));
 }
        /// <summary>Remove the render from the list</summary>
        public bool Remove(IGLRenderableItem r)
        {
            var f = Find(r);

            return(r != null?Remove(f.Item1, r) : false);
        }