Exemple #1
0
        internal virtual void RCQUpdateResources(RenderCommandQueue commandQueue)
        {
            for (int i = 0; i < ConstantBufferBindings.Length; i++)
            {
                commandQueue.QueueCommand(RenderCommand.DiscardWriteShaderConstantBuffer(
                                              ConstantBufferBindings[i], ConstantBufferBindings[i].CurValuePtr
                                              ));
            }

            if (TextureSamplerBindings.Length > 0)
            {
                if (texSamplerValueDict == null)
                {
                    texSamplerValueDict = new FastClearList <KVP <TextureSamplerBinding, TextureSampler> >();
                }
                texSamplerValueDict.Clear();
                for (int i = 0; i < TextureSamplerBindings.Length; ++i)
                {
                    texSamplerValueDict.Add(new KVP <TextureSamplerBinding, TextureSampler>(TextureSamplerBindings[i], TextureSamplerBindings[i].GetBoundResource()));
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderTextureSamplers(this, texSamplerValueDict));
            }

            if (ResourceViewBindings.Length > 0)
            {
                if (resViewValueDict == null)
                {
                    resViewValueDict = new FastClearList <KVP <ResourceViewBinding, IResourceView> >();
                }
                resViewValueDict.Clear();
                for (int i = 0; i < ResourceViewBindings.Length; ++i)
                {
                    resViewValueDict.Add(new KVP <ResourceViewBinding, IResourceView>(ResourceViewBindings[i], ResourceViewBindings[i].GetBoundResourceAsBaseResourceView()));
                    Assure.False(ResourceViewBindings[i].GetBoundResourceAsBaseResourceView().Resource.PermittedBindings == GPUBindings.None, "Underlying resource has no permitted GPU bindings.");
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderResourceViews(this, resViewValueDict));
            }
        }
Exemple #2
0
        private void RefreshText()
        {
            using (RenderingModule.RenderStateBarrier.AcquirePermit()) {
                for (int i = 0; i < activeInstances.Count; ++i)
                {
                    if (activeMaterials[i] == null)
                    {
                        break;
                    }
                    activeInstances[i].Dispose();
                }

                characterArray.Clear();
                activeMaterials.Clear();
                activeInstances.Clear();

                for (int i = 0; i < text.Length; ++i)
                {
                    characterArray.Add(font.GetFontChar(text[i]));
                }

                Vector2 viewportSizePixels = viewport.SizePixels;
                Vector2 actualScale        = scale.Scale(new Vector2(viewportSizePixels.X / Font.FULL_SCALE_RESOLUTION.X, viewportSizePixels.Y / Font.FULL_SCALE_RESOLUTION.Y));
                Vector2 anchorOffsetPixels = viewportSizePixels.Scale(anchorOffset);
                float   cursorPos;
                float   yOffset;

                // Anchoring enum values are bitmasks to make this bit work. See comments in ViewportAnchoring
                // Falling to default values in both switch statements will result in a standard top-left corner selection
                float actualLineHeight = font.LineHeightPixels * actualScale.Y;
                float scaledCharHeight = font.MaxCharHeight * actualScale.Y;
                switch ((int)anchoring & 0xF0)     // Vertical bits
                {
                case 0x10:                         // 1 == "Bottom"
                    yOffset = anchorOffsetPixels.Y + scaledCharHeight;
                    break;

                case 0x20:                         // 2 == "Centered"
                    yOffset = (viewportSizePixels.Y + scaledCharHeight) * 0.5f;
                    break;

                default:                         // 0 == "Top"
                    yOffset = viewportSizePixels.Y - anchorOffsetPixels.Y;
                    break;
                }

                float stringSizeX = ((text.Length - 1) * font.KerningPixels);
                for (int i = 0; i < text.Length; ++i)
                {
                    stringSizeX += characterArray[i].Boundary.Width;
                }
                stringSizeX *= actualScale.X;
                switch ((int)anchoring & 0xF)     // Horizontal bits
                {
                case 0x1:                         // 1 == "Right"
                    cursorPos = -stringSizeX;
                    for (int c = 0; c < text.Length; ++c)
                    {
                        FontCharacter fontChar = characterArray[c];
                        activeMaterials.Add(materialsCache.GetOrCreate(fontChar, createMaterialFunc));
                        activeInstances.Add(sceneLayer.CreateModelInstance(
                                                fontChar.ModelHandle,
                                                activeMaterials[c],
                                                new Transform(
                                                    actualScale,
                                                    Quaternion.IDENTITY,
                                                    new Vector2(cursorPos + (viewportSizePixels.X - anchorOffsetPixels.X), yOffset - (fontChar.YOffset * actualScale.Y + actualLineHeight))
                                                    )
                                                ));
                        cursorPos += (font.KerningPixels + fontChar.Boundary.Width) * actualScale.X;
                    }
                    break;

                case 0x2:                         // 2 == "Centered"
                    cursorPos = -stringSizeX / 2f;
                    for (int c = 0; c < text.Length; ++c)
                    {
                        FontCharacter fontChar = characterArray[c];
                        activeMaterials.Add(materialsCache.GetOrCreate(fontChar, createMaterialFunc));
                        activeInstances.Add(sceneLayer.CreateModelInstance(
                                                fontChar.ModelHandle,
                                                activeMaterials[c],
                                                new Transform(
                                                    actualScale,
                                                    Quaternion.IDENTITY,
                                                    new Vector2(cursorPos + viewportSizePixels.X / 2f, yOffset - (fontChar.YOffset * actualScale.Y + actualLineHeight))
                                                    )
                                                ));
                        cursorPos += (font.KerningPixels + fontChar.Boundary.Width) * actualScale.X;
                    }
                    break;

                default:                         // 0 == "Left"
                    cursorPos = 0f;
                    for (int c = 0; c < text.Length; ++c)
                    {
                        FontCharacter fontChar = characterArray[c];
                        activeMaterials.Add(materialsCache.GetOrCreate(fontChar, createMaterialFunc));
                        activeInstances.Add(sceneLayer.CreateModelInstance(
                                                fontChar.ModelHandle,
                                                activeMaterials[c],
                                                new Transform(
                                                    actualScale,
                                                    Quaternion.IDENTITY,
                                                    new Vector2(cursorPos + anchorOffsetPixels.X, yOffset - (fontChar.YOffset * actualScale.Y + actualLineHeight))
                                                    )
                                                ));
                        cursorPos += (font.KerningPixels + fontChar.Boundary.Width) * actualScale.X;
                    }
                    break;
                }

                actualSizePixels = new Vector2(stringSizeX, actualLineHeight);

                RefreshColorOnly();
            }
        }