Example #1
0
            /// <summary>
            /// Gets the render cache for the specified scheme.
            /// </summary>
            private RenderCache _GetCache(Scheme Scheme)
            {
                RenderCache rc;

                if (!this._Cache.TryGetValue(Scheme, out rc))
                {
                    rc = new RenderCache(Scheme, this._DataOctree);
                    this._Cache[Scheme] = rc;
                }
                return(rc);
            }
 private static void ClearCacheCallback()
 {
     RenderCache.ClearCache();
     SaveChangesCallback();
 }
Example #3
0
            /// <summary>
            /// Renders the chunk with the specified parameters.
            /// </summary>
            public void Render(Chunk[] Sides, Slice?Slice, Scheme Scheme)
            {
                RenderCache rc = this._GetCache(Scheme);
                Slice       s  = Slice.GetValueOrDefault(new Slice()
                {
                    Axis = Axis.Z, StartLevel = 0, EndLevel = ChunkSize
                });

                if (s.StartLevel < 0)
                {
                    s.StartLevel = 0;
                }
                if (s.EndLevel >= ChunkSize)
                {
                    s.EndLevel = ChunkSize - 1;
                }
                if (s.EndLevel >= s.StartLevel)
                {
                    if (s.StartLevel > 0 || s.EndLevel < ChunkSize - 1)
                    {
                        rc.InteriorRenderer.Render(s.Axis, s.StartLevel, s.EndLevel);
                    }
                    else
                    {
                        rc.InteriorRenderer.Render();
                    }

                    // Here marks the worst code in the program
                    if (s.Axis == Axis.Z)
                    {
                        if (s.EndLevel == ChunkSize - 1)
                        {
                            rc.GetSide(Axis.Z, Polarity.Positive, Axis.Z, this._DataOctree).Render();
                        }
                        if (s.StartLevel == 0 && s.EndLevel == ChunkSize - 1)
                        {
                            for (int t = 0; t < 4; t++)
                            {
                                Axis     ax  = (Axis)(t % 2);
                                Polarity pol = (Polarity)(t / 2);
                                if (Sides[t] == null)
                                {
                                    rc.GetSide(ax, pol, ax, this._DataOctree).Render();
                                }
                                else
                                {
                                    if (t < 2)
                                    {
                                        rc.GetInteriorSide(ax, Sides[t], ax, this._DataOctree).Render();
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int t = 0; t < 4; t++)
                            {
                                Axis     ax  = (Axis)(t % 2);
                                Polarity pol = (Polarity)(t / 2);
                                if (Sides[t] == null)
                                {
                                    rc.GetSide(ax, pol, Axis.Z, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                                }
                                else
                                {
                                    if (t < 2)
                                    {
                                        rc.GetInteriorSide(ax, Sides[t], Axis.Z, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Axis oppose = (Axis)(((int)s.Axis + 1) % 2);
                        if (s.StartLevel == 0)
                        {
                            if (Sides[(int)s.Axis + 2] == null)
                            {
                                rc.GetSide(s.Axis, Polarity.Negative, s.Axis, this._DataOctree).Render();
                            }
                        }
                        if (s.EndLevel == ChunkSize - 1)
                        {
                            if (Sides[(int)s.Axis] == null)
                            {
                                rc.GetSide(s.Axis, Polarity.Positive, s.Axis, this._DataOctree).Render();
                            }
                            else
                            {
                                rc.GetInteriorSide(s.Axis, Sides[(int)s.Axis], s.Axis, this._DataOctree).Render();
                            }
                        }
                        if (s.StartLevel == 0 && s.EndLevel == ChunkSize - 1)
                        {
                            rc.GetSide(Axis.Z, Polarity.Positive, Axis.Z, this._DataOctree).Render();
                            if (Sides[(int)oppose + 2] == null)
                            {
                                rc.GetSide(oppose, Polarity.Negative, oppose, this._DataOctree).Render();
                            }
                            if (Sides[(int)oppose] == null)
                            {
                                rc.GetSide(oppose, Polarity.Positive, oppose, this._DataOctree).Render();
                            }
                            else
                            {
                                rc.GetInteriorSide(oppose, Sides[(int)oppose], oppose, this._DataOctree).Render();
                            }
                        }
                        else
                        {
                            rc.GetSide(Axis.Z, Polarity.Positive, s.Axis, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                            if (Sides[(int)oppose + 2] == null)
                            {
                                rc.GetSide(oppose, Polarity.Negative, s.Axis, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                            }
                            if (Sides[(int)oppose] == null)
                            {
                                rc.GetSide(oppose, Polarity.Positive, s.Axis, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                            }
                            else
                            {
                                rc.GetInteriorSide(oppose, Sides[(int)oppose], s.Axis, this._DataOctree).Render(s.StartLevel, 0, s.EndLevel, 2);
                            }
                        }
                    }
                }
            }
Example #4
0
		//public static GameLib.EffectShader selMeshShader;


		void initOpenGL()
		{			
			GL.ClearColor(0.0f, 0.0f, 0.2f, 1.0f);
			GL.DepthFunc(DepthFunction.Lequal);
			GL.Enable(EnableCap.CullFace);
			GL.CullFace (CullFaceMode.Back);

			GL.PrimitiveRestartIndex (uint.MaxValue);
			GL.Enable (EnableCap.PrimitiveRestart);
			GL.Enable (EnableCap.Blend);
			GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

			GL.Enable (EnableCap.SampleShading);
			GL.MinSampleShading (0.5f);

			mainShader = new PuzzleShader();

			//selMeshShader = new GameLib.EffectShader ("Opuz2015.shaders.Border");


			mainCache = new RenderCache (ClientSize);

			ErrorCode err = GL.GetError ();
			Debug.Assert (err == ErrorCode.NoError, "OpenGL Error");	

		}
Example #5
0
 public void Render()
 {
     RenderCache?.Invoke(_cache.GetCache());
 }