Пример #1
0
 private void SetTextureParameter(TextureParameterName name, int value)
 {
     GL.ActiveTexture(TextureUnit.Texture0);
     GL.BindTexture(TextureTarget.Texture2D, handle);
     GL.TexParameter(TextureTarget.Texture2D, name, value);
     PlatformRenderer.MarkTextureSlotAsDirty(0);
 }
Пример #2
0
        /// <summary>
        /// Create texture from pixel array
        /// </summary>
        public void LoadImage(Color4[] pixels, int width, int height)
        {
            IsStubTexture = false;

            reloader = new TexturePixelArrayReloader(pixels, width, height);

            MemoryUsed  = 4 * width * height;
            ImageSize   = new Size(width, height);
            SurfaceSize = ImageSize;
            uvRect      = new Rectangle(0, 0, 1, 1);

            Window.Current.InvokeOnRendering(() => {
                var pinnedArray = GCHandle.Alloc(pixels, GCHandleType.Pinned);
                var pointer     = pinnedArray.AddrOfPinnedObject();

                PrepareOpenGLTexture();
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, handle);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pointer);
                PlatformRenderer.MarkTextureSlotAsDirty(0);
                PlatformRenderer.CheckErrors();

                pinnedArray.Free();
            });
        }
Пример #3
0
        private void ReadCompressedImage(ref Action glCommands, BinaryReader reader, int level, int width, int height, int linearSize, UInt32 pfFourCC)
        {
            var pif = (PixelInternalFormat)All.CompressedRgbS3tcDxt1Ext;

            switch ((DDSFourCC)pfFourCC)
            {
            case DDSFourCC.DXT1:
                pif = (PixelInternalFormat)All.CompressedRgbS3tcDxt1Ext;
                break;

            case DDSFourCC.DXT3:
                pif = (PixelInternalFormat)All.CompressedRgbaS3tcDxt3Ext;
                break;

            case DDSFourCC.DXT5:
                pif = (PixelInternalFormat)All.CompressedRgbaS3tcDxt5Ext;
                break;

            default:
                throw new InvalidDataException("Unsupported texture format");
            }
            var buffer = ReadTextureData(reader, linearSize);

            glCommands += () => {
                PlatformRenderer.PushTexture(handle, 0);
                GL.CompressedTexImage2D(TextureTarget.Texture2D, level, pif, width, height, 0, buffer.Length, buffer);
                PlatformRenderer.PopTexture(0);
                PlatformRenderer.CheckErrors();
            };
        }
Пример #4
0
 public void Apply(int pass)
 {
     shaderParams.Set(amountKey, new Vector4(ChromaticAberration * Red, ChromaticAberration * Green, ChromaticAberration * Blue, BarrelPincushion));
     PlatformRenderer.SetBlendState(!Opaque ? Blending.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(DistortionShaderProgram.GetInstance(Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #5
0
 public void Apply(int pass)
 {
     if (pass == 0)
     {
         if (shaderProgramPass1 == null)
         {
             shaderProgramPass1 = new ShaderProgram(
                 new Shader[] { new VertexShader(vs), new FragmentShader(fsPass1) },
                 ShaderPrograms.Attributes.GetLocations(), ShaderPrograms.GetSamplers());
         }
         PlatformRenderer.SetBlendState(Blending.LcdTextFirstPass.GetBlendState());
         PlatformRenderer.SetShaderProgram(shaderProgramPass1);
     }
     else
     {
         if (shaderProgramPass2 == null)
         {
             shaderProgramPass2 = new ShaderProgram(
                 new Shader[] { new VertexShader(vs), new FragmentShader(fsPass2) },
                 ShaderPrograms.Attributes.GetLocations(), ShaderPrograms.GetSamplers());
         }
         PlatformRenderer.SetBlendState(Blending.LcdTextSecondPass.GetBlendState());
         PlatformRenderer.SetShaderProgram(shaderProgramPass2);
     }
 }
Пример #6
0
        public void RestoreRenderTarget()
        {
            Renderer.Flush();
            uint prevFramebuffer = framebufferStack.Pop();

            PlatformRenderer.BindFramebuffer(prevFramebuffer);
        }
Пример #7
0
 public void Render()
 {
     for (int i = 0; i < Material.PassCount; i++)
     {
         Material.Apply(i);
         PlatformRenderer.DrawTriangles(mesh, StartIndex, LastIndex - StartIndex);
     }
 }
Пример #8
0
 public void Apply(int pass)
 {
     shaderParams.Set(texelStepKey, TexelStep);
     shaderParams.Set(amountKey, new Vector4(LumaTreshold, 0.25f / MulReduce, 1f / MinReduce, MaxSpan));
     PlatformRenderer.SetBlendState(!Opaque ? Blending.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(FXAAShaderProgram.GetInstance(Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #9
0
 public void Apply(int pass)
 {
     shaderParams.Set(stepKey, Dir * Radius * Step);
     shaderParams.Set(alphaCorrectionKey, 1f / AlphaCorrection);
     PlatformRenderer.SetBlendState(!Opaque ? Blending.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(BlurShaderProgram.GetInstance(BlurShaderId, Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #10
0
 private unsafe void SyncIntVector2(int location, ShaderParam <IntVector2> param)
 {
     fixed(IntVector2 *dataPtr = param.Data)
     {
         GL.Uniform2(location, param.Count, (int *)dataPtr);
         PlatformRenderer.CheckErrors();
     }
 }
Пример #11
0
 public void Apply(int pass)
 {
     shaderParams.Set(brightThresholdKey, BrightThreshold);
     shaderParams.Set(inversedGammaCorrectionKey, InversedGammaCorrection);
     PlatformRenderer.SetBlendState(disabledBlendingState);
     PlatformRenderer.SetShaderProgram(BloomShaderProgram.GetInstance());
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #12
0
 private unsafe void SyncFloatMatrix4x4(int location, ShaderParam <Matrix44> param)
 {
     fixed(Matrix44 *dataPtr = param.Data)
     {
         GL.UniformMatrix4(location, param.Count, false, (float *)dataPtr);
         PlatformRenderer.CheckErrors();
     }
 }
Пример #13
0
 public void Apply(int pass)
 {
     shaderParams.Set(stepKey, Step);
     shaderParams.Set(sharpnessKey, new Vector3(Strength, Strength * 0.25f, Limit));
     PlatformRenderer.SetBlendState(!Opaque ? Blending.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(SharpenShaderProgram.GetInstance(Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #14
0
 private void PreDraw()
 {
     UpdateBuffers();
     UpdateInputLayout();
     PlatformRenderer.SetVertexInputLayout(inputLayout);
     PlatformRenderer.SetVertexBuffer(0, vertexBuffer, 0);
     PlatformRenderer.SetIndexBuffer(indexBuffer, 0, IndexFormat.Index16Bits);
 }
Пример #15
0
 private unsafe void SyncFloatVector4(int location, ShaderParam <Vector4> param)
 {
     fixed(Vector4 *dataPtr = param.Data)
     {
         GL.Uniform4(location, param.Count, (float *)dataPtr);
         PlatformRenderer.CheckErrors();
     }
 }
Пример #16
0
 private unsafe void SyncInt(int location, ShaderParam <int> param)
 {
     fixed(int *dataPtr = param.Data)
     {
         GL.Uniform1(location, param.Count, dataPtr);
         PlatformRenderer.CheckErrors();
     }
 }
Пример #17
0
 public void Apply(int pass)
 {
     shaderParams.Set(brightThresholdKey, BrightThreshold);
     shaderParams.Set(darkThresholdKey, DarkThreshold);
     shaderParams.Set(softLightKey, SoftLight);
     PlatformRenderer.SetBlendState(!Opaque ? Blending.Alpha.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(NoiseShaderProgram.GetInstance(Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #18
0
 public void Apply(int pass)
 {
     shaderParams.Set(hslKey, HSL);
     shaderParams.Set(brightnessKey, Brightness);
     shaderParams.Set(contrastKey, Contrast);
     PlatformRenderer.SetBlendState(!Opaque ? Blending.GetBlendState() : disabledBlendingState);
     PlatformRenderer.SetShaderProgram(ColorCorrectionShaderProgram.GetInstance(RequiredBrightnessContrastProcess, RequiredHSLProcess, Opaque));
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #19
0
 public void Apply(int pass)
 {
     shaderParams.Set(angleKey, Angle);
     shaderParams.Set(uv1Key, UV1);
     shaderParams.Set(uv0Key, UV0);
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(TwistShaderProgram.Instance);
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #20
0
        public override void Render()
        {
            if (SkipRender)
            {
                return;
            }

            bool lightningEnabled = ProcessLightning && Viewport != null && Viewport.LightSource != null && Viewport.LightSource.Visible;
            bool shadowsEnabled   = lightningEnabled && Viewport.LightSource.ShadowMappingEnabled;

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;
            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    skin.SkinEnabled = sm.Bones.Count > 0;
                    if (skin.SkinEnabled)
                    {
                        if (sharedBoneTransforms.Length < sm.Bones.Count)
                        {
                            sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                        }
                        for (var i = 0; i < sm.Bones.Count; i++)
                        {
                            sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                        }
                        skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                    }
                }
                var lightningMaterial = sm.Material as IMaterialLightning;
                if (lightningMaterial != null)
                {
                    lightningMaterial.ProcessLightning = lightningEnabled;
                    if (lightningEnabled)
                    {
                        lightningMaterial.SetLightData(Viewport.LightSource);
                    }
                }

                var shadowMaterial = sm.Material as IMaterialShadowReciever;
                if (shadowMaterial != null)
                {
                    shadowMaterial.RecieveShadows = shadowsEnabled && RecieveShadow;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;
            }
        }
Пример #21
0
        public void SetAsRenderTarget()
        {
            Renderer.Flush();
            GetHandle();
            uint currentFramebuffer = (uint)PlatformRenderer.CurrentFramebuffer;

            PlatformRenderer.BindFramebuffer(framebuffer);
            framebufferStack.Push(currentFramebuffer);
        }
Пример #22
0
 public void Apply(int pass)
 {
     shaderParams.Set(brightnessKey, Brightness);
     shaderParams.Set(rangeKey, Range);
     shaderParams.Set(colorKey, Color);
     PlatformRenderer.SetTexture(1, MaskTexture);
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(DissolveMaterialShaderProgram.Instance);
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #23
0
 public void Render()
 {
     PlatformRenderer.SetTexture(0, Texture1);
     PlatformRenderer.SetTexture(1, Texture2);
     for (int i = 0; i < Material.PassCount; i++)
     {
         Material.Apply(i);
         Mesh.DrawIndexed(StartIndex, LastIndex - StartIndex);
     }
 }
Пример #24
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     if (platformRenderContext == null)
     {
         platformRenderContext = new Graphics.Platform.Vulkan.PlatformRenderContext();
         PlatformRenderer.Initialize(platformRenderContext);
     }
     RecreateSwapchain();
 }
Пример #25
0
 public void Apply(int pass)
 {
     shaderParams.Set(radiusKey, Radius);
     shaderParams.Set(brightnessKey, Brightness);
     shaderParams.Set(colorKey, Color);
     PlatformRenderer.SetTexture(1, MaskTexture);
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(AlphaIntensityShaderProgram.Instance);
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Пример #26
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     if (platformRenderContext == null)
     {
         platformRenderContext = new Graphics.Platform.Vulkan.PlatformRenderContext();
         PlatformRenderer.Initialize(platformRenderContext);
     }
     swapchain = new Graphics.Platform.Vulkan.Swapchain(platformRenderContext, Handle, ClientSize.Width, ClientSize.Height);
 }
Пример #27
0
 public void MakeCurrent()
 {
     EglMakeCurrent();
     if (platformRenderContext == null)
     {
         platformRenderContext = new Graphics.Platform.OpenGL.PlatformRenderContext();
         PlatformRenderer.Initialize(platformRenderContext);
     }
     platformRenderContext.Begin(0);
 }
Пример #28
0
 private void SetTextureParameter(TextureParameterName name, int value)
 {
     if (handle == 0)
     {
         return;
     }
     PlatformRenderer.PushTexture(handle, 0);
     GL.TexParameter(TextureTarget.Texture2D, name, value);
     PlatformRenderer.PopTexture(0);
 }
Пример #29
0
 private void OnEglContextLost()
 {
     Logger.Write("EGL context lost");
     DestroyEglContext();
     CreateEglContext();
     if (!EglTryMakeCurrent())
     {
         throw new System.Exception($"Could not make current EGL context, error {GetEglErrorString(egl.EglGetError())}");
     }
     PlatformRenderer.RaiseContextLost();
 }
Пример #30
0
 public void Apply(int pass)
 {
     shaderParams.Set(radiusKey, Radius);
     shaderParams.Set(softnessKey, Softness);
     shaderParams.Set(uv1Key, UV1);
     shaderParams.Set(uvOffsetKey, UVOffset);
     shaderParams.Set(colorKey, Color.ToVector4());
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(VignetteShaderProgram.GetInstance());
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }