Ejemplo n.º 1
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());
            }
        }
Ejemplo n.º 2
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;
        }