예제 #1
0
        public void MakeTexture()
        {
            if (PrepDevice != null)
            {
                //     PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);

                try
                {
                    texture2d = PrepDevice.createTexture();

                    PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                    PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                    PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
                    PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, texture);
                    PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
                    PrepDevice.generateMipmap(GL.TEXTURE_2D);

                    PrepDevice.bindTexture(GL.TEXTURE_2D, null);
                }
                catch
                {
                    errored = true;
                }
            }
        }
예제 #2
0
 internal Texture(WebGLContext gl, WebGLTexture texture, int width, int height)
 {
     _gl      = gl;
     _texture = texture;
     _width   = width;
     _height  = height;
 }
예제 #3
0
        public static void Use(RenderContext renderContext, WebGLBuffer vertex, WebGLTexture texture)
        {
            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.vertexAttribPointer(textureLoc, 2, GL.FLOAT, false, 36, 28);
                gl.activeTexture(GL.TEXTURE0);
                gl.bindTexture(GL.TEXTURE_2D, texture);
                gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
                gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            }
        }
예제 #4
0
        public texReader(WebGLRenderingContext webgl, WebGLTexture texRGBA, int width, int height, bool gray = true)
        {
            this.gray   = gray;
            this.width  = width;
            this.height = height;

            var fbo = webgl.CreateFramebuffer();
            WebGLFramebuffer fbold = webgl.GetParameter(webgl.FRAMEBUFFER_BINDING) as WebGLFramebuffer;

            webgl.BindFramebuffer(webgl.FRAMEBUFFER, fbo);
            webgl.FramebufferTexture2D(webgl.FRAMEBUFFER, webgl.COLOR_ATTACHMENT0, webgl.TEXTURE_2D,
                                       texRGBA, 0);

            var readData = new Uint8Array(this.width * this.height * 4);

            readData[0] = 2;
            webgl.ReadPixels(0, 0, this.width, this.height, webgl.RGBA, webgl.UNSIGNED_BYTE,
                             readData);
            webgl.DeleteFramebuffer(fbo);
            webgl.BindFramebuffer(webgl.FRAMEBUFFER, fbold);

            if (gray)
            {
                this.data = new Uint8Array(this.width * this.height);
                for (var i = 0; i < width * height; i++)
                {
                    this.data[i] = readData[i * 4];
                }
            }
            else
            {
                this.data = readData;
            }
        }
예제 #5
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>();
        }
예제 #6
0
        /// <summary>
        /// </summary>
        /// <param name="camera">
        /// </param>
        /// <param name="sourceTexture">
        /// </param>
        public virtual void activate(Camera camera, WebGLTexture sourceTexture = null)
        {
            camera = camera ?? this._camera;
            var scene         = camera.getScene();
            var desiredWidth  = ((sourceTexture != null) ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio;
            var desiredHeight = ((sourceTexture != null) ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio;

            if (this.width != desiredWidth || this.height != desiredHeight)
            {
                if (this._textures.Length > 0)
                {
                    for (var i = 0; i < this._textures.Length; i++)
                    {
                        this._engine._releaseTexture(this._textures[i]);
                    }

                    this._textures.reset();
                }

                this.width  = (int)desiredWidth;
                this.height = (int)desiredHeight;
                this._textures.Add(
                    this._engine.createRenderTargetTexture(
                        new Size {
                    width = this.width, height = this.height
                },
                        generateMipMaps: false,
                        generateDepthBuffer: camera._postProcesses.IndexOf(this) == camera._postProcessesTakenIndices[0],
                        samplingMode: this.renderTargetSamplingMode));
                if (this._reusable)
                {
                    this._textures.Add(
                        this._engine.createRenderTargetTexture(
                            new Size {
                        width = this.width, height = this.height
                    },
                            generateMipMaps: false,
                            generateDepthBuffer: camera._postProcesses.IndexOf(this) == camera._postProcessesTakenIndices[0],
                            samplingMode: this.renderTargetSamplingMode));
                }

                if (this.onSizeChanged != null)
                {
                    this.onSizeChanged();
                }
            }

            this._engine.bindFramebuffer(this._textures[this._currentRenderTextureInd]);
            if (this.onActivate != null)
            {
                this.onActivate(camera);
            }

            this._engine.clear(scene.clearColor, scene.autoClear || scene.forceWireframe, true);
            if (this._reusable)
            {
                this._currentRenderTextureInd = (this._currentRenderTextureInd + 1) % 2;
            }
        }
예제 #7
0
 public override void Destroy()
 {
     if (id != null)
     {
         GL.deleteTexture(id);
         id = null;
     }
 }
예제 #8
0
 private void DeleteGLTexture()
 {
     if (glTexture != null)
     {
         GraphicsDevice.DisposeTexture(glTexture);
     }
     glTexture = null;
 }
        public void bindTexture(int target, WebGLTexture texture)
        {
#if _DEBUG
            Log.Info(string.Format("bindTexture {0}", target, (int)(texture != null ? texture.Value : 0)));
#endif

            Gl.glBindTexture(target, (int)(texture != null ? texture.Value : 0));
            this.ErrorTest();
        }
예제 #10
0
 public void framebufferTexture2D(int target, int attachment, int textarget, WebGLTexture texture, int level)
 {
     this.openGl.FramebufferTexture2DEXT(
         (uint)target,
         (uint)attachment,
         (uint)textarget,
         texture != null ? texture.Value : 0,
         level);
     this.ErrorTest();
 }
예제 #11
0
 internal void DisposeTexture(WebGLTexture handle)
 {
     if (!_isDisposed)
     {
         lock (_disposeActionsLock)
         {
             _disposeNextFrame.Add(ResourceHandle.Texture(handle));
         }
     }
 }
예제 #12
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);
            }
        }
예제 #13
0
        public virtual void MakeTexture()
        {
            if (PrepDevice != null)
            {
                //     PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);

                try
                {
                    texture2d = PrepDevice.createTexture();

                    if (dataset.Extension == ".fits" && RenderContext.UseGlVersion2)
                    {
                        PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);

                        PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);
                    }
                    else
                    {
                        ImageElement image = texture;

                        // Before we bind resize to a power of two if nessesary so we can MIPMAP
                        if (!Texture.IsPowerOfTwo(texture.Height) | !Texture.IsPowerOfTwo(texture.Width))
                        {
                            CanvasElement temp = (CanvasElement)Document.CreateElement("canvas");
                            temp.Height = Texture.FitPowerOfTwo(image.Height);
                            temp.Width  = Texture.FitPowerOfTwo(image.Width);
                            CanvasContext2D ctx = (CanvasContext2D)temp.GetContext(Rendering.Render2D);
                            ctx.DrawImage(image, 0, 0, temp.Width, temp.Height);
                            //Substitute the resized image
                            image = (ImageElement)(Element)temp;
                        }

                        PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
                        PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
                        PrepDevice.generateMipmap(GL.TEXTURE_2D);
                    }



                    PrepDevice.bindTexture(GL.TEXTURE_2D, null);
                }
                catch
                {
                    errored = true;
                }
            }
        }
예제 #14
0
        public static WebGLTexture GetEmpty()
        {
            if (empty == null)
            {
                empty = Tile.PrepDevice.createTexture();
                Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, empty);
                Tile.PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, 1, 1, 0, GL.RGBA, GL.UNSIGNED_BYTE, (System.Html.WebGLArray)(object)(new Uint8Array(new Byte[] { 0, 0, 0, 0 })));
                Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, null);
            }

            return(empty);
        }
예제 #15
0
        public WebGLTexture GetTexture()
        {
            WebGLTexture tex = Tile.PrepDevice.createTexture();

            Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, tex);
            Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
            Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
            Tile.PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, Width, Height, 0, GL.RGBA, GL.UNSIGNED_BYTE, (WebGLArray)(object)buffer);
            Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
            Tile.PrepDevice.generateMipmap(GL.TEXTURE_2D);
            Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, null);
            return(tex);
        }
예제 #16
0
        public void InitTexture()
        {
            this.texture = gl.CreateTexture();

            var textureImageElement = new HTMLImageElement();

            textureImageElement.OnLoad = (ev) =>
            {
                this.HandleLoadedTexture(textureImageElement);
            };

            textureImageElement.Src = this.textureImageSrc;
        }
예제 #17
0
        public WebGL2Tests(JSObject canvas)
        {
            if (!WebGL2RenderingContextBase.IsSupported)
            {
                throw new InconclusiveException("WebGL 2 is not supported");
            }

            gl = new WebGL2RenderingContext(canvas);

            pixels       = new byte[TextureWidthOrHeight * 2 * BytesPerPixel];
            pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
            texture      = gl.CreateTexture();
        }
        /// <summary>
        /// </summary>
        /// <param name="sourceTexture">
        /// </param>
        /// <returns>
        /// </returns>
        public virtual bool _prepareFrame(WebGLTexture sourceTexture = null)
        {
            var postProcesses             = this._scene.activeCamera._postProcesses;
            var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;

            if (postProcessesTakenIndices.Length == 0 || !this._scene.postProcessesEnabled)
            {
                return(false);
            }

            postProcesses[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera, sourceTexture);
            return(true);
        }
        public void framebufferTexture2D(int target, int attachment, int textarget, WebGLTexture texture, int level)
        {
#if _DEBUG
            Log.Info(string.Format("framebufferTexture2D {0} {1} {2} {3} {4}", target, attachment, textarget, texture != null ? texture.Value : 0, level));
#endif

#if GLEW_STATIC
            Gl.glFramebufferTexture2D(target, attachment, textarget, (int)(texture != null ? texture.Value : 0), level);
#else
            Gl.__glewFramebufferTexture2D(target, attachment, textarget, (int)(texture != null ? texture.Value : 0), level);
#endif

            this.ErrorTest();
        }
예제 #20
0
        public override void BindTexture(uint target, uint texture)
        {
            WebGLTexture t = _textures[texture];

            if (t == null)
            {
                t = gl.CreateTexture();
                _textures[texture] = t;
            }
            //Log("binding texture " + t + " id " + texture + " for activeTexture: " + (_activeTexture - TEXTURE0));
            gl.BindTexture(target, t); CheckError("glBindTexture");
            _boundTextureId[_activeTexture] = texture;
            //glColor3f((float)Math.Random(), (float)Math.Random(), (float)Math.Random());
        }
예제 #21
0
        void IDisposable.Dispose()
        {
            if (DualityApp.ExecContext != DualityApp.ExecutionContext.Terminated &&
                this.handle != null)
            {
                // Removed thread guards because of performance
                try {
                    GraphicsBackend.GL.DeleteTexture(this.handle);
                } catch (Exception ex) {
                    Console.WriteLine("DeleteTexture() failed: " + ex);
                }

                this.handle = null;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="doNotPresent">
        /// </param>
        /// <param name="targetTexture">
        /// </param>
        public virtual void _finalizeFrame(bool doNotPresent = false, WebGLTexture targetTexture = null)
        {
            var postProcesses             = this._scene.activeCamera._postProcesses;
            var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;

            if (postProcessesTakenIndices.Length == 0 || !this._scene.postProcessesEnabled)
            {
                return;
            }

            var engine = this._scene.getEngine();

            for (var index = 0; index < postProcessesTakenIndices.Length; index++)
            {
                if (index < postProcessesTakenIndices.Length - 1)
                {
                    postProcesses[postProcessesTakenIndices[index + 1]].activate(this._scene.activeCamera);
                }
                else
                {
                    if (targetTexture != null)
                    {
                        engine.bindFramebuffer(targetTexture);
                    }
                    else
                    {
                        engine.restoreDefaultFramebuffer();
                    }
                }

                if (doNotPresent)
                {
                    break;
                }

                var effect = postProcesses[postProcessesTakenIndices[index]].apply();
                if (effect != null)
                {
                    engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, effect);
                    engine.draw(true, 0, 6);
                }
            }

            engine.setDepthBuffer(true);
            engine.setDepthWrite(true);
        }
예제 #23
0
        void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D);

            if (lastTexId != this.handle)
            {
                GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle);
            }

            // Set texture parameters
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MIN_FILTER, (int)ToOpenTKTextureMinFilter(minFilter));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MAG_FILTER, (int)ToOpenTKTextureMagFilter(magFilter));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_S, (int)ToOpenTKTextureWrapMode(wrapX));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_T, (int)ToOpenTKTextureWrapMode(wrapY));

            // Anisotropic filtering
            // ToDo: Add similar code for OpenGL ES
            //if (anisoLevel > 0) {
            //    GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel);
            //}

            // If needed, care for Mipmaps
            // ToDo: Why are mipmaps disabled here?
            //GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0);

            // Setup pixel format
            GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0,
                                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                                          ToOpenTKPixelFormat(format), WebGLRenderingContextBase.UNSIGNED_BYTE, null);

            //GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D);

            this.width   = width;
            this.height  = height;
            this.format  = format;
            this.mipmaps = mipmaps;

            if (lastTexId != this.handle)
            {
                GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId);
            }
        }
예제 #24
0
        /// <summary>
        /// </summary>
        public virtual void releaseInternalTexture()
        {
            if (this._texture == null)
            {
                return;
            }

            var texturesCache = this._scene.getEngine().getLoadedTexturesCache();

            this._texture.references--;
            if (this._texture.references == 0)
            {
                var index = texturesCache.IndexOf(this._texture);
                texturesCache.RemoveAt(index);
                this._scene.getEngine()._releaseTexture(this._texture);
                this._texture = null;
            }
        }
예제 #25
0
        internal WebGL2Texture(string file, TextureType type,
                               TextureFormat format,
                               TextureFilter minFilter, TextureFilter magFilter,
                               TextureWrap wrapX, TextureWrap wrapY, TextureWrap?wrapZ)
        {
            Type   = type;
            Width  = 1;
            Height = 1;
            Depth  = 1;
            Format = format;
            id     = GL.createTexture();
            switch (Type)
            {
            case TextureType.Texture2D:
                TextureTarget = TEXTURE_2D;
                break;

            case TextureType.Texture2DArray:
                TextureTarget = TEXTURE_2D_ARRAY_Static;
                break;

            case TextureType.Texture3D:
                TextureTarget = TEXTURE_3D_Static;
                WrapZ         = wrapZ.Value;
                break;

            default:
                throw new IllegalValueException(typeof(TextureType), Type);
            }
            MinFilter = minFilter;
            MagFilter = magFilter;
            WrapX     = wrapX;
            WrapY     = wrapY;

            //SetData(new byte[] { 255, 20, 147, 255 }); // Debug Pink
            SetData(new byte[] { 255, 255, 255, 255 });

            // Load image async
            HTMLImageElement image = new HTMLImageElement();

            image.crossOrigin = "";
            image.onload      = (ev) => { HandleLoadedTexture(image); };
            image.src         = file;
        }
예제 #26
0
        public virtual void CleanUp(bool removeFromParent)
        {
            ReadyToRender  = false;
            DemData        = null;
            demFile        = null;
            demDownloading = false;
            texReady       = false;
            DemReady       = false;
            errored        = false;
            if (this.texture != null)
            {
                this.texture = null;
            }

            RenderTriangleLists = new List <RenderTriangle> [4];
            GeometryCreated     = false;
            if (removeFromParent && Parent != null)
            {
                Parent.RemoveChild(this);
                Parent = null;
            }

            if (PrepDevice != null)
            {
                foreach (WebGLBuffer buf in IndexBuffers)
                {
                    PrepDevice.deleteBuffer(buf);
                }
                IndexBuffers = new WebGLBuffer[4];

                if (VertexBuffer != null)
                {
                    PrepDevice.deleteBuffer(VertexBuffer);
                    VertexBuffer = null;
                }

                if (texture2d != null)
                {
                    PrepDevice.deleteTexture(texture2d);

                    texture2d = null;
                }
            }
        }
예제 #27
0
        public void MakeTexture()
        {
            if (Tile.PrepDevice != null)
            {
                //     PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);

                try
                {
                    Texture2d = Tile.PrepDevice.createTexture();

                    Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, Texture2d);

                    ImageElement image = ImageElement;

                    // Before we bind resize to a power of two if nessesary so we can MIPMAP
                    if (!IsPowerOfTwo(ImageElement.Height) | !IsPowerOfTwo(ImageElement.Width))
                    {
                        CanvasElement temp = (CanvasElement)Document.CreateElement("canvas");
                        temp.Height = FitPowerOfTwo(image.Height);
                        temp.Width  = FitPowerOfTwo(image.Width);
                        CanvasContext2D ctx = (CanvasContext2D)temp.GetContext(Rendering.Render2D);
                        ctx.DrawImage(image, 0, 0, temp.Width, temp.Height);
                        //Substitute the resized image
                        image = (ImageElement)(Element)temp;
                    }


                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
                    Tile.PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image);
                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
                    Tile.PrepDevice.generateMipmap(GL.TEXTURE_2D);

                    Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, null);
                }
                catch
                {
                    Errored = true;
                }
            }
        }
예제 #28
0
        public void DrawTextured(RenderContext renderContext, WebGLTexture texture, float opacity)
        {
            InitBuffer(renderContext);

            Vector3d zero   = new Vector3d();
            Matrix3d matInv = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View);

            matInv.Invert();
            Vector3d cam = Vector3d.TransformCoordinate(zero, matInv);

            foreach (TimeSeriesPointVertexBuffer pointBuffer in pointBuffers)
            {
                TimeSeriesPointSpriteShader.Use(
                    renderContext, pointBuffer.VertexBuffer, texture,
                    Color.FromArgb(255 * opacity, 255, 255, 255), DepthBuffered, (float)(this.JNow),
                    (float)Decay, cam, (float)(scale * (renderContext.Height / 960)), MinSize, ShowFarSide, Sky
                    );

                renderContext.gl.drawArrays(GL.POINTS, 0, pointBuffer.Count);
            }
        }
예제 #29
0
        unsafe void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D);

            GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle);

            // Load pixel data to video memory
            GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0,
                                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                                          dataLayout.ToOpenTK(), dataElementType.ToOpenTK(),
                                          TypedArray <Uint8ClampedArray, byte> .From(new Span <byte>(data.ToPointer(), /*ToDo*/ (width * height * 4))));

            GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D);

            this.width  = width;
            this.height = height;
            this.format = format;

            GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId);
        }
예제 #30
0
        internal WebGL2Texture(byte[] data, TextureType type,
                               int width, int height, int depth,
                               TextureFormat format,
                               TextureFilter minFilter, TextureFilter magFilter,
                               TextureWrap wrapX, TextureWrap wrapY, TextureWrap?wrapZ)
        {
            Type   = type;
            Width  = width;
            Height = height;
            Depth  = depth;
            Format = format;
            id     = GL.createTexture();
            switch (Type)
            {
            case TextureType.Texture2D:
                TextureTarget = TEXTURE_2D;
                break;

            case TextureType.Texture2DArray:
                TextureTarget = TEXTURE_2D_ARRAY_Static;
                break;

            case TextureType.Texture3D:
                TextureTarget = TEXTURE_3D_Static;
                WrapZ         = wrapZ.Value;
                break;

            default:
                throw new IllegalValueException(typeof(TextureType), Type);
            }
            MinFilter = minFilter;
            MagFilter = magFilter;
            WrapX     = wrapX;
            WrapY     = wrapY;

            SetData(data);
        }
예제 #31
0
 public void framebufferTexture2D(int target, int attachment, int textarget, WebGLTexture texture, int level) { }
예제 #32
0
 public bool isTexture(WebGLTexture texture) { return default(bool); }
예제 #33
0
 public void bindTexture(int target, WebGLTexture texture) { }
예제 #34
0
 public void deleteTexture(WebGLTexture texture) { }
예제 #35
0
파일: Cube.cs 프로젝트: phaethom/Demos
        public void InitTexture()
        {
            this.texture = gl.CreateTexture();

            var textureImageElement = new ImageElement();

            textureImageElement.OnLoad = (ev) =>
            {
                this.HandleLoadedTexture(textureImageElement);
            };

            textureImageElement.Src = this.textureImageSrc;
        }
 /// <summary>
 /// Gets state of WebGL texture. Returns true if texture is valid, false otherwise.
 /// </summary>
 /// <param name="texture">Texture to query.</param>
 /// <returns>Returns true of texture is valid, false otherwise.</returns>
 public virtual bool IsTexture(WebGLTexture texture)
 {
     return false;
 }
 /// <summary>
 /// Deletes a specific texture object.
 /// If texture is currently bound is deleted, the binding reverts to a default 0 value texture.
 /// </summary>
 /// <param name="texture">The texture to delete</param>
 public virtual void DeleteTexture(WebGLTexture texture) { }
 /// <summary>
 /// Attaches a texture to a WebGLFramebuffer object.
 ///
 /// Errors:
 ///     gl.INVALID_ENUM        If textarget isn't from the listed values, and texture isn't 0.
 ///                         If target isn't gl.FRAMEBUFFER.
 ///                         If attachment isn't from the listed values.
 ///
 ///     gl.INVALID_OPERATION    If the default framebuffer object name 0 is bound.
 ///                             If texture isn't 0 or the name of an existing texture object
 /// </summary>
 /// <param name="target">Always use gl.FRAMEBUFFER.</param>
 /// <param name="attachment">Specifies the attachment point. One of the following:
 ///     gl.COLOR_ATTACHMENT0
 ///     gl.DEPTH_ATTACHMENT
 ///     gl.STENCIL_ATTACHEMENT
 ///     gl.DEPTH_STENCIL_ATTACHEMENT
 /// </param>
 /// <param name="texTarget">The texture target:
 ///     gl.TEXTURE_2D                       Uses a 2D image.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_X      Image for the positive X face of the cube.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_X      Image for the negative X face of the cube.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Y      Image for the positive Y face of the cube.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Y      Image for the negative Y face of the cube.
 ///     gl.TEXTURE_CUBE_MAP_POSITIVE_Z      Image for the positive Z face of the cube.
 ///     gl.TEXTURE_CUBE_MAP_NEGATIVE_Z      Image for the negative Z face of the cube.
 /// </param>
 /// <param name="texture">WebGLTexture object with image to attach.</param>
 /// <param name="level">The mipmap level of the texture image to attach. Always set to 0.</param>
 public virtual void FramebufferTexture2D(int target, int attachment, int texTarget, WebGLTexture texture, int level) { }
 /// <summary>
 /// Binds a named texture object to a target.
 /// Errors:
 ///     gl.INVALID_ENUM            If target isn't one of the listed values..
 ///     gl.INVALID_OPERATION    If texture was created with different target than target.
 /// </summary>
 /// <param name="target">gl.TEXTURE_2D or gl.TEXTURE_CUBE_MAP</param>
 /// <param name="texture">Either a reference to a texture object or null.</param>
 public virtual void BindTexture(int target, WebGLTexture texture) { }