Example #1
0
        internal void ReleaseTextureContainer(TextureContainter textureContainer)
        {
#if DEBUG
            if (textureContainer.GLBitmap != null)
            {   //clear the glbmp first
                throw new System.NotSupportedException();
            }
            if (_freeContainers.Contains(textureContainer))
            {
            }
#endif
            //must remove from active
            if (textureContainer.ActiveQueueLinkedNode != null)
            {
                //remove specific node
                _activeContainers.Remove(textureContainer.ActiveQueueLinkedNode);
                textureContainer.ActiveQueueLinkedNode = null;//***
            }
            else
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();//???
#endif
            }

            _freeContainers.Enqueue(textureContainer);
        }
Example #2
0
        void UploadGradientLookupTable(GLBitmap bmp)
        {
            //load before use with RenderSubImage
            //-------------------------------------------------------------------------------------
            // Bind the texture...
            TextureContainter container = _shareRes.LoadGLBitmap(bmp);

            s_texture.SetValue(container.TextureUnitNo);
        }
Example #3
0
        internal void ReleaseTextureContainer(TextureContainter textureContainer)
        {
#if DEBUG
            if (textureContainer.GLBitmap != null)
            {   //clear the glbmp first
                throw new System.NotSupportedException();
            }
#endif
            _freeContainers.Enqueue(textureContainer);
        }
Example #4
0
        void UploadGradientLookupTable(GLBitmap bmp)
        {
            //load before use with RenderSubImage
            //-------------------------------------------------------------------------------------
            // Bind the texture...
            TextureContainter container = _shareRes.LoadGLBitmap(bmp);

            //GL.ActiveTexture(TextureUnit.Texture0);
            //GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId());
            // Set the texture sampler to texture unit to 0
            s_texture.SetValue(container.TextureUnitNo);
        }
Example #5
0
        /// <summary>
        /// load glbitmap to free texture unit
        /// </summary>
        /// <param name="bmp"></param>
        /// <returns></returns>
        public TextureContainter LoadGLBitmap(GLBitmap bmp)
        {
            if (bmp.TextureContainer != null)
            {
                //bmp.TextureContainer.UnloadGLBitmap();

                if (_latestLoadGLBmp != bmp)
                {
                    bmp.TextureContainer.MakeActive();
                    return(bmp.TextureContainer);
                }
                else
                {
                    _latestLoadGLBmp = bmp;
                    return(bmp.TextureContainer);
                }
            }


            //----------------
            if (_freeContainers.Count > 0)
            {
                //has some free texture unit
                TextureContainter container = _freeContainers.Dequeue();
                container.LoadGLBitmap(bmp);
                _activeContainers.Enqueue(container);//move to active container queue
#if DEBUG
                container._debugIsActive = true;
#endif
                return(container);
            }
            else
            {
                //TODO: handle out-of-quota  texture unit here
                //in this version we unload from oldest active container
                TextureContainter container = _activeContainers.Dequeue();
                container.UnloadGLBitmap();
#if DEBUG
                if (_freeContainers.Count < 2)
                {
                }
#endif
                //when container is unload, it will enqueue to the free pool
                //so we get the new one from the pool,DO NOT reuse current container
                container = _freeContainers.Dequeue();
                container.LoadGLBitmap(bmp);
                _activeContainers.Enqueue(container);
#if DEBUG
                container._debugIsActive = true;
#endif
                return(container);
            }
        }
Example #6
0
        /// <summary>
        /// load glbmp before draw
        /// </summary>
        /// <param name="bmp"></param>
        public void LoadGLBitmap(GLBitmap bmp)
        {
            //load before use with RenderSubImage
            SetCurrent();
            CheckViewMatrix();
            //-------------------------------------------------------------------------------------
            // Bind the texture...

            TextureContainter container = _shareRes.LoadGLBitmap(bmp);

            // Set the texture sampler to texture unit to 0
            s_texture.SetValue(container.TextureUnitNo);


            _latestBmpW        = bmp.Width;
            _latestBmpH        = bmp.Height;
            _latestBmpYFlipped = bmp.IsYFlipped;
        }
Example #7
0
        public void Render(GLBitmap glBmp, float left, float top, float w, float h, bool isFlipped = false)
        {
            SetCurrent();
            CheckViewMatrix();
            unsafe
            {
                //user's coord
                //(left,top) ----- (right,top)
                //  |                   |
                //  |                   |
                //  |                   |
                //(left,bottom) ---(right,bottom)

                //
                //(0,1) ------------ (1,1)
                //  |                   |
                //  |   texture-img     |
                //  |                   |
                //(0,0) -------------(1,0)


                if (isFlipped)
                {
                    //since this is fliped in Y axis
                    //so we map
                    //| user's coord    | texture-img |
                    //----------------------------------
                    //| left            | left
                    //| right           | right
                    //----------------------------------
                    //| top             | bottom
                    //| bottom          | top
                    //----------------------------------

                    float *imgVertices = stackalloc float[5 * 4];
                    {
                        imgVertices[0] = left; imgVertices[1] = top; imgVertices[2] = 0;     //coord 0 (left,top)
                        imgVertices[3] = 0; imgVertices[4] = 0;                              //texture coord 0 (left,bottom)
                        //---------------------
                        imgVertices[5] = left; imgVertices[6] = top - h; imgVertices[7] = 0; //coord 1 (left,bottom)
                        imgVertices[8] = 0; imgVertices[9] = 1;                              //texture coord 1  (left,top)

                        //---------------------
                        imgVertices[10] = left + w; imgVertices[11] = top; imgVertices[12] = 0; //coord 2 (right,top)
                        imgVertices[13] = 1; imgVertices[14] = 0;                               //texture coord 2  (right,bottom)

                        //---------------------
                        imgVertices[15] = left + w; imgVertices[16] = top - h; imgVertices[17] = 0; //coord 3 (right, bottom)
                        imgVertices[18] = 1; imgVertices[19] = 1;                                   //texture coord 3 (right,top)
                    }
                    a_position.UnsafeLoadMixedV3f(imgVertices, 5);
                    a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5);
                }
                else
                {    //since this is NOT fliped in Y axis
                    //so we map
                    //| user's coord    | texture-img |
                    //----------------------------------
                    //| left            | left
                    //| right           | right
                    //----------------------------------
                    //| top             | top
                    //| bottom          | bottom
                    //----------------------------------
                    float *imgVertices = stackalloc float[5 * 4];
                    {
                        imgVertices[0] = left; imgVertices[1] = top; imgVertices[2] = 0; //coord 0 (left,top)
                        imgVertices[3] = 0; imgVertices[4] = 1;                          //texture coord 0 (left,top)

                        //---------------------
                        imgVertices[5] = left; imgVertices[6] = top - h; imgVertices[7] = 0; //coord 1 (left,bottom)
                        imgVertices[8] = 0; imgVertices[9] = 0;                              //texture coord 1 (left,bottom)

                        //---------------------
                        imgVertices[10] = left + w; imgVertices[11] = top; imgVertices[12] = 0; //coord 2 (right,top)
                        imgVertices[13] = 1; imgVertices[14] = 1;                               //texture coord 2 (right,top)

                        //---------------------
                        imgVertices[15] = left + w; imgVertices[16] = top - h; imgVertices[17] = 0; //coord 3 (right, bottom)
                        imgVertices[18] = 1; imgVertices[19] = 0;                                   //texture coord 3  (right,bottom)
                    }
                    a_position.UnsafeLoadMixedV3f(imgVertices, 5);
                    a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5);
                }
            }

            SetCurrent();
            CheckViewMatrix();
            //-------------------------------------------------------------------------------------
            // Bind the texture...

            TextureContainter container = _shareRes.LoadGLBitmap(glBmp);

            //GL.ActiveTexture(TextureUnit.Texture0);
            //GL.BindTexture(TextureTarget.Texture2D, textureId);
            // Set the texture sampler to texture unit to 0
            s_texture.SetValue(container.TextureUnitNo);

            SetVarsBeforeRender();
            GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices);
        }
Example #8
0
        /// <summary>
        /// load glbitmap to free texture unit
        /// </summary>
        /// <param name="bmp"></param>
        /// <returns></returns>
        public TextureContainter LoadGLBitmap(GLBitmap bmp)
        {
            if (bmp.TextureContainer != null)
            {
                //bmp.TextureContainer.UnloadGLBitmap();

                if (_latestLoadGLBmp != bmp)
                {
                    bmp.TextureContainer.MakeActive();
                    return(bmp.TextureContainer);
                }
                else
                {
                    _latestLoadGLBmp = bmp;
                    return(bmp.TextureContainer);
                }
            }
            //----------------
            if (_freeContainers.Count > 0)
            {
                //has some free texture unit
                TextureContainter container = _freeContainers.Dequeue();
                container.LoadGLBitmap(bmp);

#if DEBUG
                if (_activeContainers.Contains(container))
                {
                    //remove this from
                    System.Diagnostics.Debugger.Break();
                }
#endif

                container.ActiveQueueLinkedNode = _activeContainers.AddLast(container);
#if DEBUG
                container._debugIsActive = true;
#endif
                return(container);
            }
            else
            {
                //TODO: handle out-of-quota  texture unit here
                //in this version we unload from oldest active container

                TextureContainter container = _activeContainers.First.Value;
                container.UnloadGLBitmap();

#if DEBUG
                if (container.ActiveQueueLinkedNode != null)
                {
                    System.Diagnostics.Debugger.Break();
                }
                if (_freeContainers.Count < 2)
                {
                }
#endif
                //when container is unload, it will enqueue to the free pool
                //so we get the new one from the pool,DO NOT reuse current container
                container = _freeContainers.Dequeue();
                container.LoadGLBitmap(bmp);

                //enqueue
                container.ActiveQueueLinkedNode = _activeContainers.AddLast(container);

#if DEBUG
                container._debugIsActive = true;
#endif
                return(container);
            }
        }