Esempio n. 1
0
        private void CreateShader(MaterialType material, ShadingTechnique shadingTechnique, RenderQueue renderQueue)
        {
            if (shadingTechnique == ShadingTechnique.Deferred && RenderQueue == RenderQueue.CustomShaderOpaque)
            {
                throw new NotSupportedException("CustomOpaque shaders are not supported yet in Deferred Shading mode.");
            }

            this.RenderQueue      = renderQueue;
            this.MaterialType     = material;
            this.ShadingTechnique = shadingTechnique;

            OpenGLShader shader;

            this._shader  = shader = new OpenGLShader();
            _shader.Code  = GetDefaultShaderCode();
            _shader.Code += string.Format("\n#if defined FRAGMENT_SHADER\n{0}\n#endif\n", Resources.StandardShaders);
            shader.Define(material.ToString());

            switch (material)
            {
            case MaterialType.FlatColor:
            case MaterialType.FlatTextureColor:
            case MaterialType.FlatVertexColor:
                break;

            case MaterialType.DiffuseColor:
            case MaterialType.DiffuseColorTexture:
            case MaterialType.DiffuseNormalTextureColor:
            case MaterialType.ReflectionDiffuseColor:
            case MaterialType.RimDiffuseColorTexture:
            case MaterialType.RimReflectionDiffuseTextureColor:
                shader.Flags = ShaderDefines.USE_LIGHTING;
                break;

            default:
                throw new NotSupportedException(material.ToString());
            }

            InitShader();
        }
Esempio n. 2
0
        private string GetDefaultShaderCode()
        {
            switch (ShadingTechnique)
            {
            case ShadingTechnique.Forward:
                return(Resources.Forward);

            case ShadingTechnique.Deferred:
                switch (this.RenderQueue)
                {
                case RenderQueue.Opaque:
                    return(Resources.Deferred_1pass);

                case RenderQueue.Transparent:
                    return(Resources.Forward);

                default:
                    throw new NotSupportedException(this.RenderQueue.ToString());
                }

            default:
                throw new NotSupportedException(ShadingTechnique.ToString());
            }
        }
Esempio n. 3
0
 public Material(MaterialType material, ShadingTechnique shadingTechnique, RenderQueue renderQueue)
 {
     CreateShader(material, shadingTechnique, renderQueue);
 }
Esempio n. 4
0
        public Graphics(UserControl control, SceneTime time, ShadingTechnique technique)
        {
            Assert.NotNull(control);
            Assert.NotNull(time);

            IsDisposed = false;
            CurrentShadingTechnique = technique;

            if (GL.GetCurrent(false) != null || GetCurrent(false) != null)
            {
                var error = "Only one NetGL view per thread is now supported. Try launching 3D view in different thread.";
                Log.Error(error);
                throw new InvalidOperationException(error);
            }

            _control = control;
            _time    = time;

            try {
                _glContext = new GL(_control.Handle);
            }
            catch {
                Dispose();
                throw;
            }

            _currentContext.Value = this;

            _glContext.Enable(EnableCap.DepthTest);
            _glContext.Enable(EnableCap.Texture2D);
            _glContext.Enable(EnableCap.CullFace);
            _glContext.Enable(EnableCap.ProgramPointSize);
            _glContext.Enable(EnableCap.PointSprite);
            _glContext.CullFace(MaterialFace.Back);
            _glContext.FrontFace(FrontFaceDirection.CounterClockwise);
            _glContext.BlendEquation(BlendEquations.FuncAdd);
            _glContext.BlendFunc(BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);

            _glContext.SwapInterval(_swapInterval);

            _globalUniforms   = new GlobalUniformsBufferObject();
            _standartUniforms = new StandardUniformsBufferObject();
            _defaultMaterial  = new Material(MaterialType.DiffuseColor);
            _blankTexture     = new Texture2();
            _blankTexture.SetImage(new byte[4] {
                255, 0, 255, 255
            }, new Size(1, 1), Core.PixelFormat.Rgba, Core.PixelInternalFormat.Rgba8);
            _quadShader = new QuadShader();

            _displayQuadVao = CreateDisplayQuadVao();

            switch (CurrentShadingTechnique)
            {
            case ShadingTechnique.Forward:
                _renderTechnique = new ForwardRender();
                break;

            case ShadingTechnique.Deferred:
                _renderTechnique = new DeferredRender();
                break;

            default:
                throw new NotSupportedException(CurrentShadingTechnique.ToString());
            }

            ScreenSize = _control.ClientSize;
        }