예제 #1
0
        //public bool HasAlpha => !(Min.Alpha == 1.0f && Max.Alpha == 1.0f);

        internal float GetStats(ITexture texture, int layer, int mipmap, StatisticsShader statShader, ReduceShader redShader, bool normalize)
        {
            // obtain a buffer that is big enough
            int numElements = texture.Size.GetMip(mipmap).Product;

            if (layer == -1)
            {
                numElements *= texture.NumLayers;
            }

            if (buffer == null || buffer.ElementCount < numElements)
            {
                buffer?.Dispose();
                buffer = new GpuBuffer(4, numElements);
            }

            // copy all values into buffer
            statShader.CopyToBuffer(texture, buffer, layer, mipmap);

            // execute reduce
            redShader.Run(buffer, numElements);

            shared.Download.CopyFrom(buffer);

            var res = shared.Download.GetData <float>();

            if (normalize)
            {
                res /= numElements;
            }
            return(res);
        }
예제 #2
0
        /// <summary>
        /// allocates a buffer that is big enough to hold numElement floats
        /// </summary>
        /// <param name="numElements"></param>
        /// <returns></returns>
        internal GpuBuffer GetBuffer(int numElements)
        {
            if (buffer == null || buffer.ElementCount < numElements)
            {
                buffer?.Dispose();
                buffer = new GpuBuffer(4, numElements);
            }

            return(buffer);
        }
예제 #3
0
 public override void Dispose()
 {
     coordDstBuffer.Dispose();
     coordShader.Dispose();
     base.Dispose();
 }
예제 #4
0
 public void Dispose()
 {
     shader2D?.Dispose();
     shader3D?.Dispose();
     dstBuffer?.Dispose();
 }
예제 #5
0
 protected override void DisposeManaged()
 {
     vertexBuffer.Dispose();
     indexBuffer.Dispose();
     vao.Dispose();
 }