Exemplo n.º 1
0
        private VertexArrayObjectInstance GetInstance(EffectInputSignature effectInputSignature)
        {
            VertexArrayObjectInstance inputLayout;

            lock (registeredInstances)
            {
                if (!registeredInstances.TryGetValue(effectInputSignature, out inputLayout))
                {
                    inputLayout = new VertexArrayObjectInstance(GraphicsDevice, effectInputSignature, vertexAttribs, indexBufferId);
                    registeredInstances.Add(effectInputSignature, inputLayout);
                }
            }
            return(inputLayout);
        }
Exemplo n.º 2
0
        internal void Apply(EffectInputSignature effectInputSignature)
        {
            if (effectInputSignature == null)
            {
                throw new ArgumentNullException("effectInputSignature");
            }

            // Optimization: If the current VAO and shader signature was previously used, we can use it directly without asking for a proper instance
            if (RequiresApply(effectInputSignature))
            {
                currentInstance = ReferenceEquals(preferredInputSignature, effectInputSignature)
                    ? preferredInstance
                    : GetInstance(effectInputSignature);
                currentShaderSignature = effectInputSignature;
            }

            currentInstance.Apply(GraphicsDevice);
        }
Exemplo n.º 3
0
        private void CreateAttributes()
        {
            int vertexAttribCount = 0;

            for (int i = 0; i < vertexBufferBindings.Length; ++i)
            {
                vertexAttribCount += vertexBufferBindings[i].Declaration.VertexElements.Length;
            }

            vertexAttribs = new VertexAttrib[vertexAttribCount];
            int j = 0;

            for (int i = 0; i < vertexBufferBindings.Length; ++i)
            {
                var inputSlot    = vertexBufferBindings[i];
                var vertexBuffer = vertexBufferBindings[i].Buffer;

                foreach (var vertexElementAndOffset in inputSlot.Declaration.EnumerateWithOffsets())
                {
                    var vertexElement = vertexElementAndOffset.VertexElement;
                    var attributeName = "a_" + vertexElement.SemanticName + vertexElement.SemanticIndex;

                    var vertexElementFormat = ConvertVertexElementFormat(vertexElement.Format);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                    IntPtr bufferStart = vertexBuffer.ResourceId == 0
                        ? vertexBuffer.StagingData
                        : (IntPtr)vertexBufferBindings[i].Offset;
#else
                    var bufferStart = (IntPtr)vertexBufferBindings[i].Offset;
#endif
                    vertexAttribs[j] = new VertexAttrib
                    {
                        VertexBufferId = vertexBuffer.ResourceId,
                        Index          = -1,
                        IsInteger      = IsInteger(vertexElementFormat.Type),
                        Size           = vertexElementFormat.Size,
                        Type           = vertexElementFormat.Type,
                        Normalized     = vertexElementFormat.Normalized,
                        Stride         = inputSlot.Declaration.VertexStride,
                        Offset         = bufferStart + vertexElementAndOffset.Offset,
                        AttributeName  = attributeName
                    };

                    j++;
                }
            }

            if (indexBufferBinding != null)
            {
                indexBufferId = indexBufferBinding.Buffer.resourceId;

#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                if (GraphicsDevice.IsOpenGLES2 && indexBufferBinding.Is32Bit)
                {
                    throw new PlatformNotSupportedException("32 bits index buffer are not supported on OpenGL ES 2.0");
                }
                indexBufferOffset = (indexBufferId == 0 ? indexBufferBinding.Buffer.StagingData : IntPtr.Zero) +
                                    indexBufferBinding.Offset;
#else
                indexBufferOffset = (IntPtr)indexBufferBinding.Offset;
#endif
                drawElementsType = indexBufferBinding.Is32Bit ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort;
                indexElementSize = indexBufferBinding.Is32Bit ? 4 : 2;
            }

            // If we have a signature, we can already pre-create the instance
            if (preferredInputSignature != null)
            {
                preferredInstance = GetInstance(preferredInputSignature);
            }

            currentShaderSignature = preferredInputSignature;
            currentInstance        = preferredInstance;
        }
        private void CreateAttributes()
        {
            int vertexAttribCount = 0;
            for (int i = 0; i < vertexBufferBindings.Length; ++i)
            {
                vertexAttribCount += vertexBufferBindings[i].Declaration.VertexElements.Length;
            }

            vertexAttribs = new VertexAttrib[vertexAttribCount];
            int j = 0;
            for (int i = 0; i < vertexBufferBindings.Length; ++i)
            {
                var inputSlot = vertexBufferBindings[i];
                var vertexBuffer = vertexBufferBindings[i].Buffer;

                foreach (var vertexElementAndOffset in inputSlot.Declaration.EnumerateWithOffsets())
                {
                    var vertexElement = vertexElementAndOffset.VertexElement;
                    var attributeName = "a_" + vertexElement.SemanticName + vertexElement.SemanticIndex;

                    var vertexElementFormat = ConvertVertexElementFormat(vertexElement.Format);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                    IntPtr bufferStart = vertexBuffer.ResourceId == 0
                        ? vertexBuffer.StagingData
                        : (IntPtr)vertexBufferBindings[i].Offset;
#else
                    var bufferStart = (IntPtr)vertexBufferBindings[i].Offset;
#endif
                    vertexAttribs[j] = new VertexAttrib
                    {
                        VertexBufferId = vertexBuffer.ResourceId,
                        Index = -1,
                        IsInteger = IsInteger(vertexElementFormat.Type),
                        Size = vertexElementFormat.Size,
                        Type = vertexElementFormat.Type,
                        Normalized = vertexElementFormat.Normalized,
                        Stride = inputSlot.Declaration.VertexStride,
                        Offset = bufferStart + vertexElementAndOffset.Offset,
                        AttributeName = attributeName
                    };

                    j++;
                }
            }

            if (indexBufferBinding != null)
            {
                indexBufferId = indexBufferBinding.Buffer.resourceId;

#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                if (GraphicsDevice.IsOpenGLES2 && indexBufferBinding.Is32Bit)
                    throw new PlatformNotSupportedException("32 bits index buffer are not supported on OpenGL ES 2.0");
                indexBufferOffset = (indexBufferId == 0 ? indexBufferBinding.Buffer.StagingData : IntPtr.Zero) +
                                    indexBufferBinding.Offset;
#else
                
                indexBufferOffset = (IntPtr)indexBufferBinding.Offset;
#endif
                drawElementsType = indexBufferBinding.Is32Bit ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort;
                indexElementSize = indexBufferBinding.Is32Bit ? 4 : 2;
            }

            // If we have a signature, we can already pre-create the instance
            if (preferredInputSignature != null)
            {
                preferredInstance = GetInstance(preferredInputSignature);
            }

            currentShaderSignature = preferredInputSignature;
            currentInstance = preferredInstance;
        }
 private VertexArrayObjectInstance GetInstance(EffectInputSignature effectInputSignature)
 {
     VertexArrayObjectInstance inputLayout;
     lock (registeredInstances)
     {
         if (!registeredInstances.TryGetValue(effectInputSignature, out inputLayout))
         {
             inputLayout = new VertexArrayObjectInstance(GraphicsDevice, effectInputSignature, vertexAttribs, indexBufferId);
             registeredInstances.Add(effectInputSignature, inputLayout);
         }
     }
     return inputLayout;
 }
        internal void Apply(EffectInputSignature effectInputSignature)
        {
            if (effectInputSignature == null) throw new ArgumentNullException("effectInputSignature");

            // Optimization: If the current VAO and shader signature was previously used, we can use it directly without asking for a proper instance
            if (RequiresApply(effectInputSignature))
            {
                currentInstance = ReferenceEquals(preferredInputSignature, effectInputSignature)
                    ? preferredInstance
                    : GetInstance(effectInputSignature);
                currentShaderSignature = effectInputSignature;
            }

            currentInstance.Apply(GraphicsDevice);
        }