Beispiel #1
0
        public ModelBatch(int bufferSize, int indexBufferSize)
        {
            const int ShadowMapSize = 2048;

            GLUtilities.AllocateBuffers(bufferSize, indexBufferSize, out bufferId, out indexBufferId, GL_STATIC_DRAW);

            modelShader = new Shader();
            modelShader.Attach(ShaderTypes.Vertex, "ModelShadow.vert");
            modelShader.Attach(ShaderTypes.Fragment, "ModelShadow.frag");
            modelShader.AddAttribute <float>(3, GL_FLOAT);
            modelShader.AddAttribute <float>(2, GL_FLOAT);
            modelShader.AddAttribute <float>(3, GL_FLOAT);
            modelShader.CreateProgram();
            modelShader.Bind(bufferId, indexBufferId);
            modelShader.Use();
            modelShader.SetUniform("shadowSampler", 0);
            modelShader.SetUniform("textureSampler", 1);

            shadowMapShader = new Shader();
            shadowMapShader.Attach(ShaderTypes.Vertex, "ShadowMap.vert");
            shadowMapShader.Attach(ShaderTypes.Fragment, "ShadowMap.frag");
            shadowMapShader.AddAttribute <float>(3, GL_FLOAT, false, false, sizeof(float) * 5);
            shadowMapShader.CreateProgram();
            shadowMapShader.Bind(bufferId, indexBufferId);

            shadowMapTarget = new RenderTarget(ShadowMapSize, ShadowMapSize, RenderTargetFlags.Depth);
            defaultTexture  = ContentCache.GetTexture("Grey.png");
            handles         = new List <ModelHandle>();

            // These default values are arbitrary, just to make sure something shows up.
            LightDirection   = vec3.UnitX;
            LightColor       = Color.White;
            AmbientIntensity = 0.1f;
        }
Beispiel #2
0
        public SpriteBatch()
        {
            var accessor       = Properties.Access();
            var bufferCapacity = accessor.GetInt("sprite.batch.buffer.capacity");
            var indexCapacity  = accessor.GetInt("sprite.batch.index.capacity");

            buffer = new PrimitiveBuffer(bufferCapacity, indexCapacity);

            GLUtilities.AllocateBuffers(bufferCapacity, indexCapacity, out bufferId, out indexId, GL_DYNAMIC_DRAW);

            // These two shaders (owned by the sprite batch) can be completed here (in terms of binding a buffer).
            // External shaders are bound when first applied.
            spriteShader = new Shader(bufferId, indexId);
            spriteShader.Attach(ShaderTypes.Vertex, "Sprite.vert");
            spriteShader.Attach(ShaderTypes.Fragment, "Sprite.frag");
            spriteShader.AddAttribute <float>(2, GL_FLOAT);
            spriteShader.AddAttribute <float>(2, GL_FLOAT);
            spriteShader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, ShaderAttributeFlags.IsNormalized);
            spriteShader.Initialize();

            primitiveShader = new Shader(bufferId, indexId);
            primitiveShader.Attach(ShaderTypes.Vertex, "Primitives2D.vert");
            primitiveShader.Attach(ShaderTypes.Fragment, "Primitives.frag");
            primitiveShader.AddAttribute <float>(2, GL_FLOAT);
            primitiveShader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, ShaderAttributeFlags.IsNormalized);
            primitiveShader.Initialize();
        }
Beispiel #3
0
        public SpriteBatch()
        {
            const int BufferCapacity = 30000;
            const int IndexCapacity  = 3000;

            buffer = new PrimitiveBuffer(BufferCapacity, IndexCapacity);

            GLUtilities.AllocateBuffers(BufferCapacity, IndexCapacity, out bufferId, out indexBufferId,
                                        GL_DYNAMIC_DRAW);

            // These two shaders (owned by the sprite batch) can be completed here (in terms of binding a buffer).
            // External shaders are bound when first applied.
            spriteShader = new Shader();
            spriteShader.Attach(ShaderTypes.Vertex, "Sprite.vert");
            spriteShader.Attach(ShaderTypes.Fragment, "Sprite.frag");
            spriteShader.AddAttribute <float>(2, GL_FLOAT);
            spriteShader.AddAttribute <float>(2, GL_FLOAT);
            spriteShader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, false, true);
            spriteShader.CreateProgram();
            spriteShader.Bind(bufferId, indexBufferId);

            primitiveShader = new Shader();
            primitiveShader.Attach(ShaderTypes.Vertex, "Primitives2D.vert");
            primitiveShader.Attach(ShaderTypes.Fragment, "Primitives.frag");
            primitiveShader.CreateProgram();
            primitiveShader.AddAttribute <float>(2, GL_FLOAT);
            primitiveShader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, false, true);
            primitiveShader.Bind(bufferId, indexBufferId);

            MessageSystem.Subscribe(this, CoreMessageTypes.ResizeWindow, (messageType, data, dt) => { OnResize(); });
        }
Beispiel #4
0
        protected MeshRenderer(GlobalLight light, string property) : base(light)
        {
            var accessor       = Properties.Access();
            var bufferCapacity = accessor.GetInt(property + ".buffer.capacity");
            var indexCapacity  = accessor.GetInt(property + ".index.capacity");

            GLUtilities.AllocateBuffers(bufferCapacity, indexCapacity, out bufferId, out indexId, GL_STATIC_DRAW);
        }
        public PrimitiveRenderer3D(Camera3D camera, int bufferSize, int indexSize)
        {
            this.camera = camera;

            buffer = new PrimitiveBuffer(bufferSize, indexSize);

            GLUtilities.AllocateBuffers(bufferSize, indexSize, out bufferId, out indexId, GL_DYNAMIC_DRAW);

            shader = new Shader(bufferId, indexId);
            shader.Attach(ShaderTypes.Vertex, "Primitives3D.vert");
            shader.Attach(ShaderTypes.Fragment, "Primitives.frag");
            shader.AddAttribute <float>(3, GL_FLOAT);
            shader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, ShaderAttributeFlags.IsNormalized);
            shader.Initialize();
        }
Beispiel #6
0
        public PrimitiveRenderer3D(Camera3D camera)
        {
            const int BufferCapacity = 2048;
            const int IndexCapacity  = 256;

            this.camera = camera;

            buffer = new PrimitiveBuffer(BufferCapacity, IndexCapacity);

            GLUtilities.AllocateBuffers(BufferCapacity, IndexCapacity, out bufferId, out indexBufferId,
                                        GL_DYNAMIC_DRAW);

            primitiveShader = new Shader();
            primitiveShader.Attach(ShaderTypes.Vertex, "Primitives3D.vert");
            primitiveShader.Attach(ShaderTypes.Fragment, "Primitives.frag");
            primitiveShader.CreateProgram();
            primitiveShader.AddAttribute <float>(3, GL_FLOAT);
            primitiveShader.AddAttribute <byte>(4, GL_UNSIGNED_BYTE, true);
            primitiveShader.Bind(bufferId, indexBufferId);
        }
        public SkeletalTester()
        {
            const int ShadowMapSize = 2048;

            GLUtilities.AllocateBuffers(10000, 1000, out bufferId, out indexId, GL_STATIC_DRAW);

            skeletalShader = new Shader(bufferId, indexId);
            skeletalShader.Attach(ShaderTypes.Vertex, "Skeletal.vert");
            skeletalShader.Attach(ShaderTypes.Fragment, "ModelShadow.frag");
            skeletalShader.AddAttribute <float>(3, GL_FLOAT);
            skeletalShader.AddAttribute <float>(2, GL_FLOAT);
            skeletalShader.AddAttribute <float>(3, GL_FLOAT);
            skeletalShader.AddAttribute <float>(2, GL_FLOAT);
            skeletalShader.AddAttribute <short>(2, GL_SHORT, ShaderAttributeFlags.IsInteger);
            skeletalShader.AddAttribute <int>(1, GL_INT, ShaderAttributeFlags.IsInteger);
            skeletalShader.Initialize();
            skeletalShader.Use();
            skeletalShader.SetUniform("shadowSampler", 0);
            skeletalShader.SetUniform("textureSampler", 1);

            shadowMapShader = new Shader(bufferId, indexId);
            shadowMapShader.Attach(ShaderTypes.Vertex, "ShadowMapSkeletal.vert");
            shadowMapShader.Attach(ShaderTypes.Fragment, "ShadowMap.frag");
            shadowMapShader.AddAttribute <float>(3, GL_FLOAT, ShaderAttributeFlags.None, 20);
            shadowMapShader.AddAttribute <float>(2, GL_FLOAT);
            shadowMapShader.AddAttribute <short>(2, GL_SHORT, ShaderAttributeFlags.IsInteger);
            shadowMapShader.AddAttribute <int>(1, GL_INT, ShaderAttributeFlags.IsInteger);
            shadowMapShader.Initialize();

            shadowMapTarget = new RenderTarget(ShadowMapSize, ShadowMapSize, RenderTargetFlags.Depth);
            defaultTexture  = ContentCache.GetTexture("Grey.png");
            lightDirection  = -vec3.UnitY;

            model = new Model("Tree.dae");

            BufferMesh(model.Mesh);
        }
        public void Dispose()
        {
            shader.Dispose();

            GLUtilities.DeleteBuffers(bufferId, indexId);
        }
Beispiel #9
0
        public unsafe SpriteBatch3D(GlobalLight light) : base(light)
        {
            GLUtilities.GenerateBuffers(out bufferId, out indexId);

            shader = new Shader();
            shader.Attach(ShaderTypes.Vertex, "Sprite3D.vert");
            shader.Attach(ShaderTypes.Fragment, "Sprite3D.frag");
            shader.AddAttribute <float>(3, GL_FLOAT);
            shader.AddAttribute <float>(2, GL_FLOAT);

            Bind(bufferId, indexId);

            // Buffer vertex data.
            vec2[] points =
            {
                -vec2.Ones,
                new vec2(-1,  1),
                new vec2(1,  -1),
                vec2.Ones
            };

            // Dividing each point by two gives the entire quad a unit length of one.
            for (int i = 0; i < points.Length; i++)
            {
                points[i] /= 2;
            }

            // Modifying the source order causes sprites to appear the right way up (and not flipped horizontally).
            vec2[] sources =
            {
                vec2.UnitY,
                vec2.Zero,
                vec2.Ones,
                vec2.UnitX
            };

            float[] data = new float[20];

            for (int i = 0; i < points.Length; i++)
            {
                var p = points[i];
                var s = sources[i];

                int start = i * 5;

                data[start]     = p.x;
                data[start + 1] = p.y;
                data[start + 2] = 0;
                data[start + 3] = s.x;
                data[start + 4] = s.y;
            }

            glBindBuffer(GL_ARRAY_BUFFER, bufferId);

            fixed(float *address = &data[0])
            {
                glBufferData(GL_ARRAY_BUFFER, sizeof(float) * (uint)data.Length, address, GL_STATIC_DRAW);
            }

            // Buffer index data.
            ushort[] indices = new ushort[4];

            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = (ushort)i;
            }

            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);

            fixed(ushort *address = &indices[0])
            {
                glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ushort) * 4, address, GL_STATIC_DRAW);
            }
        }