Exemple #1
0
        //A very simple "object pool" for the possible 3 matrices a label renderer can create,
        //to avoid allocating the matrices object on each tick.
        //Each possible matrix creation has a cell reserved for it.
        private GLMatrices acquireMatrix(int index)
        {
            GLMatrices matrices = _matricesPool[index];

            if (matrices == null)
            {
                matrices             = new GLMatrices();
                _matricesPool[index] = matrices;
            }
            return(matrices);
        }
Exemple #2
0
        private void updateBoundingBoxes(IObject obj, IDrawableInfo drawable, IViewport viewport)
        {
            AutoFit autoFit = getAutoFit();

            float height = obj.Height;
            float width  = obj.Width;

            if (autoFit == AutoFit.LabelShouldFitText)
            {
                updateText(GLText.EmptySize, null);
                CustomImageSize = new SizeF(_glText.Width, _glText.Height);
            }
            else
            {
                CustomImageSize = BaseSize;
            }

            var resolutionFactor = string.IsNullOrEmpty(Text) ? AGSModelMatrixComponent.NoScaling : new PointF(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY);

            CustomImageResolutionFactor = resolutionFactor;
            var  noFactor          = AGSModelMatrixComponent.NoScaling;
            bool resolutionMatches = resolutionFactor.Equals(noFactor);
            var  viewportMatrix    = drawable.IgnoreViewport ? Matrix4.Identity : _viewport.GetViewport(drawable.RenderLayer.Z).GetMatrix(viewport, drawable.RenderLayer.ParallaxSpeed);

            var modelMatrices = obj.GetModelMatrices();

            IGLMatrices textRenderMatrices = new GLMatrices {
                ModelMatrix = modelMatrices.InObjResolutionMatrix, ViewportMatrix = viewportMatrix
            };                                                                                                                                      //_textRenderMatrixBuilder.Build(_labelMatrixRenderTarget, sprite, parent, matrix, areaScaling, resolutionFactor);
            IGLMatrices labelRenderMatrices = new GLMatrices {
                ModelMatrix = modelMatrices.InVirtualResolutionMatrix, ViewportMatrix = viewportMatrix
            };                                                                                                                                           // _labelRenderMatrixBuilder.Build(_labelMatrixRenderTarget, sprite, parent, matrix, areaScaling, noFactor);
            IGLMatrices textHitTestMatrices  = resolutionMatches ? textRenderMatrices : labelRenderMatrices;
            IGLMatrices labelHitTestMatrices = labelRenderMatrices;

            updateBoundingBoxes(autoFit, textHitTestMatrices, labelHitTestMatrices, noFactor, resolutionMatches, true);
            if (!resolutionMatches)
            {
                updateBoundingBoxes(autoFit, textRenderMatrices, labelRenderMatrices, resolutionFactor, true, false);
            }
        }