Ejemplo n.º 1
0
        protected override void PlatformSetSamplerState(int slot, SamplerState samplerState)
        {
            OpenGLESSamplerState           glSampler = (OpenGLESSamplerState)samplerState;
            OpenGLESTextureBindingSlotInfo info      = ShaderResourceBindingSlots.GetSamplerBindingInfo(slot);

            _textureSamplerManager.SetSampler(info.RelativeIndex, glSampler);
        }
Ejemplo n.º 2
0
        protected override void PlatformSetTexture(int slot, ShaderTextureBinding textureBinding)
        {
            OpenGLESTextureBinding         glTextureBinding = (OpenGLESTextureBinding)textureBinding;
            OpenGLESTextureBindingSlotInfo info             = ShaderResourceBindingSlots.GetTextureBindingInfo(slot);

            _textureSamplerManager.SetTexture(info.RelativeIndex, glTextureBinding);
            ShaderSet.UpdateTextureUniform(info.UniformLocation, info.RelativeIndex);
        }
        public OpenGLESShaderResourceBindingSlots(OpenGLESShaderSet shaderSet, ShaderResourceDescription[] resources)
        {
            Resources = resources;
            int programID = shaderSet.ProgramID;

            int lastTextureLocation  = -1;
            int relativeTextureIndex = -1;

            for (int i = 0; i < resources.Length; i++)
            {
                ShaderResourceDescription resource = resources[i];
                if (resource.Type == ShaderResourceType.ConstantBuffer)
                {
                    int blockIndex = GL.GetUniformBlockIndex(programID, resource.Name);
                    Utilities.CheckLastGLES3Error();
                    if (blockIndex != -1)
                    {
                        ValidateBlockSize(programID, blockIndex, resource.DataSizeInBytes, resource.Name);
                        _constantBindings[i] = new OpenGLESUniformBinding(programID, blockIndex, resource.DataSizeInBytes);
                    }
                    else
                    {
                        int uniformLocation = GL.GetUniformLocation(programID, resource.Name);
                        Utilities.CheckLastGLES3Error();
                        if (uniformLocation == -1)
                        {
                            throw new VeldridException($"No uniform or uniform block with name {resource.Name} was found.");
                        }

                        OpenGLESUniformStorageAdapter storageAdapter = new OpenGLESUniformStorageAdapter(programID, uniformLocation);
                        _constantBindings[i] = new OpenGLESUniformBinding(programID, storageAdapter);
                    }
                }
                else if (resource.Type == ShaderResourceType.Texture)
                {
                    int location = GL.GetUniformLocation(shaderSet.ProgramID, resource.Name);
                    Utilities.CheckLastGLES3Error();
                    if (location == -1)
                    {
                        throw new VeldridException($"No sampler was found with the name {resource.Name}");
                    }

                    relativeTextureIndex += 1;
                    _textureBindings[i]   = new OpenGLESTextureBindingSlotInfo()
                    {
                        RelativeIndex = relativeTextureIndex, UniformLocation = location
                    };
                    lastTextureLocation = location;
                }
                else
                {
                    Debug.Assert(resource.Type == ShaderResourceType.Sampler);
                    if (lastTextureLocation == -1)
                    {
                        throw new VeldridException(
                                  "OpenGL Shaders must specify at least one texture before a sampler. Samplers are implicity linked with the closest-previous texture resource in the binding list.");
                    }

                    _samplerBindings[i] = new OpenGLESTextureBindingSlotInfo()
                    {
                        RelativeIndex = relativeTextureIndex, UniformLocation = lastTextureLocation
                    };
                }
            }
        }