/// <summary>
        ///
        /// </summary>
        /// <param name="transformFeedbackObj"></param>
        /// <param name="unit"></param>
        public static void Draw(this TransformFeedbackObject transformFeedbackObj, RenderUnit unit)
        {
            if (transformFeedbackObj == null || unit == null)
            {
                throw new ArgumentNullException();
            }

            transformFeedbackObj.Draw(unit.Program, unit.VertexArrayObject, unit.StateList);
        }
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.CameraStack.Peek();
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderUnit    unit    = this.RenderUnits[0];
            ShaderProgram program = unit.Program;

            program.SetUniform("projectionMatrix", projection);
            program.SetUniform("viewMatrix", view);
            program.SetUniform("modelMatrix", model);

            unit.Render();
        }
        protected override void DoInitialize()
        {
            base.DoInitialize();

            var bmp     = new Bitmap(@"KleinBottle.png");
            var texture = new Texture(TextureTarget.Texture1D,
                                      new TexImage2D(TexImage2D.Target.Texture2D, 0, GL.GL_RGBA, bmp.Width, bmp.Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)));

            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
            texture.Initialize();
            bmp.Dispose();

            RenderUnit    unit    = this.RenderUnits[0];
            ShaderProgram program = unit.Program;

            program.SetUniform("tex", texture);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public RenderUnit ToRenderUnit(IBufferSource model)
        {
            // init shader program.
            ShaderProgram program = this.programProvider.GetShaderProgram();

            // init vertex attribute buffer objects.
            VertexShaderAttribute[] vertexAttributeBuffers;
            {
                var list = new List <VertexShaderAttribute>();
                foreach (AttributeMap.NamePair item in this.map)
                {
                    VertexBuffer buffer = model.GetVertexAttributeBuffer(item.NameInIBufferSource);
                    if (buffer == null)
                    {
                        throw new Exception(string.Format("[{0}] returns null buffer pointer!", model));
                    }
                    list.Add(new VertexShaderAttribute(buffer, item.VarNameInShader));
                }
                vertexAttributeBuffers = list.ToArray();
            }

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

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

            var result = new RenderUnit(program, vertexArrayObject, this.states);

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

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

            return(result);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoInitialize()
        {
            foreach (var item in this.builders)
            {
                RenderUnit renderUnit = item.ToRenderUnit(this.model);
                this.renderUnits.Add(renderUnit);
            }

            {
                IPickableRenderUnit renderUnit = this.pickingRenderUnitBuilder.ToRenderUnit(this.model);
                if (renderUnit.VertexArrayObject.IndexBuffer is ZeroIndexBuffer)
                {
                    this.picker = new ZeroIndexPicker(this);
                }
                else if (renderUnit.VertexArrayObject.IndexBuffer is OneIndexBuffer)
                {
                    this.picker = new OneIndexPicker(this);
                }

                this.PickingRenderUnit = renderUnit;
            }
        }