Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoInitialize()
        {
            // init shader program.
            ShaderProgram program = this.shaderCodes.CreateProgram();

            // init property buffer objects.
            VertexBuffer positionBuffer = null;
            IBufferable  model          = this.DataSource;

            VertexBuffer[] vertexAttributeBuffers;
            {
                var list = new List <VertexBuffer>();
                foreach (AttributeMap.NamePair item in this.attributeMap)
                {
                    VertexBuffer buffer = model.GetVertexAttributeBuffer(
                        item.NameInIBufferable, item.VarNameInShader);
                    if (buffer == null)
                    {
                        throw new Exception(string.Format("[{0}] returns null buffer pointer!", model));
                    }
                    if (item.NameInIBufferable == positionNameInIBufferable)
                    {
                        if (positionBuffer != null)
                        {
                            throw new Exception(string.Format("Duplicate position buffer is not allowed!"));
                        }

                        positionBuffer = buffer.Clone() as VertexBuffer;
                        positionBuffer.VarNameInVertexShader = "in_Position";// in_Postion same with in the PickingShader.vert shader
                    }
                    list.Add(buffer);
                }
                vertexAttributeBuffers = list.ToArray();
            }

            // init index buffer
            OneIndexBuffer indexBuffer;
            {
                var mode = DrawMode.Points;//any mode is OK as we'll update it later in other place.
                indexBuffer              = Buffer.Create(IndexBufferElementType.UInt, positionBuffer.ByteLength / (positionBuffer.Config.GetDataSize() * positionBuffer.Config.GetDataTypeByteLength()), mode, BufferUsage.StaticDraw);
                this.maxElementCount     = indexBuffer.ElementCount;
                indexBuffer.ElementCount = 0;// 高亮0个图元
                // RULE: Renderer takes uint.MaxValue, ushort.MaxValue or byte.MaxValue as PrimitiveRestartIndex. So take care this rule when designing a model's index buffer.
                GLState glState = new PrimitiveRestartState(indexBuffer.ElementType);
                this.stateList.Add(glState);
            }

            // init VAO.
            var vertexArrayObject = new VertexArrayObject(indexBuffer, vertexAttributeBuffers);

            vertexArrayObject.Initialize(program);

            // sets fields.
            this.Program = program;
            this.vertexAttributeBuffers = vertexAttributeBuffers;
            this.indexBuffer            = indexBuffer;
            this.vertexArrayObject      = vertexArrayObject;

            this.positionBuffer = positionBuffer;
        }
Exemplo n.º 2
0
 private TrefoilKnotRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.stateList.Add(new LineWidthState(3));
     this.stateList.Add(new PointSizeState(3));
 }
Exemplo n.º 3
0
        private static IBufferable GetModel(BuildInSceneObject buildIn)
        {
            IBufferable bufferable = null;

            switch (buildIn)
            {
            case BuildInSceneObject.Cube:
                bufferable = new Cube();
                break;

            case BuildInSceneObject.Sphere:
                bufferable = new Sphere();
                break;

            case BuildInSceneObject.Ground:
                bufferable = new Ground(1, 1000, 1000);
                break;

            case BuildInSceneObject.Axis:
                bufferable = new Axis();
                break;

            default:
                throw new NotImplementedException();
            }

            return(bufferable);
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="bufferable">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        internal InnerPickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                                       PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                                       params GLSwitch[] switches)
            : base(bufferable, shaderCodes, propertyNameMap, switches)
        {
            this.positionNameInIBufferable = positionNameInIBufferable;

            {
                var polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled);
                this.PolygonModeSwitch = polygonModeSwitch;
                this.switchList.Add(polygonModeSwitch);
            }
            {
                float min, max;
                OpenGL.LineWidthRange(out min, out max);
                var lineWidthSwitch = new LineWidthSwitch(max);
                this.LineWidthSwitch = lineWidthSwitch;
                this.switchList.Add(lineWidthSwitch);
            }
            {
                float min, max;
                OpenGL.PointSizeRange(out min, out max);
                var pointSizeSwitch = new PointSizeSwitch(max);
                this.PointSizeSwitch = pointSizeSwitch;
                this.switchList.Add(pointSizeSwitch);
            }
        }
Exemplo n.º 5
0
 public MovableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
     this.Scale = 1.0f;
 }
 public OrderIndependentTransparencyRenderer(IBufferable model, vec3 lengths,
     string positionName, string normalName)
 {
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestState = new DepthTestState(false);
         this.cullFaceState = new CullFaceState(false);
     }
     this.ModelSize = lengths;
 }
Exemplo n.º 7
0
        /// <summary>
        /// 高亮显示指定的图元。
        /// </summary>
        /// <param name="bufferable">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<see cref="BufferPtr"/>和<see cref="ShaderCode"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public HighlightRenderer(IBufferable bufferable,
                                 string positionNameInIBufferable,
                                 params GLSwitch[] switches)
            : base(bufferable, HighlightShaderHelper.GetHighlightShaderCode(),
                   new PropertyNameMap("in_Position", positionNameInIBufferable),
                   switches)
        {
            this.Name = this.GetType().Name;

            this.positionNameInIBufferable = positionNameInIBufferable;
            var uniformHighlightColor = new UniformVec4("highlightColor");

            //another way: uniform.SetValue(new vec4(1, 1, 1, 1));
            uniformHighlightColor.Value = new vec4(1, 1, 1, 1);
            this.UniformVariables.Add(uniformHighlightColor);
            this.UniformVariables.Add(this.uniformMVP);
            var polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Lines);

            this.SwitchList.Add(polygonModeSwitch);
            var lineWidthSwitch = new LineWidthSwitch(10.0f);

            this.SwitchList.Add(lineWidthSwitch);
            var pointSizeSwitch = new PointSizeSwitch(20.0f);

            this.SwitchList.Add(pointSizeSwitch);
            var polygonOffsetSwitch = new PolygonOffsetSwitch(PolugonOffset.Fill, true);

            this.SwitchList.Add(polygonOffsetSwitch);
            polygonOffsetSwitch = new PolygonOffsetSwitch(PolugonOffset.Point, true);
            this.SwitchList.Add(polygonOffsetSwitch);
        }
        /// <summary>
        /// 根据<see cref="IndexBufferPtr"/>的具体类型获取一个<see cref="PickableRenderer"/>
        /// </summary>
        /// <param name="bufferable"></param>
        /// <param name="propertyNameMap"></param>
        /// <param name="positionNameInIBufferable"></param>
        /// <param name="switches"></param>
        /// <returns></returns>
        public static InnerPickableRenderer GetRenderer(
            this IBufferable bufferable,
            PropertyNameMap propertyNameMap,
            string positionNameInIBufferable,
            params GLSwitch[] switches)
        {
            if (bufferable == null || propertyNameMap == null || string.IsNullOrEmpty(positionNameInIBufferable))
            {
                throw new ArgumentNullException();
            }

            IndexBufferPtr indexBufferPtr = bufferable.GetIndex();

            if (indexBufferPtr is ZeroIndexBufferPtr)
            {
                return(new ZeroIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches));
            }
            else if (indexBufferPtr is OneIndexBufferPtr)
            {
                return(new OneIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 9
0
 public OrderIndependentTransparencyRenderer(IBufferable model, vec3 lengths,
                                             string positionName, string normalName)
 {
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0]          = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1]          = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0]   = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1]   = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestSwitch = new DepthTestSwitch(false);
         this.cullFaceSwitch  = new CullFaceSwitch(false);
     }
     this.Lengths = lengths;
 }
Exemplo n.º 10
0
 private TerrainRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                         PropertyNameMap propertyNameMap, BoundingBox boundingBox, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.BoundingBox = boundingBox;
     this.PointColor  = Color.Green;
 }
Exemplo n.º 11
0
 private TrefoilKnotRenderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                             AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches)
     : base(model, shaderProgramProvider, attributeMap, positionNameInIBufferable, switches)
 {
     this.stateList.Add(new LineWidthState(3));
     this.stateList.Add(new PointSizeState(3));
 }
Exemplo n.º 12
0
        private static IBufferable GetModel(BuildInSceneObject buildIn)
        {
            IBufferable model = null;

            switch (buildIn)
            {
            case BuildInSceneObject.Cube:
                model = new Cube();
                break;

            case BuildInSceneObject.Sphere:
                model = new Sphere();
                break;

            case BuildInSceneObject.Ground:
                model = new Ground(1, groundXLength / 2, groundZLength / 2);
                break;

            case BuildInSceneObject.Axis:
                model = new Axis();
                break;

            default:
                throw new NotImplementedException();
            }

            return(model);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 用glDrarArrays进行渲染。
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal ZeroIndexRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                            PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                            params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
     this.Name = this.GetType().Name;
 }
Exemplo n.º 14
0
 private GroundRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                        PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.LineColor = Color.White;
     this.Scale     = 1.0f;
 }
Exemplo n.º 15
0
 private MovableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                         PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                         params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, "position")
 {
     this.Scale = 1.0f;
 }
        protected override void DoInitialize()
        {
            // init shader program.
            ShaderProgram program = this.shaderCodes.CreateProgram();

            VertexBuffer positionBuffer = null;
            IBufferable  model          = this.DataSource;

            VertexBuffer[] vertexAttributeBuffers;
            {
                var list = new List <VertexBuffer>();
                foreach (AttributeMap.NamePair item in this.attributeMap)
                {
                    VertexBuffer buffer = model.GetVertexAttributeBuffer(
                        item.NameInIBufferable, item.VarNameInShader);
                    if (buffer == null)
                    {
                        throw new Exception(string.Format("[{0}] returns null buffer pointer!", model));
                    }

                    if (item.NameInIBufferable == this.PositionNameInIBufferable)
                    {
                        positionBuffer = buffer.Clone() as VertexBuffer;
                        positionBuffer.VarNameInVertexShader = "in_Position";// in_Postion same with in the PickingShader.vert shader
                        break;
                    }
                    list.Add(buffer);
                }
                vertexAttributeBuffers = list.ToArray();
            }

            // 由于picking.vert/frag只支持vec3的position buffer,所以有此硬性规定。
            if (positionBuffer == null || positionBuffer.Config != VBOConfig.Vec3)
            {
                throw new Exception(string.Format("Position buffer must use a type composed of 3 float as PropertyBuffer<T>'s T!"));
            }

            // init index buffer.
            IndexBuffer indexBuffer = model.GetIndexBuffer();

            // RULE: Renderer takes uint.MaxValue, ushort.MaxValue or byte.MaxValue as PrimitiveRestartIndex. So take care this rule when designing a model's index buffer.
            var ptr = indexBuffer as OneIndexBuffer;

            if (ptr != null)
            {
                GLState glState = new PrimitiveRestartState(ptr.ElementType);
                this.stateList.Add(glState);
            }

            // init VAO.
            var vertexArrayObject = new VertexArrayObject(indexBuffer, positionBuffer);

            vertexArrayObject.Initialize(program);

            // sets fields.
            this.Program = program;
            this.vertexAttributeBuffers = new VertexBuffer[] { positionBuffer };
            this.indexBuffer            = indexBuffer;
            this.vertexArrayObject      = vertexArrayObject;
        }
Exemplo n.º 17
0
        List <PipelineStepContainer> _pipelineSteps = new List <PipelineStepContainer>(); // Reference to all steps

        public Pipeline <TPipelineIn, TPipelineOut> AddStepAndStart <TIn, TOut>(IPipelineProcessor <TIn, TOut> processor)
        {
            var step      = new PipelineStep <TIn, TOut>(processor);
            int stepIndex = _pipelineSteps.Count;

            // Alternatively, I can store a list of the Task.Run() handlers here and then run them at a later point
            // Start the step
            Task.Run(() =>
            {
                // Cached next step
                IBufferable <TOut> nextBuffer = null;

                foreach (Item <TIn> input in step.Buffer.GetConsumingEnumerable())
                {
                    // Give us the most up-to-date status on our current position in the pipeline
                    bool isLastStep = stepIndex == _pipelineSteps.Count - 1;

                    TOut outputValue;

                    // Attempt to process value
                    try
                    {
                        outputValue = processor.Process(input.Value);
                    }
                    catch (Exception e)
                    {
                        input.TaskCompletionSource.SetException(e);
                        continue;
                    }

                    // Move to next step
                    if (isLastStep)
                    {
                        input.TaskCompletionSource.SetResult((TPipelineOut)(object)outputValue);
                    }
                    else
                    {
                        nextBuffer = nextBuffer ?? _pipelineSteps[stepIndex + 1].Value as IBufferable <TOut>;
                        try // In the case of the pipeline closing prematurely, catch the error and throw an exception to the task
                        {
                            nextBuffer.Buffer.Add(new Item <TOut>
                            {
                                Value = outputValue,
                                TaskCompletionSource = input.TaskCompletionSource
                            });
                        }
                        catch (InvalidOperationException e)
                        {
                            input.TaskCompletionSource.SetException(e);
                        }
                    }
                }
            });
            _pipelineSteps.Add(new PipelineStepContainer
            {
                Value = step,
            });
            return(this);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="model">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="attributeMap">Mapping relations between 'in' variables in vertex shader in <see cref="shaderCodes"/> and buffers in <see cref="Model"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 public Renderer(IBufferable model, ShaderCode[] shaderCodes,
                 AttributeMap attributeMap, params GLSwitch[] switches)
 {
     this.Model        = model;
     this.shaderCodes  = shaderCodes;
     this.attributeMap = attributeMap;
     this.switchList.AddRange(switches);
 }
Exemplo n.º 19
0
 private BillboardRenderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                           AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderProgramProvider, attributeMap, switches)
 {
     this.Width      = 1.0f; this.Height = 0.125f;
     this.Percentage = new vec2(0.2f, 0.05f);
     this.PixelSize  = new ivec2(100, 10);
 }
Exemplo n.º 20
0
 private UniformArrayRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     var groundRenderer = GroundRenderer.Create(new GroundModel(20));
     groundRenderer.Scale = new vec3(10, 10, 10);
     this.groundRenderer = groundRenderer;
 }
Exemplo n.º 21
0
 public PointSpriteRenderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                            AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderProgramProvider, attributeMap, switches)
 {
     this.pointSpriteState = new PointSpriteState();
     this.stateList.Add(this.pointSpriteState);
     this.PointSpriteEnabled = true;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="bufferable">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="propertyNameMap">Mapping relations between 'in' variables in vertex shader in <see cref="shaderCodes"/> and buffers in <see cref="bufferable"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 public Renderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                 PropertyNameMap propertyNameMap, params GLSwitch[] switches)
 {
     this.bufferable      = bufferable;
     this.shaderCodes     = shaderCodes;
     this.propertyNameMap = propertyNameMap;
     this.switchList.AddRange(switches);
 }
Exemplo n.º 23
0
    private IBufferable InstantiateOneObject()
    {
        GameObject  obj        = GameObject.Instantiate(m_Prefab) as GameObject;
        IBufferable bufferable = obj.GetComponent <IBufferable>();

        bufferable.SetBufferGroup(this);
        return(bufferable);
    }
Exemplo n.º 24
0
 public BillboardRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                          PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.Width      = 1.0f; this.Height = 0.125f;
     this.Percentage = new vec2(0.2f, 0.05f);
     this.PixelSize  = new ivec2(100, 10);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="model">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderProgramProvider">All shader codes needed for this renderer.</param>
 /// <param name="attributeMap">Mapping relations between 'in' variables in vertex shader in <see cref="shaderProgramProvider"/> and buffers in <see cref="DataSource"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 public Renderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                 AttributeMap attributeMap, params GLState[] switches)
 {
     this.DataSource            = model;
     this.shaderProgramProvider = shaderProgramProvider;
     this.attributeMap          = attributeMap;
     this.stateList.AddRange(switches);
 }
Exemplo n.º 26
0
    private void CreateBaseObject(Vector3 pos, string name)
    {
        IBufferable bufferable = SimpleBuffer.GetObject(name);
        Transform   trm        = bufferable.GetTransform();

        trm.SetParent(this.GetTransform());
        trm.localPosition = pos;
    }
Exemplo n.º 27
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="model">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="attributeMap">Mapping relations between 'in' variables in vertex shader in <see cref="shaderCodes"/> and buffers in <see cref="DataSource"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 public Renderer(IBufferable model, ShaderCode[] shaderCodes,
                 AttributeMap attributeMap, params GLState[] switches)
 {
     this.DataSource   = model;
     this.shaderCodes  = shaderCodes;
     this.attributeMap = attributeMap;
     this.stateList.AddRange(switches);
 }
Exemplo n.º 28
0
 private BillboardRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     this.Width = 1.0f; this.Height = 0.125f;
     this.Percentage = new vec2(0.2f, 0.05f);
     this.PixelSize = new ivec2(100, 10);
 }
Exemplo n.º 29
0
 /// <summary>
 /// 支持"拾取"的渲染器
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 public PickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
         bufferable, propertyNameMap, positionNameInIBufferable);
     this.innerPickableRenderer = innerPickableRenderer;
 }
Exemplo n.º 30
0
        private UniformArrayRenderer(IBufferable model, ShaderCode[] shaderCodes,
                                     AttributeMap attributeMap, params GLState[] switches)
            : base(model, shaderCodes, attributeMap, switches)
        {
            var groundRenderer = GroundRenderer.Create(new GroundModel(20));

            groundRenderer.Scale = new vec3(10, 10, 10);
            this.groundRenderer  = groundRenderer;
        }
Exemplo n.º 31
0
 private HemisphereLightingRenderer(IBufferable model, ShaderCode[] shaderCodes,
                                    AttributeMap attributeMap, string positionNameInIBufferable,
                                    params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.LightPosition = new vec3(0, 2, 0);
     this.SkyColor      = new vec3(1, 0, 0);
     this.GroundColor   = new vec3(0, 1, 0);
 }
Exemplo n.º 32
0
        private UniformStructRenderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                                      AttributeMap attributeMap, params GLState[] switches)
            : base(model, shaderProgramProvider, attributeMap, switches)
        {
            var groundRenderer = GroundRenderer.Create(new GroundModel(20));

            groundRenderer.Scale = new vec3(10, 10, 10);
            this.groundRenderer  = groundRenderer;
        }
 private HemisphereLightingRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.LightPosition = new vec3(0, 2, 0);
     this.SkyColor = new vec3(1, 0, 0);
     this.GroundColor = new vec3(0, 1, 0);
 }
Exemplo n.º 34
0
 /// <summary>
 /// 支持"拾取"的渲染器
 /// </summary>
 /// <param name="model">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="attributeMap">关联<paramref name="model"/>和<paramref name="shaderCodes"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 public PickableRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
         model, attributeMap, positionNameInIBufferable);
     this.innerPickableRenderer = innerPickableRenderer;
 }
Exemplo n.º 35
0
        /// <summary>
        /// 支持"拾取"的渲染器
        /// </summary>
        /// <param name="bufferable">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<paramref name="bufferable"/>和<paramref name="shaderCodes"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public PickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                                PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                                params GLSwitch[] switches)
            : base(bufferable, shaderCodes, propertyNameMap, switches)
        {
            var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
                bufferable, propertyNameMap, positionNameInIBufferable);

            this.innerPickableRenderer = innerPickableRenderer;
        }
Exemplo n.º 36
0
        /// <summary>
        /// 支持"拾取"的渲染器
        /// </summary>
        /// <param name="model">一种渲染方式</param>
        /// <param name="shaderProgramProvider">各种类型的shader代码</param>
        /// <param name="attributeMap">关联<paramref name="model"/>和<paramref name="shaderProgramProvider"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public PickableRenderer(IBufferable model, IShaderProgramProvider shaderProgramProvider,
                                AttributeMap attributeMap, string positionNameInIBufferable,
                                params GLState[] switches)
            : base(model, shaderProgramProvider, attributeMap, switches)
        {
            var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
                model, attributeMap, positionNameInIBufferable);

            this.innerPickableRenderer = innerPickableRenderer;
        }
Exemplo n.º 37
0
        /// <summary>
        /// 用Shader+VBO(VAO)进行渲染。
        /// </summary>
        /// <param name="bufferable">将具体模型转换为可被OpenGL拿来渲染的格式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCodes"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public Renderer(IBufferable bufferable, ShaderCode[] shaderCodes,
            PropertyNameMap propertyNameMap, params GLSwitch[] switches)
        {
            this.Name = this.GetType().Name;

            this.bufferable = bufferable;
            this.shaderCodes = shaderCodes;
            this.propertyNameMap = propertyNameMap;
            this.switchList.AddRange(switches);
        }
Exemplo n.º 38
0
        /// <summary>
        /// 支持"拾取"的渲染器
        /// </summary>
        /// <param name="model">一种渲染方式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="attributeMap">关联<paramref name="model"/>和<paramref name="shaderCodes"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public PickableRenderer(IBufferable model, ShaderCode[] shaderCodes,
                                AttributeMap attributeMap, string positionNameInIBufferable,
                                params GLSwitch[] switches)
            : base(model, shaderCodes, attributeMap, switches)
        {
            var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
                model, attributeMap, positionNameInIBufferable);

            this.innerPickableRenderer = innerPickableRenderer;
        }
Exemplo n.º 39
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="VertexBufferPtr"/>和<see cref="ShaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 public ModernRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                       PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                       params GLSwitch[] switches)
 {
     this.bufferable                = bufferable;
     this.shaderCode                = shaderCodes;
     this.propertyNameMap           = propertyNameMap;
     this.positionNameInIBufferable = positionNameInIBufferable;
     this.switchList.AddRange(switches);
 }
Exemplo n.º 40
0
 private DirectonalLightRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.AmbientLightColor = new vec3(0.2f);
     this.DirectionalLightDirection = new vec3(1);
     this.DirectionalLightColor = new vec3(1);
     //this.HalfVector = new vec3(1);
     this.Shininess = 10.0f;
     this.Strength = 1.0f;
 }
Exemplo n.º 41
0
 private PointLightRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.Ambient = new vec3(0.2f);
     this.LightPosition = new vec3(400);
     this.LightColor = new vec3(1);
     //this.HalfVector = new vec3(1);
     this.Shininess = 10.0f;
     this.Strength = 1.0f;
     this.ConstantAttenuation = 0.2f;
     this.LinearAttenuation = 0.0f;
     this.QuadraticAttenuation = 0.0f;
 }
Exemplo n.º 42
0
 /// <summary>
 /// 支持"拾取"的渲染器
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal InnerPickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     {
         this.positionNameInIBufferable = positionNameInIBufferable;
     }
     {
         this.switchList.Add(polygonModeSwitch);
     }
     {
         float min, max;
         OpenGL.LineWidthRange(out min, out max);
         this.switchList.Add(new LineWidthSwitch(max));
     }
     {
         float min, max;
         OpenGL.PointSizeRange(out min, out max);
         this.switchList.Add(new PointSizeSwitch(max));
     }
 }
Exemplo n.º 43
0
 internal static SimpleRenderer Create(IBufferable model, vec3 lengths, string positionNameInIBufferable)
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Simple.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Simple.frag"), ShaderType.FragmentShader);
     var map = new AttributeMap();
     map.Add("in_Position", "position");
     map.Add("in_Color", "color");
     var renderer = new SimpleRenderer(model, shaderCodes, map, positionNameInIBufferable);
     renderer.ModelSize = lengths;
     return renderer;
 }
Exemplo n.º 44
0
 public ParticleRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
 }
Exemplo n.º 45
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <param name="shaderCodes"></param>
 /// <param name="attributeMap"></param>
 /// <param name="positionNameInIBufferable"></param>
 /// <param name="switches"></param>
 private LightRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable, params GLSwitch[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.LightDirection = new vec3(1, 1, 1);
 }
Exemplo n.º 46
0
 /// <summary>
 /// Rendering something using GLSL shader and VBO(VAO).
 /// </summary>
 /// <param name="model">model data that can be transfermed into OpenGL Buffer's pointer.</param>
 /// <param name="shaderCodes">All shader codes needed for this renderer.</param>
 /// <param name="attributeMap">Mapping relations between 'in' variables in vertex shader in <paramref name="shaderCodes"/> and buffers in <paramref name="model"/>.</param>
 ///<param name="switches">OpenGL switches.</param>
 private BoundingBoxRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     this.BoundingBoxColor = Color.White;
 }
 private AnalyzedPointSpriteRenderer(
     IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
 }
Exemplo n.º 48
0
 public BuildInRenderer(vec3 lengths, IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     this.ModelSize = lengths;
 }
Exemplo n.º 49
0
 /// <summary>
 /// 用glDrawElements进行渲染。
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal OneIndexRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
 }
Exemplo n.º 50
0
 private TextureRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
 }
Exemplo n.º 51
0
 private QuadStripRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
 }
Exemplo n.º 52
0
 public static BillboardRenderer Create(IBufferable model)
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\billboard.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\billboard.frag"), ShaderType.FragmentShader);
     var map = new AttributeMap();
     map.Add("in_Positions", BillboardModel.strPosition);
     var billboardRenderer = new BillboardRenderer(model, shaderCodes, map);
     return billboardRenderer;
 }