Ejemplo n.º 1
0
        public override void StartDrawingModel(float[] model_color, Matrix mvp_matrix)
        {
            // コンテキストの状態を保存する
            State.SaveState();

            // 描画設定をする
            Gl.FrontFace(FrontFaceDirection.Ccw);

            Gl.Disable(EnableCap.ScissorTest);
            Gl.Disable(EnableCap.StencilTest);
            Gl.Disable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            Gl.ColorMask(true, true, true, true);

            // 不要なバッファがバインドされていたら解除する
            Gl.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            Gl.BindBuffer(BufferTarget.ArrayBuffer, 0);

            // モデルのパラメータをコピーする
            if ((model_color != null) && (model_color.Length == 4))
            {
                model_color.CopyTo(ModelColor, 0);
            }
            else
            {
                DefaultModelColor.CopyTo(ModelColor, 0);
            }
            MvpMatrix = (Matrix)mvp_matrix.Clone();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存した状態を復帰する。
        /// </summary>
        public void RestoreState()
        {
            Gl.UseProgram((uint)LastProgram);

            SetEnabledVertexAttribArray(0, LastVertexAttribArrayEnabled[0] != 0);
            SetEnabledVertexAttribArray(1, LastVertexAttribArrayEnabled[1] != 0);
            SetEnabledVertexAttribArray(2, LastVertexAttribArrayEnabled[2] != 0);
            SetEnabledVertexAttribArray(3, LastVertexAttribArrayEnabled[3] != 0);

            SetEnabled(EnableCap.ScissorTest, LastScissorTest);
            SetEnabled(EnableCap.StencilTest, LastStencilTest);
            SetEnabled(EnableCap.DepthTest, LastDepthTest);
            SetEnabled(EnableCap.CullFace, LastCullFace);
            SetEnabled(EnableCap.Blend, LastBlend);

            Gl.FrontFace((FrontFaceDirection)LastFrontFace);

            Gl.ColorMask(LastColorMask[0] != 0, LastColorMask[1] != 0, LastColorMask[2] != 0, LastColorMask[3] != 0);

            Gl.BindBuffer(BufferTarget.ArrayBuffer, (uint)LastArrayBufferBinding);
            Gl.BindBuffer(BufferTarget.ElementArrayBuffer, (uint)LastElementArrayBufferBinding);

            Gl.ActiveTexture(TextureUnit.Texture1);
            Gl.BindTexture(TextureTarget.Texture2d, (uint)LastTexture1Binding2D);

            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, (uint)LastTexture0Binding2D);

            Gl.ActiveTexture((TextureUnit)LastActiveTexture);

            Gl.BlendFuncSeparate((BlendingFactor)LastBlending[0], (BlendingFactor)LastBlending[1], (BlendingFactor)LastBlending[2], (BlendingFactor)LastBlending[3]);

            RestoreViewport();
            RestoreFrameBuffer();
        }
Ejemplo n.º 3
0
 private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program)
 {
     // Color
     Gl.ColorMask(ColorMaskR, ColorMaskG, ColorMaskB, ColorMaskA);
     // Depth
     Gl.DepthMask(DepthMask);
     // Stencil
     if (ctx.Version >= Gl.Version_200)
     {
         if (StencilMaskFront != StencilMaskBack)
         {
             Gl.StencilMaskSeparate(StencilFaceDirection.Front, StencilMaskFront);
             Gl.StencilMaskSeparate(StencilFaceDirection.Back, StencilMaskBack);
         }
         else
         {
             Gl.StencilMaskSeparate(StencilFaceDirection.FrontAndBack, StencilMaskFront);
         }
     }
     else
     {
         if (StencilMaskFront != StencilMaskBack)
         {
             throw new InvalidOperationException("seperate stencil mask not supported");
         }
         Gl.StencilMask(StencilMaskFront);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Toggle whether to render to the color buffer.
 /// </summary>
 /// <param name="renderColor">Whether to render to the color buffer.</param>
 public void ToggleRenderColor(bool renderColor)
 {
     FlushRenderStream();
     if (renderColor)
     {
         Gl.ColorMask(true, true, true, true);
     }
     else
     {
         Gl.ColorMask(false, false, false, false);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Toggle whether to render to the color buffer.
 /// </summary>
 /// <param name="renderColor">Whether to render to the color buffer.</param>
 public void ToggleRenderColor(bool renderColor)
 {
     InvalidateStateBatches();
     if (renderColor)
     {
         Gl.ColorMask(true, true, true, true);
     }
     else
     {
         Gl.ColorMask(false, false, false, false);
     }
 }
Ejemplo n.º 6
0
 private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program, WriteMaskState currentState)
 {
     // Color
     if (ColorMaskR != currentState.ColorMaskR || ColorMaskG != currentState.ColorMaskG || ColorMaskB != currentState.ColorMaskB || ColorMaskA != currentState.ColorMaskA)
     {
         Gl.ColorMask(ColorMaskR, ColorMaskG, ColorMaskB, ColorMaskA);
     }
     // Depth
     if (DepthMask != currentState.DepthMask)
     {
         Gl.DepthMask(DepthMask);
     }
     // Stencil
     if (ctx.Version >= Gl.Version_200)
     {
         if (StencilMaskFront != StencilMaskBack)
         {
             if (StencilMaskFront != currentState.StencilMaskFront)
             {
                 Gl.StencilMaskSeparate(StencilFaceDirection.Front, StencilMaskFront);
             }
             if (StencilMaskBack != currentState.StencilMaskBack)
             {
                 Gl.StencilMaskSeparate(StencilFaceDirection.Back, StencilMaskBack);
             }
         }
         else
         {
             if (StencilMaskFront != currentState.StencilMaskFront || StencilMaskFront != currentState.StencilMaskBack)
             {
                 Gl.StencilMaskSeparate(StencilFaceDirection.FrontAndBack, StencilMaskFront);
             }
         }
     }
     else
     {
         if (StencilMaskFront != StencilMaskBack)
         {
             throw new InvalidOperationException("seperate stencil mask not supported");
         }
         if (StencilMaskFront != currentState.StencilMaskFront)
         {
             Gl.StencilMask(StencilMaskFront);
         }
     }
 }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public override void DefaultGLState()
        {
            // If the renderer is not setup, skip.
            if (Engine.Renderer == null)
            {
                return;
            }

            CheckError("after setting default state");

            // Reset blend.
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Reset depth test.
            StateDepthTest(true);
            Gl.DepthFunc(DepthFunction.Lequal);

            // Reset stencil.
            StateStencilTest(false);

            // Reset cull face.
            Gl.Disable(EnableCap.CullFace);

            // Reset depth mask.
            Gl.DepthMask(true);

            // Reset scissor.
            SetClipRect(0, 0, (int)Engine.Renderer.CurrentTarget.Size.X, (int)Engine.Renderer.CurrentTarget.Size.Y);
            Gl.FrontFace(FrontFaceDirection.Ccw);

            // Reset color mask.
            Gl.ColorMask(true, true, true, true);

            CheckError("before setting default state");
        }