예제 #1
0
        public async Task Initialize()
        {
            _context = await _canvasReference.CreateWebGLAsync(new WebGLContextAttributes
            {
                PowerPreference = WebGLContextAttributes.POWER_PREFERENCE_HIGH_PERFORMANCE
            });

            vertexBuffer = await _context.CreateBufferAsync();

            await _context.BindBufferAsync(BufferType.ARRAY_BUFFER, vertexBuffer);

            var program = await this.InitProgramAsync(this._context, VS_SOURCE, FS_SOURCE);

            var positionLocation = await _context.GetAttribLocationAsync(program, "aPos");

            var texcoordLocation = await _context.GetAttribLocationAsync(program, "aTex");

            await _context.VertexAttribPointerAsync((uint)positionLocation, 3, DataType.FLOAT, false, 6 *sizeof(float), 0);

            await _context.VertexAttribPointerAsync((uint)texcoordLocation, 2, DataType.FLOAT, false, 6 *sizeof(float), 3 *sizeof(float));

            await _context.EnableVertexAttribArrayAsync((uint)positionLocation);

            await _context.EnableVertexAttribArrayAsync((uint)texcoordLocation);

            await _context.UseProgramAsync(program);

            var texture = await _context.CreateTextureAsync();

            await _context.BindTextureAsync(TextureType.TEXTURE_2D, texture);
        }
예제 #2
0
        public async Task <GLBuffer <TBufferObject, TBufferType> > ConsumeAndBindBufferAsync(TBufferObject obj)
        {
            ResetObject();

            var buffer = await _context.CreateBufferAsync();

            await _context.BindBufferAsync(_bufferType, buffer);             // select

            await _context.BufferDataAsync(_bufferType, GetBuffer(obj), _bufferUsageHint);

            await PostProcessBufferAsync(obj, buffer);

            LastState     = LastStateType.Success;
            GLObjectValue = buffer;

            return(this);
        }
예제 #3
0
        public async Task BindToAttributeAsync(uint attribute)
        {
            await _gl.BindBufferAsync(BufferType.ARRAY_BUFFER, _dataBuffer);

            await _gl.EnableVertexAttribArrayAsync(attribute);

            await _gl.VertexAttribPointerAsync(attribute, _size, DataType.FLOAT, false, 0, 0);
        }
예제 #4
0
        public async static Task <VBO> BuildAsync(WebGLContext gl, int count, float[] data)
        {
            var dataBuffer = await gl.CreateBufferAsync();

            await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, dataBuffer);

            await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, data, BufferUsageHint.STATIC_DRAW);

            return(new VBO(gl, count, data, dataBuffer));
        }
        private static async void InitStaticBuffer(WebGLContext gl)
        {
            vertexBuffer = await gl.CreateBufferAsync();

            await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, vertexBuffer);

            {
                var vertexArrayDef = new[] {
                    -0.5f, 0.5f,
                    0.5f, 0.5f,
                    0.5f, -0.5f,
                    -0.5f, -0.5f,
                };

                await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, vertexArrayDef, BufferUsageHint.STATIC_DRAW);

                await gl.EnableVertexAttribArrayAsync(shader.PositionAttributeLocaltion);

                await gl.VertexAttribPointerAsync(shader.PositionAttributeLocaltion, 2, DataType.FLOAT, false, sizeof(float) * 2, 0);
            }

            texBuffer = await gl.CreateBufferAsync();

            await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, texBuffer);

            {
                var texArrayDef = new[]
                {
                    0, 0,
                    1, 0,
                    1, 1,
                    0, 1
                };

                await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, texArrayDef, BufferUsageHint.STATIC_DRAW);

                await gl.EnableVertexAttribArrayAsync(shader.TexturePositionAttributeLocaltion);

                await gl.VertexAttribPointerAsync(shader.TexturePositionAttributeLocaltion, 2, DataType.FLOAT, false, sizeof(float) * 2, 0);
            }
        }