Exemplo n.º 1
0
 private VBO(WebGLContext gl, int count, float[] data, WebGLBuffer dataBuffer)
 {
     _gl         = gl;
     _count      = count;
     _size       = data.Length / count;
     _dataBuffer = dataBuffer;
 }
        public void Run()
        {
            InitContextAttributes();

            gl = new WebGL2RenderingContext(canvas, contextAttributes);

            var vertexShaderCode =
                @"#version 300 es
in vec4 aPos;
void main(void) 
{
   gl_PointSize = 20.;
   gl_Position = vec4(-aPos.x, aPos.yzw);
}
";

            var fragmentShaderCode =
                @"#version 300 es
precision highp float;
out vec4 fragColor;
void main(void)
{
    fragColor = vec4(1., 0., 0., 1. );
}
";
            var vertexShader = GLExtensions.GetShader(
                gl,
                vertexShaderCode,
                WebGLRenderingContextBase.VERTEX_SHADER);
            var fragmentShader = GLExtensions.GetShader(
                gl,
                fragmentShaderCode,
                WebGLRenderingContextBase.FRAGMENT_SHADER);

            var shaderProgram = gl.CreateProgram();

            gl.AttachShader(shaderProgram, vertexShader);
            gl.AttachShader(shaderProgram, fragmentShader);
            gl.TransformFeedbackVaryings(
                shaderProgram,
                new string[] { "gl_Position" },
                WebGL2RenderingContextBase.SEPARATE_ATTRIBS);
            gl.LinkProgram(shaderProgram);
            gl.UseProgram(shaderProgram);

            aPosLoc = (uint)gl.GetAttribLocation(shaderProgram, "aPos");
            gl.EnableVertexAttribArray(aPosLoc);

            var bufAData = new float[] { 0.8f, 0, 0, 1 };

            bufA = gl.CreateArrayBufferWithUsage(bufAData, WebGL2RenderingContextBase.DYNAMIC_COPY);

            var bufBData = new float[4 * 4];

            bufB = gl.CreateArrayBufferWithUsage(bufBData, WebGL2RenderingContextBase.DYNAMIC_COPY);

            var transformFeedback = gl.CreateTransformFeedback();

            gl.BindTransformFeedback(WebGL2RenderingContextBase.TRANSFORM_FEEDBACK, transformFeedback);
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        public virtual void dispose()
        {
            if (this._vertexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                this._vertexBuffer = null;
            }

            if (this._indexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                this._indexBuffer = null;
            }

            if (this.texture != null)
            {
                this.texture.dispose();
                this.texture = null;
            }

            var index = this._scene.layers.IndexOf(this);

            this._scene.layers.RemoveAt(index);
            if (this.onDispose != null)
            {
                this.onDispose();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="mesh">
        /// </param>
        /// <param name="shouldDispose">
        /// </param>
        public virtual void releaseForMesh(Mesh mesh, bool shouldDispose = false)
        {
            var meshes = this._meshes;
            var index  = meshes.IndexOf(mesh);

            if (index == -1)
            {
                return;
            }

            foreach (var kind in this._vertexBuffers.Keys)
            {
                this._vertexBuffers[kind].dispose();
            }

            if (this._indexBuffer != null && this._engine._releaseBuffer(this._indexBuffer))
            {
                this._indexBuffer = null;
            }

            meshes.RemoveAt(index);
            mesh._geometry = null;
            if (meshes.Length == 0 && shouldDispose)
            {
                this.dispose();
            }
        }
Exemplo n.º 5
0
        public void Draw()
        {
            if (!shouldDraw)
            {
                return;
            }

            gl.Enable(WebGLRenderingContextBase.DEPTH_TEST);

            gl.Viewport(0, 0, canvasWidth, canvasHeight);

            gl.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W);
            gl.Clear(WebGLRenderingContextBase.COLOR_BUFFER_BIT);

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, bufA);
            gl.VertexAttribPointer(aPosLoc, 4, WebGLRenderingContextBase.FLOAT, false, 0, 0);
            gl.BindBufferBase(WebGL2RenderingContextBase.TRANSFORM_FEEDBACK_BUFFER, 0, bufB);

            gl.BeginTransformFeedback(WebGLRenderingContextBase.POINTS);
            gl.DrawArrays(WebGLRenderingContextBase.POINTS, 0, 1);
            gl.EndTransformFeedback();

            gl.BindBufferBase(WebGL2RenderingContextBase.TRANSFORM_FEEDBACK_BUFFER, 0, null);
            var t = bufA;

            bufA = bufB;
            bufB = t;

            shouldDraw = false;
        }
Exemplo n.º 6
0
        void IDualityBackend.Shutdown()
        {
            if (activeInstance == this)
            {
                activeInstance = null;
            }

            if (DualityApp.ExecContext != DualityApp.ExecutionContext.Terminated)
            {
                for (int i = 0; i < this.perVertexTypeVBO.Count; i++)
                {
                    WebGLBuffer handle = this.perVertexTypeVBO[i];
                    if (handle != null)
                    {
                        GL.DeleteBuffer(handle);
                    }
                }
                this.perVertexTypeVBO.Clear();

                for (int i = 0; i < this.perBatchEBO.Count; i++)
                {
                    WebGLBuffer handle = this.perBatchEBO[i];
                    if (handle != null)
                    {
                        GL.DeleteBuffer(handle);
                    }
                }
                this.perBatchEBO.Clear();
            }
        }
Exemplo n.º 7
0
        public void Unlock()
        {
            VertexBuffer = Tile.PrepDevice.createBuffer();
            Tile.PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
            Float32Array f32array = new Float32Array(Count * 19);

            float[] buffer = (float[])(object)f32array;
            int     index  = 0;

            foreach (KeplerVertex pt in verts)
            {
                buffer[index++] = (float)pt.ABC.X;
                buffer[index++] = (float)pt.ABC.Y;
                buffer[index++] = (float)pt.ABC.Z;
                buffer[index++] = (float)pt.abc1.X;
                buffer[index++] = (float)pt.abc1.Y;
                buffer[index++] = (float)pt.abc1.Z;
                buffer[index++] = (float)pt.PointSize;
                buffer[index++] = (float)pt.Color.R / 255;
                buffer[index++] = (float)pt.Color.G / 255;
                buffer[index++] = (float)pt.Color.B / 255;
                buffer[index++] = (float)pt.Color.A / 255;
                buffer[index++] = (float)pt.w;
                buffer[index++] = (float)pt.e;
                buffer[index++] = (float)pt.n;
                buffer[index++] = (float)pt.T;
                buffer[index++] = (float)pt.a;
                buffer[index++] = (float)pt.z;
                buffer[index++] = (float)pt.orbitPos;
                buffer[index++] = (float)pt.orbits;
            }

            Tile.PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);
        }
Exemplo n.º 8
0
        public static void Use(RenderContext renderContext, WebGLBuffer vertex)
        {
            GL gl = renderContext.gl;

            if (gl != null)
            {
                if (!initialized)
                {
                    Init(renderContext);
                }

                gl.useProgram(prog);

                Matrix3d mvMat = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View);

                gl.uniformMatrix4fv(mvMatLoc, false, mvMat.FloatArray());
                gl.uniformMatrix4fv(projMatLoc, false, renderContext.Projection.FloatArray());
                gl.uniform1i(sampLoc, 0);

                gl.disable(GL.DEPTH_TEST);

                gl.enableVertexAttribArray(vertLoc);
                gl.enableVertexAttribArray(textureLoc);
                gl.enableVertexAttribArray(colorLoc);
                gl.bindBuffer(GL.ARRAY_BUFFER, vertex);
                gl.vertexAttribPointer(vertLoc, 3, GL.FLOAT, false, 36, 0);
                gl.vertexAttribPointer(colorLoc, 4, GL.FLOAT, false, 36, 12);
                gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
                gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// </summary>
        /// <param name="name">
        /// </param>
        /// <param name="imgUrl">
        /// </param>
        /// <param name="scene">
        /// </param>
        /// <param name="isBackground">
        /// </param>
        /// <param name="color">
        /// </param>
        public Layer(string name, string imgUrl, Scene scene, bool isBackground = false, Color4 color = null)
        {
            this.name         = name;
            this.texture      = (imgUrl != null) ? new Texture(imgUrl, scene, true) : null;
            this.isBackground = isBackground;
            this.color        = (color == null) ? new Color4(1, 1, 1, 1) : color;
            this._scene       = scene;
            this._scene.layers.Add(this);
            var vertices = new Array <double>();

            vertices.Add(1, 1);
            vertices.Add(-1, 1);
            vertices.Add(-1, -1);
            vertices.Add(1, -1);
            this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
            var indices = new Array <int>();

            indices.Add(0);
            indices.Add(1);
            indices.Add(2);
            indices.Add(0);
            indices.Add(2);
            indices.Add(3);
            this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
            this._effect      = this._scene.getEngine()
                                .createEffect(
                new EffectBaseName {
                baseName = "layer"
            },
                new Array <string>("position"),
                new Array <string>("textureMatrix", "color"),
                new Array <string>("textureSampler"),
                string.Empty);
        }
Exemplo n.º 10
0
        /// <summary>
        /// </summary>
        /// <param name="doNotRecurse">
        /// </param>
        public virtual void dispose(bool doNotRecurse = false)
        {
            if (this._vertexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                this._vertexBuffer = null;
            }

            if (this._indexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                this._indexBuffer = null;
            }

            if (this.particleTexture != null)
            {
                this.particleTexture.dispose();
                this.particleTexture = null;
            }

            var index = this._scene.particleSystems.IndexOf(this);

            this._scene.particleSystems.RemoveAt(index);
            if (this.onDispose != null)
            {
                this.onDispose();
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public void Unlock()
        {
            VertexBuffer = Tile.PrepDevice.createBuffer();
            Tile.PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
            Float32Array f32array = new Float32Array(Count * 10);

            float[] buffer = (float[])(object)f32array;
            int     index  = 0;

            foreach (TimeSeriesPointVertex pt in verts)
            {
                buffer[index++] = (float)pt.Position.X;
                buffer[index++] = (float)pt.Position.Y;
                buffer[index++] = (float)pt.Position.Z;
                buffer[index++] = (float)pt.Color.R / 255.0f;
                buffer[index++] = (float)pt.Color.G / 255.0f;
                buffer[index++] = (float)pt.Color.B / 255.0f;
                buffer[index++] = (float)pt.Color.A / 255.0f;
                buffer[index++] = (float)pt.Tu;
                buffer[index++] = (float)pt.Tv;
                buffer[index++] = (float)pt.PointSize;
            }

            Tile.PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);
        }
Exemplo n.º 13
0
        /// <summary>
        /// </summary>
        /// <param name="data">
        /// </param>
        public virtual void create(Array <double> data = null)
        {
            if (data == null && this._buffer != null)
            {
                return;
            }

            data = data ?? this._data;
            if (this._buffer == null)
            {
                if (this._updatable)
                {
                    this._buffer = this._engine.createDynamicVertexBuffer(data.Length * 4);
                }
                else
                {
                    this._buffer = this._engine.createVertexBuffer(data);
                }
            }

            if (this._updatable)
            {
                this._engine.updateDynamicVertexBuffer(this._buffer, data);
                this._data = data;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// </summary>
        /// <param name="name">
        /// </param>
        /// <param name="emitter">
        /// </param>
        /// <param name="scene">
        /// </param>
        public LensFlareSystem(string name, object emitter, Scene scene)
        {
            this.name     = name;
            this._scene   = scene;
            this._emitter = emitter;
            scene.lensFlareSystems.Add(this);
            this.meshesSelectionPredicate =
                (m) => m.material != null && m.isVisible && m.isEnabled() && m.checkCollisions && ((m.layerMask & scene.activeCamera.layerMask) != 0);
            var vertices = new Array <double>();

            vertices.Add(1, 1);
            vertices.Add(-1, 1);
            vertices.Add(-1, -1);
            vertices.Add(1, -1);
            this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
            var indices = new Array <int>();

            indices.Add(0);
            indices.Add(1);
            indices.Add(2);
            indices.Add(0);
            indices.Add(2);
            indices.Add(3);
            this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
            this._effect      = this._scene.getEngine()
                                .createEffect(
                new EffectBaseName {
                baseName = "lensFlare"
            },
                new Array <string>("position"),
                new Array <string>("color", "viewportMatrix"),
                new Array <string>("textureSampler"),
                string.Empty);
        }
Exemplo n.º 15
0
        public void record()
        {
            //记录状态
            this.DEPTH_WRITEMASK = (bool)this.webgl.GetParameter(this.webgl.DEPTH_WRITEMASK);
            this.DEPTH_TEST      = (bool)this.webgl.GetParameter(this.webgl.DEPTH_TEST);
            this.DEPTH_FUNC      = (int)this.webgl.GetParameter(this.webgl.DEPTH_FUNC);
            //alphablend ,跟着mat走
            this.BLEND           = (bool)this.webgl.GetParameter(this.webgl.BLEND);
            this.BLEND_EQUATION  = (int)this.webgl.GetParameter(this.webgl.BLEND_EQUATION);
            this.BLEND_SRC_RGB   = (int)this.webgl.GetParameter(this.webgl.BLEND_SRC_RGB);
            this.BLEND_SRC_ALPHA = (int)this.webgl.GetParameter(this.webgl.BLEND_SRC_ALPHA);
            this.BLEND_DST_RGB   = (int)this.webgl.GetParameter(this.webgl.BLEND_DST_RGB);
            this.BLEND_DST_ALPHA = (int)this.webgl.GetParameter(this.webgl.BLEND_DST_ALPHA);
            //    this.webgl.blendFuncSeparate(this.webgl.ONE, this.webgl.ONE_MINUS_SRC_ALPHA,
            //        this.webgl.SRC_ALPHA, this.webgl.ONE);

            var p = this.webgl.GetParameter(this.webgl.CURRENT_PROGRAM);

            this.CURRENT_PROGRAM = p.As <WebGLProgram>();

            var pb = this.webgl.GetParameter(this.webgl.ARRAY_BUFFER_BINDING);

            this.ARRAY_BUFFER = pb.As <WebGLBuffer>();

            this.ACTIVE_TEXTURE     = (int)this.webgl.GetParameter(this.webgl.ACTIVE_TEXTURE);
            this.TEXTURE_BINDING_2D = this.webgl.GetParameter(this.webgl.TEXTURE_BINDING_2D).As <WebGLTexture>();
        }
Exemplo n.º 16
0
        /// <summary>
        /// </summary>
        /// <param name="mesh">
        /// </param>
        private void _applyToMesh(Mesh mesh)
        {
            var numOfMeshes = this._meshes.Length;

            foreach (var kind in this._vertexBuffers.Keys)
            {
                if (numOfMeshes == 1)
                {
                    this._vertexBuffers[kind].create();
                }

                this._vertexBuffers[kind]._buffer.references = numOfMeshes;
                if (kind == VertexBufferKind.PositionKind)
                {
                    mesh._resetPointsArrayCache();
                    var extend = Tools.ExtractMinAndMax(this._vertexBuffers[kind].getData(), 0, this._totalVertices);
                    mesh._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);
                    mesh._createGlobalSubMesh();
                }
            }

            if (numOfMeshes == 1 && this._indices != null)
            {
                this._indexBuffer = this._engine.createIndexBuffer(this._indices);
            }

            if (this._indexBuffer != null)
            {
                this._indexBuffer.references = numOfMeshes;
            }
        }
Exemplo n.º 17
0
 public override void Destroy()
 {
     if (buffer != null)
     {
         GL.deleteBuffer(buffer);
         buffer = null;
     }
 }
Exemplo n.º 18
0
 internal override void Bind()
 {
     if (buffer != currentlyBoundIndexBuffer)
     {
         GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, buffer);
         currentlyBoundIndexBuffer = buffer;
     }
 }
Exemplo n.º 19
0
 internal override void Bind()
 {
     if (buffer != currentlyBoundVertexBuffer)
     {
         GL.bindBuffer(GL.ARRAY_BUFFER, buffer);
         currentlyBoundVertexBuffer = buffer;
     }
 }
 public void bindBufferBase(decimal target, decimal index, WebGLBuffer buffer = null)
 {
     EventHorizonBlazorInterop.Func <CachedEntity>(
         new object[]
     {
         new string[] { this.___guid, "bindBufferBase" }, target, index, buffer
     }
         );
 }
Exemplo n.º 21
0
 internal void DisposeBuffer(WebGLBuffer handle)
 {
     if (!_isDisposed)
     {
         lock (_disposeActionsLock)
         {
             _disposeNextFrame.Add(ResourceHandle.Buffer(handle));
         }
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// </summary>
        /// <param name="subMesh">
        /// </param>
        /// <param name="wireFrame">
        /// </param>
        /// <param name="batch">
        /// </param>
        /// <param name="effect">
        /// </param>
        /// <param name="engine">
        /// </param>
        public virtual void _renderWithInstances(SubMesh subMesh, bool wireFrame, _InstancesBatch batch, Effect effect, Engine engine)
        {
            var matricesCount = this.instances.Length + 1;
            var bufferSize    = matricesCount * 16 * 4;

            while (this._instancesBufferSize < bufferSize)
            {
                this._instancesBufferSize *= 2;
            }

            if (this._worldMatricesInstancesBuffer == null || this._worldMatricesInstancesBuffer.capacity < this._instancesBufferSize)
            {
                if (this._worldMatricesInstancesBuffer != null)
                {
                    engine.deleteInstancesBuffer(this._worldMatricesInstancesBuffer);
                }

                this._worldMatricesInstancesBuffer = engine.createInstancesBuffer(this._instancesBufferSize);
                this._worldMatricesInstancesArray  = new double[this._instancesBufferSize / 4];
            }

            var offset         = 0;
            var instancesCount = 0;
            var world          = this.getWorldMatrix();

            if (batch.renderSelf[subMesh._id])
            {
                world.copyToArray(this._worldMatricesInstancesArray, offset);
                offset += 16;
                instancesCount++;
            }

            var visibleInstances = batch.visibleInstances[subMesh._id];

            if (visibleInstances != null)
            {
                for (var instanceIndex = 0; instanceIndex < visibleInstances.Length; instanceIndex++)
                {
                    var instance = visibleInstances[instanceIndex];
                    instance.getWorldMatrix().copyToArray(this._worldMatricesInstancesArray, offset);
                    offset += 16;
                    instancesCount++;
                }
            }

            var offsetLocation0 = effect.getAttributeLocationByName("world0");
            var offsetLocation1 = effect.getAttributeLocationByName("world1");
            var offsetLocation2 = effect.getAttributeLocationByName("world2");
            var offsetLocation3 = effect.getAttributeLocationByName("world3");
            var offsetLocations = new Array <int>(offsetLocation0, offsetLocation1, offsetLocation2, offsetLocation3);

            engine.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer, this._worldMatricesInstancesArray, offsetLocations);
            this._draw(subMesh, !wireFrame, instancesCount);
            engine.unBindInstancesBuffer(this._worldMatricesInstancesBuffer, offsetLocations);
        }
Exemplo n.º 23
0
        public static void Use(RenderContext renderContext, WebGLBuffer vertex, WebGLTexture texture, Color lineColor, bool zBuffer, float jNow, float decay, Vector3d camera, float scale)
        {
            GL gl = renderContext.gl;

            if (gl != null)
            {
                if (!initialized)
                {
                    Init(renderContext);
                }

                gl.useProgram(prog);

                Matrix3d mvMat = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View);

                gl.uniformMatrix4fv(mvMatLoc, false, mvMat.FloatArray());
                gl.uniformMatrix4fv(projMatLoc, false, renderContext.Projection.FloatArray());
                gl.uniform1i(sampLoc, 0);
                gl.uniform1f(jNowLoc, jNow);
                gl.uniform1f(decayLoc, decay);
                gl.uniform4f(lineColorLoc, lineColor.R / 255f, lineColor.G / 255f, lineColor.B / 255f, 1f);
                gl.uniform3f(cameraPosLoc, (float)camera.X, (float)camera.Y, (float)camera.Z);
                gl.uniform1f(scaleLoc, scale);
                if (zBuffer)
                {
                    gl.enable(GL.DEPTH_TEST);
                }
                else
                {
                    gl.disable(GL.DEPTH_TEST);
                }
                //gl.enable(0x8642);
                gl.disableVertexAttribArray(0);
                gl.disableVertexAttribArray(1);
                gl.disableVertexAttribArray(2);
                gl.disableVertexAttribArray(3);


                gl.enableVertexAttribArray(vertLoc);
                gl.enableVertexAttribArray(colorLoc);
                gl.enableVertexAttribArray(pointSizeLoc);
                gl.enableVertexAttribArray(timeLoc);

                gl.bindBuffer(GL.ARRAY_BUFFER, vertex);
                gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
                gl.vertexAttribPointer(vertLoc, 3, GL.FLOAT, false, 40, 0);
                gl.vertexAttribPointer(colorLoc, 4, GL.FLOAT, false, 40, 12);
                gl.vertexAttribPointer(pointSizeLoc, 1, GL.FLOAT, false, 40, 36);
                gl.vertexAttribPointer(timeLoc, 2, GL.FLOAT, false, 40, 28);
                gl.activeTexture(GL.TEXTURE0);
                gl.bindTexture(GL.TEXTURE_2D, texture);
                gl.lineWidth(1.0f);
                gl.blendFunc(GL.SRC_ALPHA, GL.ONE);
            }
        }
Exemplo n.º 24
0
 public void Dispose()
 {
     if (DualityApp.ExecContext != DualityApp.ExecutionContext.Terminated &&
         this.handle != null)
     {
         //DefaultOpenTKBackendPlugin.GuardSingleThreadState();
         GraphicsBackend.GL.DeleteBuffer(this.handle);
     }
     this.handle     = null;
     this.bufferSize = 0;
 }
Exemplo n.º 25
0
        /// <summary>
        /// </summary>
        public virtual void dispose()
        {
            if (this._buffer == null)
            {
                return;
            }

            if (this._engine._releaseBuffer(this._buffer))
            {
                this._buffer = null;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// </summary>
        public virtual void dispose()
        {
            if (this._linesIndexBuffer != null)
            {
                this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);
                this._linesIndexBuffer = null;
            }

            var index = this._mesh.subMeshes.IndexOf(this);

            this._mesh.subMeshes.RemoveAt(index);
        }
        /// <summary>
        /// </summary>
        public virtual void dispose()
        {
            if (this._vertexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
                this._vertexBuffer = null;
            }

            if (this._indexBuffer != null)
            {
                this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                this._indexBuffer = null;
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// </summary>
        /// <param name="name">
        /// </param>
        /// <param name="imgUrl">
        /// </param>
        /// <param name="capacity">
        /// </param>
        /// <param name="cellSize">
        /// </param>
        /// <param name="scene">
        /// </param>
        /// <param name="epsilon">
        /// </param>
        public SpriteManager(string name, string imgUrl, int capacity, int cellSize, Scene scene, double epsilon = 0.01)
        {
            this.name                 = name;
            this.cellSize             = cellSize;
            this._capacity            = capacity;
            this._spriteTexture       = new Texture(imgUrl, scene, true, false);
            this._spriteTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
            this._spriteTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
            this._epsilon             = epsilon;
            this._scene               = scene;
            this._scene.spriteManagers.Add(this);
            this._vertexDeclaration = new Array <VertexBufferKind>(
                VertexBufferKind.UVKind, VertexBufferKind.UV2Kind, VertexBufferKind.UV2Kind, VertexBufferKind.UV2Kind);
            this._vertexStrideSize = 15 * 4;
            this._vertexBuffer     = scene.getEngine().createDynamicVertexBuffer(capacity * this._vertexStrideSize * 4);
            var indices = new Array <int>();
            var index   = 0;

            for (var count = 0; count < capacity; count++)
            {
                indices.Add(index);
                indices.Add(index + 1);
                indices.Add(index + 2);
                indices.Add(index);
                indices.Add(index + 2);
                indices.Add(index + 3);
                index += 4;
            }

            this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
            this._vertices    = new double[capacity * this._vertexStrideSize];
            this._effectBase  = this._scene.getEngine()
                                .createEffect(
                new EffectBaseName {
                baseName = "sprites"
            },
                new Array <string>("position", "options", "cellInfo", "color"),
                new Array <string>("view", "projection", "textureInfos", "alphaTest"),
                new Array <string>("diffuseSampler"),
                string.Empty);
            this._effectFog = this._scene.getEngine()
                              .createEffect(
                new EffectBaseName {
                baseName = "sprites"
            },
                new Array <string>("position", "options", "cellInfo", "color"),
                new Array <string>("view", "projection", "textureInfos", "alphaTest", "vFogInfos", "vFogColor"),
                new Array <string>("diffuseSampler"),
                "#define FOG");
        }
Exemplo n.º 29
0
        /// <summary>
        /// If the IBO does not exist, create it.
        /// </summary>
        void GenerateIfRequired()
        {
            if (ibo == null)
            {
                var sizeInBytes = IndexCount * (this.IndexElementSize == IndexElementSize.SixteenBits ? 2 : 4);

                ibo = gl.createBuffer();
                GraphicsExtensions.CheckGLError();
                gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
                GraphicsExtensions.CheckGLError();
                gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array(0), _isDynamic ? gl.STREAM_DRAW : gl.STATIC_DRAW);
                GraphicsExtensions.CheckGLError();
            }
        }
Exemplo n.º 30
0
        public void bindBuffer(int target, WebGLBuffer buffer)
        {
            var bufferId = (int)(buffer != null ? buffer.Value : 0);

#if _DEBUG
            Log.Info(string.Format("bindBuffer {0} {1}", target, bufferId));
#endif

#if GLEW_STATIC
            Gl.glBindBuffer(target, bufferId);
#else
            Gl.__glewBindBuffer(target, bufferId);
#endif
            this.ErrorTest();
        }
        public WebGL15ContextImpl()
            : base(100, 100)
        {
            gl = null;
#endif
            if (gl == null)
                throw new Exception("UnsupportedOperationException: WebGL N/A");
            InitShaders(); CheckError("initShader");
            _elementBuffer = gl.CreateBuffer(); CheckError("createBuffer f. elements");
            for (int index = 0; index < _buffers.Length; index++)
            {
                WebGLBufferData b = new WebGLBufferData();
                b.ToBind = null;
                b.Buffer = gl.CreateBuffer(); CheckError("createBuffer" + index);
                b.Stride = 0;
                b.Size = 0;
                b.Type = 0;
                b.ByteSize = 0;
                b.Normalized = false;
                _buffers[index] = b;
            }
        }
Exemplo n.º 32
0
 public void bindBuffer(int target, WebGLBuffer buffer) { }
Exemplo n.º 33
0
        public void InitBuffers()
        {
            this.cubeVertexPositionBuffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);

            var vertices = new double[] {
                // Front face
                -1.0, -1.0,  1.0,
                 1.0, -1.0,  1.0,
                 1.0,  1.0,  1.0,
                -1.0,  1.0,  1.0,

                // Back face
                -1.0, -1.0, -1.0,
                -1.0,  1.0, -1.0,
                 1.0,  1.0, -1.0,
                 1.0, -1.0, -1.0,

                // Top face
                -1.0,  1.0, -1.0,
                -1.0,  1.0,  1.0,
                 1.0,  1.0,  1.0,
                 1.0,  1.0, -1.0,

                // Bottom face
                -1.0, -1.0, -1.0,
                 1.0, -1.0, -1.0,
                 1.0, -1.0,  1.0,
                -1.0, -1.0,  1.0,

                // Right face
                 1.0, -1.0, -1.0,
                 1.0,  1.0, -1.0,
                 1.0,  1.0,  1.0,
                 1.0, -1.0,  1.0,

                // Left face
                -1.0, -1.0, -1.0,
                -1.0, -1.0,  1.0,
                -1.0,  1.0,  1.0,
                -1.0,  1.0, -1.0,
            };

            gl.BufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);

            this.cubeVertexNormalBuffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ARRAY_BUFFER, cubeVertexNormalBuffer);

            var vertexNormals = new double[] {
                // Front face
                 0.0,  0.0,  1.0,
                 0.0,  0.0,  1.0,
                 0.0,  0.0,  1.0,
                 0.0,  0.0,  1.0,

                // Back face
                 0.0,  0.0, -1.0,
                 0.0,  0.0, -1.0,
                 0.0,  0.0, -1.0,
                 0.0,  0.0, -1.0,

                // Top face
                 0.0,  1.0,  0.0,
                 0.0,  1.0,  0.0,
                 0.0,  1.0,  0.0,
                 0.0,  1.0,  0.0,

                // Bottom face
                 0.0, -1.0,  0.0,
                 0.0, -1.0,  0.0,
                 0.0, -1.0,  0.0,
                 0.0, -1.0,  0.0,

                // Right face
                 1.0,  0.0,  0.0,
                 1.0,  0.0,  0.0,
                 1.0,  0.0,  0.0,
                 1.0,  0.0,  0.0,

                // Left face
                -1.0,  0.0,  0.0,
                -1.0,  0.0,  0.0,
                -1.0,  0.0,  0.0,
                -1.0,  0.0,  0.0
            };

            gl.BufferData(gl.ARRAY_BUFFER, new Float32Array(vertexNormals), gl.STATIC_DRAW);

            this.cubeVertexTextureCoordBuffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ARRAY_BUFFER, cubeVertexTextureCoordBuffer);

            var textureCoords = new double[] {
                // Front face
                0.0, 0.0,
                1.0, 0.0,
                1.0, 1.0,
                0.0, 1.0,

                // Back face
                1.0, 0.0,
                1.0, 1.0,
                0.0, 1.0,
                0.0, 0.0,

                // Top face
                0.0, 1.0,
                0.0, 0.0,
                1.0, 0.0,
                1.0, 1.0,

                // Bottom face
                1.0, 1.0,
                0.0, 1.0,
                0.0, 0.0,
                1.0, 0.0,

                // Right face
                1.0, 0.0,
                1.0, 1.0,
                0.0, 1.0,
                0.0, 0.0,

                // Left face
                0.0, 0.0,
                1.0, 0.0,
                1.0, 1.0,
                0.0, 1.0
            };

            gl.BufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);

            this.cubeVertexIndexBuffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);

            var cubeVertexIndices = new int[] {
                 0,  1,  2,    0,  2,  3,  // Front face
                 4,  5,  6,    4,  6,  7,  // Back face
                 8,  9, 10,    8, 10, 11,  // Top face
                12, 13, 14,   12, 14, 15,  // Bottom face
                16, 17, 18,   16, 18, 19,  // Right face
                20, 21, 22,   20, 22, 23   // Left face
            };

            gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
        }
 /// <summary>
 /// Delete a specific buffer.
 /// If a buffer has already been deleted, this method has no effect.
 /// </summary>
 /// <param name="buffer">The buffer to delete</param>
 public virtual void DeleteBuffer(WebGLBuffer buffer) { }
Exemplo n.º 35
0
 public void deleteBuffer(WebGLBuffer buffer) { }
 /// <summary>
 /// Associates a buffer with a buffer target.
 /// </summary>
 /// <param name="target">One of the following: gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER</param>
 /// <param name="buffer">A WebGLBuffer object to bind to target.</param>
 public virtual void BindBuffer(int target, WebGLBuffer buffer) { }
Exemplo n.º 37
0
 public bool isBuffer(WebGLBuffer buffer) { return default(bool); }
 /// <summary>
 /// Gets state of WebGLBuffer. Returns true if buffer is valid, false otherwise.
 /// </summary>
 /// <param name="buffer">The buffer to query.</param>
 /// <returns>Returns true if buffer is valid, false otherwise. </returns>
 public virtual bool IsBuffer(WebGLBuffer buffer)
 {
     return false;
 }