Example #1
0
 public void ResetViews()
 {
     //!!!!
     for (int n = 0; n < currentViewNumber; n++)
     {
         Bgfx.ResetView((ushort)n);
     }
     currentViewNumber = -1;
 }
Example #2
0
        public void SetViewport(Viewport viewport, Matrix4F viewMatrix, Matrix4F projectionMatrix,
                                FrameBufferTypes clearBuffers, ColorValue clearBackgroundColor, float clearDepthValue = 1, byte clearStencilValue = 0)
        {
            currentViewport = viewport;
            currentViewNumber++;

            //init bgfx view

            Bgfx.ResetView(CurrentViewNumber);

            bool skip         = false;
            var  renderWindow = currentViewport.parent as RenderWindow;

            if (renderWindow != null && renderWindow.ThisIsApplicationWindow)
            {
                skip = true;
            }
            if (!skip)
            {
                Bgfx.SetViewFrameBuffer(CurrentViewNumber, currentViewport.parent.FrameBuffer);
            }

            Bgfx.SetViewMode(CurrentViewNumber, ViewMode.Sequential);
            Bgfx.SetViewRect(CurrentViewNumber, 0, 0, CurrentViewport.SizeInPixels.X, CurrentViewport.SizeInPixels.Y);
            unsafe
            {
                Bgfx.SetViewTransform(CurrentViewNumber, (float *)&viewMatrix, (float *)&projectionMatrix);
            }

            ////!!!!
            //if( clearBuffers == 0 )
            //{
            //	var target = viewport.Parent as RenderTexture;
            //	if( target != null )
            //	{
            //		if( !target.Creator._renderTargetCleared )
            //		{
            //			clearBuffers = FrameBufferTypes.Color;
            //			//clearBuffers = FrameBufferTypes.All;
            //		}
            //	}
            //}

            //clear
            if (clearBuffers != 0)
            {
                ClearTargets targets = 0;
                if ((clearBuffers & FrameBufferTypes.Color) != 0)
                {
                    targets |= ClearTargets.Color;
                }
                if ((clearBuffers & FrameBufferTypes.Depth) != 0)
                {
                    targets |= ClearTargets.Depth;
                }
                if ((clearBuffers & FrameBufferTypes.Stencil) != 0)
                {
                    targets |= ClearTargets.Stencil;
                }
                Bgfx.SetViewClear(CurrentViewNumber, targets, ToRGBA(clearBackgroundColor), clearDepthValue, clearStencilValue);

                Bgfx.Touch(CurrentViewNumber);
            }

            ////!!!!
            //if( clearBuffers != 0 )//if( clearBuffers == FrameBufferTypes.All )
            //{
            //	var target = viewport.Parent as RenderTexture;
            //	if( target != null )
            //		target.Creator._renderTargetCleared = true;
            //}

            //u_viewportSettings
            unsafe
            {
                var data = new ViewportSettingsUniform();
                data.size    = viewport.SizeInPixels.ToVector2F();
                data.sizeInv = new Vector2F(1, 1) / data.size;

                int vec4Count = sizeof(ViewportSettingsUniform) / sizeof(Vector4F);
                if (vec4Count != 1)
                {
                    Log.Fatal("Component_RenderingPipeline: Render: vec4Count != 1.");
                }
                SetUniform("u_viewportSettings", ParameterType.Vector4, vec4Count, &data);
            }
        }