示例#1
0
        private IntPtr AllocateTextureBufferInternal(int size, int width, int height, int format, bool hasMipMaps)
        {
            // :TODO: do we need to know if linear?
            TextureBuffer textureBuffer = new TextureBuffer(size, width, height, format, hasMipMaps, m_idGenerator.GetNextID());

            return(textureBuffer.CreatePointerToMarshalledTextureBuffer());
        }
示例#2
0
        /// <summary>
        /// Called when the first frame rendering is started, and D3DDevice is properly started and functional
        /// </summary>
        private void RenderDeviceStarted()
        {
            // TODO pre-compile shader
            Shader raymarchShader = Shader.CompileFromFiles(@"Shaders\Raymarch");

            raymarchRenderPlane = Mesh.CreateQuad();

            // Set as current shaders
            // TODO what's inputlayout?
            deviceContext.InputAssembler.InputLayout = raymarchShader.InputLayout;
            deviceContext.VertexShader.Set(raymarchShader.VertexShader);
            deviceContext.PixelShader.Set(raymarchShader.PixelShader);

            raymarchShaderBuffer = new ConstantBuffer <RaymarchShaderBufferData>(device);

            // Create buffers for different types of shapes. Combine later?
            primitivesBuffer = new StructuredBuffer <PrimitiveBufferData> [8];
            for (int i = 0; i < primitivesBuffer.Length; i++)
            {
                primitivesBuffer[i] = new StructuredBuffer <PrimitiveBufferData>(device, i);
            }

            noiseTextureBuffer =
                new TextureBuffer <Color>(device, CreateNoise(1024), 1024, Format.R8G8B8A8_UNorm, 1);
        }
示例#3
0
        public TextureDrawingContext(DeviceManager deviceManager, int width, int height)
            : base(deviceManager: deviceManager)
        {
            Width  = width;
            Height = height;

            _textureBuffer = new TextureBuffer(deviceManager, width, height);
            _depthBuffer   = new DepthBuffer(deviceManager, width, height);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="internalFormat"></param>
        /// <param name="elementCount"></param>
        /// <param name="usage"></param>
        /// <param name="noDataCopyed"></param>
        /// <returns></returns>
        public static Texture CreateBufferTexture <T>(uint internalFormat, int elementCount, BufferUsage usage, bool noDataCopyed = false) where T : struct
        {
            var buffer = new TextureBuffer <T>(usage, noDataCopyed);

            buffer.Create(elementCount);
            BufferPtr bufferPtr = buffer.GetBufferPtr();

            return(bufferPtr.DumpBufferTexture(internalFormat, autoDispose: true));
        }
 public void OnReset(object data = null)
 {
     lerpers                   = new TextureLerper[12];
     texturePagePool           = new TexturePagePool();
     textureBuffers            = new TextureBuffer[12];
     externallyUpdatedTextures = new Texture2D[12];
     for (int i = 0; i < 12; i++)
     {
         TextureProperties textureProperties = default(TextureProperties);
         textureProperties.textureFormat = TextureFormat.Alpha8;
         textureProperties.filterMode    = FilterMode.Bilinear;
         textureProperties.blend         = false;
         textureProperties.blendSpeed    = 1f;
         TextureProperties item = textureProperties;
         for (int j = 0; j < this.textureProperties.Length; j++)
         {
             if (i == (int)this.textureProperties[j].simProperty)
             {
                 item = this.textureProperties[j];
             }
         }
         Property property = (Property)i;
         item.name = property.ToString();
         if ((UnityEngine.Object)externallyUpdatedTextures[i] != (UnityEngine.Object)null)
         {
             UnityEngine.Object.Destroy(externallyUpdatedTextures[i]);
             externallyUpdatedTextures[i] = null;
         }
         Texture texture;
         if (item.updatedExternally)
         {
             externallyUpdatedTextures[i] = new Texture2D(Grid.WidthInCells, Grid.HeightInCells, TextureUtil.TextureFormatToGraphicsFormat(item.textureFormat), TextureCreationFlags.None);
             texture = externallyUpdatedTextures[i];
         }
         else
         {
             TextureBuffer[] array     = textureBuffers;
             int             num       = i;
             Property        property2 = (Property)i;
             array[num] = new TextureBuffer(property2.ToString(), Grid.WidthInCells, Grid.HeightInCells, item.textureFormat, item.filterMode, texturePagePool);
             texture    = textureBuffers[i].texture;
         }
         if (item.blend)
         {
             TextureLerper[] array2         = lerpers;
             int             num2           = i;
             Texture         target_texture = texture;
             Property        property3      = (Property)i;
             array2[num2]     = new TextureLerper(target_texture, property3.ToString(), texture.filterMode, item.textureFormat);
             lerpers[i].Speed = item.blendSpeed;
         }
         Shader.SetGlobalTexture(item.texturePropertyName = (texture.name = GetShaderPropertyName((Property)i)), texture);
         allTextureProperties.Add(item);
     }
 }
示例#6
0
        static void Main(string[] args)
        {
            GraphicsDebug.Init();
            Wnd = new Window("Test", 800, 600);

            Pipeline    DefaultPipeline = Wnd.CreatePipeline(new ResourceLayout[] { UniformLayouts.TextureLayout, UniformLayouts.UniformsLayout });
            CommandList List            = Wnd.CreateCommandList();

            MeshBuffer Msh = Wnd.CreateGraphicsObject <MeshBuffer>();

            Msh.Upload(new Vertex3D[] {
                new Vertex3D(new Vector3(0, 0, 0), RgbaFloat.Red, new Vector2(0, 0)),
                new Vertex3D(new Vector3(0, 1, 0), RgbaFloat.Green, new Vector2(0, 1)),
                new Vertex3D(new Vector3(1, 1, 0), RgbaFloat.Blue, new Vector2(1, 1)),
                new Vertex3D(new Vector3(1, 0, 0), RgbaFloat.Yellow, new Vector2(1, 0)),
            }, new ushort[] { 2, 1, 0, 2, 0, 3 });

            TextureBuffer Tex = Wnd.CreateGraphicsObject <TextureBuffer>();

            Tex.Update(UniformLayouts.TextureLayout, Image.FromFile("Data/Textures/Test.png"));

            ResourceSet TexResource = Wnd.CreateResourceSet(UniformLayouts.TextureLayout, new BindableResource[] { Tex.TexView, Tex.TexSampler });

            DeviceBuffer UniformBuffer = Wnd.GfxDev.ResourceFactory.CreateBuffer(new BufferDescription((uint)sizeof(Uniforms), BufferUsage.UniformBuffer, 0));
            ResourceSet  UniformsRes   = Wnd.CreateResourceSet(UniformLayouts.UniformsLayout, new BindableResource[] { UniformBuffer });

            while (!Wnd.ShouldClose)
            {
                {
                    List.Begin();
                    List.SetFramebuffer(Wnd.GetFramebuffer());
                    List.ClearColorTarget(0, RgbaFloat.CornflowerBlue);

                    List.SetPipeline(DefaultPipeline);
                    List.SetGraphicsResourceSet(0, TexResource);

                    /*List.SetGraphicsResourceSet(1, UniformsRes);
                     * List.UpdateBuffer(UniformBuffer, 0, new Uniforms() {
                     *      Clr = new Vector4(50, 143, 168, 255) / new Vector4(255),
                     * });*/

                    Msh.Render(List);

                    List.End();
                }

                Wnd.SubmitCommands(List);
                Wnd.WaitForIdle();
                Wnd.SwapBuffers();
                Wnd.PumpEvents();
            }
        }
        public BlockChunkManager(BlockRegistry blockRegistry,
                                 ResourceManager applicationResourceManager,
                                 IFileSystem userDataFileSystem, FileSystemPath worldDataPathRoot)
        {
            BlockRegistry = blockRegistry ??
                            throw new ArgumentNullException(nameof(blockRegistry));
            Resources = applicationResourceManager ??
                        throw new ArgumentNullException(
                                  nameof(applicationResourceManager));
            this.userDataFileSystem = userDataFileSystem ??
                                      throw new ArgumentNullException(nameof(userDataFileSystem));
            this.worldDataPathRoot = worldDataPathRoot;

            if (!userDataFileSystem.IsWritable)
            {
                Log.Information("The game file system is read-only - any " +
                                "modifications to the game world in this session will " +
                                "not be saved.");
            }

            try
            {
                if (this.worldDataPathRoot.IsEmpty)
                {
                    throw new Exception("The path is empty.");
                }
                if (!this.worldDataPathRoot.IsAbsolute)
                {
                    throw new Exception("The path is not absolute.");
                }
                if (!this.worldDataPathRoot.IsDirectoryPath)
                {
                    throw new Exception("The path references a file, not a " +
                                        "directory.");
                }

                this.worldDataPathRoot = worldDataPathRoot;

                ProbeSaveDirectory();
            }
            catch (Exception exc)
            {
                throw new ArgumentException("The specified save root path " +
                                            "is invalid or inaccessible.", exc);
            }

            if (blockRegistry.HasTexture)
            {
                Resources.LoadTexture(blockRegistry.Texture,
                                      TextureFilter.Nearest).Subscribe(r => BlockTexture = r);
            }
        }
示例#8
0
        public override Texture2D GetTexture(Color[] colors)
        {
            var tex           = new Texture2D(Memory.Graphics.GraphicsDevice, _width, _height);
            var textureBuffer = new TextureBuffer(_width, _height, false);
            var i             = 0;

            foreach (var b in _buffer)
            {
                textureBuffer[i++] = colors[b];
            }
            textureBuffer.SetData(tex);
            return(tex);
        }
示例#9
0
        public Texture2D GetTexture(IColorData[] colors)
        {
            var tex           = new Texture2D(Memory.Graphics.GraphicsDevice, GetWidth, GetHeight);
            var textureBuffer = new TextureBuffer(GetWidth, GetHeight, false);
            var i             = 0;

            foreach (var b in _buffer)
            {
                textureBuffer[i++] = colors[b];
            }
            textureBuffer.SetData(tex);
            return(tex);
        }
示例#10
0
        public override Texture2D GetTexture(Color[] colors)
        {
            Texture2D     tex     = new Texture2D(Memory.graphics.GraphicsDevice, width, height);
            TextureBuffer texbuff = new TextureBuffer(width, height, false);
            int           i       = 0;

            foreach (byte b in buffer)
            {
                texbuff[i++] = colors[b];
            }
            texbuff.SetData(tex);
            return(tex);
        }
示例#11
0
 public TextureRegion(int x, int y, TexturePage page, TextureBuffer buffer)
 {
     this.x         = x;
     this.y         = y;
     this.page      = page;
     this.buffer    = buffer;
     width          = page.width;
     bytesPerPixel  = TextureUtil.GetBytesPerPixel(page.format);
     bytes          = page.bytes;
     floatConverter = new ByteToFloatConverter
     {
         bytes = page.bytes
     };
 }
示例#12
0
 protected override void DoInitialize()
 {
     this.buildListsRenderer.Initialize();
     this.resolve_lists.Initialize();
     {
         var texture = new Texture(TextureTarget.Texture2D,
                                   new NullImageFiller(MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, OpenGL.GL_R32UI, OpenGL.GL_RED_INTEGER, OpenGL.GL_UNSIGNED_BYTE),
                                   new SamplerParameters(TextureWrapping.Repeat, TextureWrapping.Repeat, TextureWrapping.Repeat, TextureFilter.Nearest, TextureFilter.Nearest));
         texture.Initialize();
         this.headTexture = texture;
         OpenGL.BindImageTexture(0, this.headTexture.Id, 0, true, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);
     }
     // Create buffer for clearing the head pointer texture
     //var buffer = new IndependentBuffer<uint>(BufferTarget.PixelUnpackBuffer, BufferUsage.StaticDraw, false);
     using (var buffer = new PixelUnpackBuffer <uint>(BufferUsage.StaticDraw, false))
     {
         buffer.Create(MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT);
         // NOTE: not all initial values are zero in this unmanged array.
         //unsafe
         //{
         //    var array = (uint*)buffer.Header.ToPointer();
         //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
         //    {
         //        array[i] = 0;
         //    }
         //}
         this.headClearBufferPtr = buffer.GetBufferPtr() as PixelUnpackBufferPtr;
     }
     // Create the atomic counter buffer
     using (var buffer = new AtomicCounterBuffer <uint>(BufferUsage.DynamicCopy, false))
     {
         buffer.Create(1);
         this.atomicCountBufferPtr = buffer.GetBufferPtr() as AtomicCounterBufferPtr;
     }
     // Bind it to a texture (for use as a TBO)
     using (var buffer = new TextureBuffer <vec4>(BufferUsage.DynamicCopy, noDataCopyed: false))
     {
         buffer.Create(elementCount: MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * 3);
         IndependentBufferPtr bufferPtr = buffer.GetBufferPtr();
         Texture texture = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32UI, autoDispose: true);
         texture.Initialize();
         bufferPtr.Dispose();// dispose it ASAP.
         this.linkedListTexture = texture;
     }
     {
         OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
     }
     OpenGL.ClearDepth(1.0f);
 }
示例#13
0
        public void Add(string fileName, int index, int width = 64, int height = 64)
        {
            Bitmap textureBmp = new Bitmap($"Resources\\textures\\{fileName}");

            Pixel[] texture = new Pixel[width * height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    texture[x * width + y]       = new Pixel();
                    texture[x * width + y].Color = textureBmp.GetPixel(y, x);
                    texture[x * width + y].X     = x;
                    texture[x * width + y].Y     = y;
                }
            }
            TextureBuffer.Add(index, texture);
        }
示例#14
0
 public TextureWorkItemCollection(PropertyTextureUpdater instance,
                                  TextureBuffer buffer, Vector2I min, Vector2I max, UpdateTexture updater)
 {
     parent = instance ?? throw new ArgumentNullException(nameof(instance));
     xMin   = min.x;
     xMax   = max.x;
     yMin   = min.y;
     yMax   = max.y;
     if (xMax < xMin || yMax < yMin)
     {
         throw new ArgumentOutOfRangeException(nameof(max));
     }
     if (buffer == null)
     {
         throw new ArgumentNullException(nameof(buffer));
     }
     region        = buffer.Lock(xMin, yMin, xMax - xMin + 1, yMax - yMin + 1);
     Count         = 1 + (yMax - yMin) / TEXTURE_RESOLUTION;
     updateTexture = updater ?? throw new ArgumentNullException(nameof(updater));
 }
示例#15
0
        public void SetTextureBuffer(TargetBuffer Target, PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type, int Width, int Height, int Number = 0)
        {
            TextureBuffer buffer = new TextureBuffer(InternalFormat, Format, Type, Width, Height);

            switch (Target)
            {
            case TargetBuffer.Color:
                if (colorBuffers.ContainsKey(Number))
                {
                    UnBind();
                    colorBuffers[Number].Dispose();
                    Bind();
                }
                colorBuffers[Number] = buffer;
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0 + Number), TextureTarget.Texture2D, buffer.handle, 0);
                break;

            case TargetBuffer.Depth:
                if (depthBuffer != null)
                {
                    UnBind();
                    depthBuffer.Dispose();
                    Bind();
                }
                depthBuffer = buffer;
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, buffer.handle, 0);
                break;

            case TargetBuffer.Stencil:
                if (stencilBuffer != null)
                {
                    UnBind();
                    stencilBuffer.Dispose();
                    Bind();
                }
                stencilBuffer = buffer;
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, TextureTarget.Texture2D, buffer.handle, 0);
                break;
            }
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public RectangleTexture(TextureBuffer pBuffer)
     : base(pBuffer, "RectangleTexture") {
     mColour = ColourValue.White;
     mX1 = 0;
     mY1 = 0;
     mX2 = pBuffer.getWidth();
     mY2 = pBuffer.getHeight();
 }
示例#17
0
 protected override void DoInitialize()
 {
     this.buildListsRenderer.Initialize();
     this.resolve_lists.Initialize();
     {
         var texture = new Texture(TextureTarget.Texture2D,
                                   new NullImageFiller(MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, OpenGL.GL_R32UI, OpenGL.GL_RED_INTEGER, OpenGL.GL_UNSIGNED_BYTE),
                                   new SamplerParameters(TextureWrapping.Repeat, TextureWrapping.Repeat, TextureWrapping.Repeat, TextureFilter.Nearest, TextureFilter.Nearest));
         texture.Initialize();
         this.headTexture = texture;
         OpenGL.BindImageTexture(0, this.headTexture.Id, 0, true, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);
     }
     // Create buffer for clearing the head pointer texture
     {
         const int         length = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT;
         PixelUnpackBuffer buffer = PixelUnpackBuffer.Create(typeof(uint), length, BufferUsage.StaticDraw);
         // NOTE: not all initial values are zero in this unmanged array.
         // initialize buffer's value to 0.
         //unsafe
         //{
         //    IntPtr pointer = ptr.MapBuffer(MapBufferAccess.WriteOnly);
         //    var array = (uint*)pointer.ToPointer();
         //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
         //    {
         //        array[i] = 0;
         //    }
         //}
         // another way to initialize buffer's value to 0.
         //using (var data = new UnmanagedArray<uint>(1))
         //{
         //    data[0] = 0;
         //    ptr.ClearBufferData(OpenGL.GL_UNSIGNED_INT, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_INT, data);
         //}
         this.headClearBuffer = buffer;
     }
     // Create the atomic counter buffer
     {
         const int           length = 1;
         AtomicCounterBuffer buffer = AtomicCounterBuffer.Create(typeof(uint), length, BufferUsage.DynamicCopy);
         // another way to do this:
         //uint data = 1;
         //AtomicCounterBuffer buffer = data.GenAtomicCounterBuffer(BufferUsage.DynamicCopy);
         this.atomicCountBuffer = buffer;
     }
     // Bind it to a texture (for use as a TBO)
     {
         const int     length  = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * 3;
         TextureBuffer buffer  = TextureBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
         Texture       texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32UI, autoDispose: true);
         texture.Initialize();
         buffer.Dispose();// dispose it ASAP.
         this.linkedListTexture = texture;
     }
     {
         //TextureBuffer buffer = TextureBuffer.Create()
     }
     {
         OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
     }
     OpenGL.ClearDepth(1.0f);
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Flip(TextureBuffer pBuffer)
     : base(pBuffer, "Flip") {
     mAxis = FLIP_AXIS.FLIP_VERTICAL;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Invert(TextureBuffer pBuffer)
     : base(pBuffer, "Invert") {
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Channel(TextureBuffer pBuffer)
     : base(pBuffer, "Channel") {
     mSelection = CANNEL_SELECTION.SELECT_GRAY;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Segment(TextureBuffer pBuffer)
     : base(pBuffer, "Segment") {
     mThreshold = 128;
     mColourSource = null;
 }
        //    *
        //	Set parameter image for colour source.
        //	\param coloursource Pointer to an input image (default NULL)
        //	

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public Segment setColourSource(TextureBuffer coloursource) {
            mColourSource = coloursource;
            return this;
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public TextureLightBaker(TextureBuffer pBuffer)
     : base(pBuffer, "Light") {
     mNormal = null;
     mColourAmbient = ColourValue.Black;
     mColourDiffuse = new ColourValue(0.5f, 0.5f, 0.5f, 1.0f);
     mColourSpecular = ColourValue.White;
     mPosition = new Vector3(255.0f, 255.0f, 127.0f);
     mSpecularPower = 0;
     mBumpPower = 0;
 }
        //    *
        //	Set parameter image for compensation.
        //	\param normal Pointer to an normal map image (default NULL)
        //	\note If the parameter normal is set to NULL a clone of the base input image will be used as normal map with Normals filter.
        //	

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public TextureLightBaker setNormalMap(TextureBuffer normal) {
            mNormal = normal;
            return this;
        }
        //    *
        //	Set first image (a).
        //	\param image1 Pointer to a new first image (default NULL)
        //	

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public Lerp setImageA(TextureBuffer image1) {
            mBufferA = image1;
            return this;
        }
 //    *
 //	Set second image (b).
 //	\param image2 Pointer to a new second image (default NULL)
 //	
 public Lerp setImageB(TextureBuffer image2) {
     mBufferB = image2;
     return this;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public AlphaMask(TextureBuffer pBuffer)
     : base(pBuffer, "AlphaMask") {
     mColourMask = false;
     mParam = null;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	\note This is the third image (c).
 //	
 public Lerp(TextureBuffer pBuffer)
     : base(pBuffer, "Lerp") {
     mBufferA = null;
     mBufferB = null;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Jitter(TextureBuffer pBuffer)
     : base(pBuffer, "Jitter") {
     mRadius = 57;
     mSeed = 5120;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public RotationZoom(TextureBuffer pBuffer)
     : base(pBuffer, "RotationZoom") {
     mCenterX = 0.5f;
     mCenterY = 0.5f;
     mZoomX = 1.0f;
     mZoomY = 1.0f;
     mRotation = 0.0f;
     mWrap = true;
 }
 //    *
 //	Set parameter image for masking/colouring.
 //	\param image Pointer to second image (default NULL)
 //	\note Methode 1 is used if the parameter image is set to zero. If the size of the parameter image is smaller than the base buffer the operation will be canceled without any image manipulation.
 //	
 public AlphaMask setParameterImage(TextureBuffer image) {
     mParam = image;
     return this;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Blit(TextureBuffer pBuffer)
     : base(pBuffer, "Blit") {
     mInputBuffer = null;
     mOutputRect.left = 0;
     mOutputRect.top = 0;
     mOutputRect.right = (int)pBuffer.getWidth();
     mOutputRect.bottom = (int)pBuffer.getHeight();
 }
//    *
//	Default constructor.
//	\param pBuffer Image buffer where to modify the image.
//	
	public TextTexture(TextureBuffer pBuffer) : base(pBuffer, "TextTexture")
	{
		mText = "OgreProcedural";
		mFontSize = 12;
		mColour = ColourValue.Black;
		mX = pBuffer.getWidth() / 2;
		mY = pBuffer.getHeight() / 2;
	}
        //    *
        //	Sets the texture buffer that must be copied towards the current texture buffer
        //	\param inputBuffer Pointer on image where to copy from
        //	

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public Blit setInputBuffer(TextureBuffer inputBuffer) {
            if (inputBuffer != null)
                if (inputBuffer.getHeight() >= mBuffer.getHeight() && inputBuffer.getWidth() >= mBuffer.getWidth()) {
                    mInputBuffer = inputBuffer;
                    mInputRect.left = 0;
                    mInputRect.top = 0;
                    mInputRect.right = (int)inputBuffer.getWidth();
                    mInputRect.bottom = (int)inputBuffer.getHeight();
                }
            return this;
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Vortex(TextureBuffer pBuffer)
     : base(pBuffer, "Vortex") {
     mCenterX = 0.5f;
     mCenterY = 0.5f;
     mRadiusX = 0.5f;
     mRadiusY = 0.5f;
     mTwist = Math.HALF_PI;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Sharpen(TextureBuffer pBuffer)
     : base(pBuffer, "Sharpen") {
     mSize = 5;
     mSigma = 92;
     mType = (int)SHARP_TYPE.SHARP_BASIC;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Glow(TextureBuffer pBuffer)
     : base(pBuffer, "Glow") {
     mColour = ColourValue.White;
     mCenterX = 0.5f;
     mCenterY = 0.5f;
     mRadiusX = 0.5f;
     mRadiusY = 0.5f;
     mAlpha = 1.0f;
     mGamma = 1.0f;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Threshold(TextureBuffer pBuffer)
     : base(pBuffer, "Threshold") {
     mThreshold = 128;
     mRatio = 128;
     mMode = THRESHOLD_MODE.MODE_EXPAND_DOWNWARDS;
 }
示例#39
0
        public GameWorld(GameWorldConfiguration configuration,
                         FileSystemPath worldFilePath, TrippingCubesGame game)
        {
            DateTime startTime = DateTime.Now;

            Game = game;

            Entities = new ReadOnlyCollection <IEntity>(entities);

            Physics = new PhysicsSystem(IsBlockSolid, IsBlockLiquid);

            Paths = new ReadOnlyDictionary <string, PathLinear>(
                configuration.Paths ?? new Dictionary <string, PathLinear>());

            Log.Trace("Initializing world style...");
            try
            {
                Game.Resources.LoadMesh(MeshData.Skybox).Subscribe(
                    r => skyboxMesh = r);
                Game.Resources.LoadTexture(configuration.SkyboxPath,
                                           TextureFilter.Linear).Subscribe(
                    r => skyboxTexture = r);
                if (!configuration.InnerSkyboxPath.IsEmpty)
                {
                    Game.Resources.LoadTexture(configuration.InnerSkyboxPath,
                                               TextureFilter.Linear).Subscribe(
                        r => innerSkyboxTexture = r);
                }
            }
            catch (Exception exc)
            {
                Log.Warning("The skybox couldn't be loaded and will not " +
                            "be available.", exc);
            }
            try
            {
                DateTime             localStartTime       = DateTime.Now;
                BlockRegistryBuilder blockRegistryBuilder =
                    BlockRegistryBuilder.FromXml(
                        configuration.BlockRegistryPath,
                        FileSystem, false);
                Blocks = blockRegistryBuilder.GenerateRegistry(
                    FileSystem);
                Log.Trace("Block registry with " + Blocks.Count +
                          " block definitions initialized in " +
                          (DateTime.Now - localStartTime).TotalMilliseconds + "ms.");
            }
            catch (Exception exc)
            {
                throw new Exception("The block registry couldn't be " +
                                    "initialized.", exc);
            }


            Log.Trace("Initializing world chunk manager...");
            try
            {
                FileSystemPath primaryWorldBackupPath =
                    FileSystemPath.Combine(worldFilePath.GetParentDirectory(),
                                           $"{worldFilePath.GetFileName(false)}1");
                FileSystemPath secondaryWorldBackupPath =
                    FileSystemPath.Combine(worldFilePath.GetParentDirectory(),
                                           $"{worldFilePath.GetFileName(false)}2");

                if (FileSystem.IsWritable)
                {
                    try
                    {
                        if (FileSystem.ExistsFile(primaryWorldBackupPath))
                        {
                            using Stream secondaryBackupStream =
                                      FileSystem.CreateFile(secondaryWorldBackupPath,
                                                            true);
                            using Stream primaryWorldBackup =
                                      FileSystem.OpenFile(primaryWorldBackupPath,
                                                          false);

                            primaryWorldBackup.CopyTo(secondaryBackupStream);
                        }

                        if (FileSystem.ExistsFile(worldFilePath))
                        {
                            using Stream primaryWorldBackup =
                                      FileSystem.CreateFile(primaryWorldBackupPath,
                                                            true);
                            using Stream worldFile =
                                      FileSystem.OpenFile(worldFilePath, false);

                            worldFile.CopyTo(primaryWorldBackup);
                        }
                    }
                    catch (Exception exc)
                    {
                        throw new Exception("The world backups couldn't be " +
                                            "updated.", exc);
                    }
                }

                if (FileSystem.ExistsFile(worldFilePath))
                {
                    zipFileSystem = new ZipFileSystem(FileSystem.OpenFile(
                                                          worldFilePath, FileSystem.IsWritable));
                }
                else if (FileSystem.IsWritable)
                {
                    Log.Information("No world data file was found at the " +
                                    "specified path. A new world file is initialized.");
                    zipFileSystem = ZipFileSystem.Initialize(FileSystem,
                                                             worldFilePath, false);
                }
                else
                {
                    throw new Exception("The world data file doesn't exist " +
                                        $"under the path {worldFilePath} and can't be created, " +
                                        "as the file system is read-only.");
                }

                RootChunk = new Chunk <BlockVoxel>(
                    new BlockChunkManager(Blocks, Game.Resources,
                                          zipFileSystem, "/"));
            }
            catch (Exception exc)
            {
                throw new Exception("The world chunk manager couldn't be " +
                                    "initialized.", exc);
            }


            Log.Trace("Spawning entities...");
            foreach (EntityInstantiation instantiation in
                     configuration.Entities)
            {
                if (configuration.EntityConfigurations.TryGetValue(
                        instantiation.ConfigurationIdentifier,
                        out EntityConfiguration entityConfiguration))
                {
                    try
                    {
                        IEntity entity = entityConfiguration.Instantiate(this,
                                                                         instantiation.InstanceParameters);
                        entities.Add(entity);
                    }
                    catch (Exception exc)
                    {
                        Log.Warning($"Entity #{entities.Count} couldn't " +
                                    "be spawned and will be skipped.", exc);
                    }
                }
            }
            Log.Trace($"Spawned {entities.Count} entities.");

            Log.Trace("Game world initialized in " +
                      (DateTime.Now - startTime).TotalMilliseconds + "ms.");
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Blur(TextureBuffer pBuffer)
     : base(pBuffer, "Blur") {
     mSize = 5;
     mSigma = 92;
     mType = (int)BLUR_TYPE.BLUR_BOX;
 }
示例#41
0
 public void Apply()
 {
     Transformations = MatrixBuffer.ToArray();
     Textures        = TextureBuffer.ToArray();
     ChunkManager.PullingShaderData = true;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public CircleTexture(TextureBuffer pBuffer)
     : base(pBuffer, "CircleTexture") {
     mColour = ColourValue.White;
     mRadius = (int)System.Math.Min(pBuffer.getWidth(), pBuffer.getHeight()) / 2;
     mX = mRadius;
     mY = mRadius;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public RandomPixels(TextureBuffer pBuffer)
     : base(pBuffer, "RandomPixels") {
     mColour = ColourValue.White;
     mSeed = 5120;
     mCount = ((uint)Math.Sqrt((float)mBuffer.getWidth()) + (uint)Math.Sqrt((float)mBuffer.getHeight())) * 10;
 }
        //    *
        //	Set parameter image for coordinates mapping.
        //	\param image Pointer to second image (default NULL)
        //	\note If the parameter image is set to NULL there won't be any image manipulation.
        //	

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public Lookup setParameterImage(TextureBuffer image) {
            mParam = image;
            return this;
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public EllipseTexture(TextureBuffer pBuffer)
     : base(pBuffer, "EllipseTexture") {
     mColour = ColourValue.White;
     mRadiusX = (int)pBuffer.getWidth() / 2;
     mX = mRadiusX;
     mRadiusY = (int)pBuffer.getHeight() / 2;
     mY = mRadiusY;
 }
示例#46
0
        private void UpdateResources(int width, int height)
        {
            {
                if (this.headTexture != null)
                {
                    this.headTexture.Dispose();
                }

                int  level = 0, border = 0;
                uint internalformat = GL.GL_R32UI, format = GL.GL_RED_INTEGER, type = GL.GL_UNSIGNED_BYTE;
                var  storage = new TexImage2D(TexImage2D.Target.Texture2D, level, internalformat, width, height, border, format, type);
                var  texture = new Texture(TextureTarget.Texture2D, storage,
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_NEAREST),
                                           TexParameter.Create(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_NEAREST)
                                           );
                texture.Initialize();

                this.headTexture = texture;
            }
            // Create buffer for clearing the head pointer texture
            {
                if (this.headClearBuffer != null)
                {
                    this.headClearBuffer.Dispose();
                }

                int length = width * height;
                // NOTE: not all initial values are zero in this unmanged array.
                PixelUnpackBuffer buffer = PixelUnpackBuffer.Create(typeof(uint), length, BufferUsage.StaticDraw);
                // initialize buffer's value to 0.
                //unsafe
                //{
                //    IntPtr pointer = ptr.MapBuffer(MapBufferAccess.WriteOnly);
                //    var array = (uint*)pointer.ToPointer();
                //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
                //    {
                //        array[i] = 0;
                //    }
                //}
                // another way to initialize buffer's value to 0.
                //using (var data = new UnmanagedArray<uint>(1))
                //{
                //    data[0] = 0;
                //    ptr.ClearBufferData(OpenGL.GL_UNSIGNED_INT, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_INT, data);
                //}

                this.headClearBuffer = buffer;
            }
            // Bind it to a texture (for use as a TBO)
            {
                if (this.linkedListTexture != null)
                {
                    this.linkedListTexture.Dispose();
                }

                int           length         = width * height * 3;
                TextureBuffer buffer         = TextureBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
                uint          internalFormat = GL.GL_RGBA32UI;
                Texture       texture        = buffer.DumpBufferTexture(internalFormat, autoDispose: true);
                texture.Initialize();
                buffer.Dispose();// dispose it ASAP.

                this.linkedListTexture = texture;
            }
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Normals(TextureBuffer pBuffer)
     : base(pBuffer, "Normals") {
     mAmplify = 64;
 }
示例#48
0
        /// <summary>
        /// Starts a multithreaded texture update. Uses the asynchronous job manager.
        /// </summary>
        /// <param name="property">The property to update.</param>
        /// <param name="buffer">The texture where the updates will be stored.</param>
        /// <param name="min">The minimum cell coordinates to update.</param>
        /// <param name="max">The maximum cell coordinates to update.</param>
        private void StartTextureUpdate(SimProperty property, TextureBuffer buffer,
                                        Vector2I min, Vector2I max)
        {
            UpdateTexture updater;

            switch (property)
            {
            case SimProperty.StateChange:
                updater = PropertyTextures.UpdateStateChange;
                break;

            case SimProperty.GasPressure:
                updater = PropertyTextures.UpdatePressure;
                break;

            case SimProperty.GasColour:
                updater = PropertyTextures.UpdateGasColour;
                break;

            case SimProperty.GasDanger:
                updater = PropertyTextures.UpdateDanger;
                break;

            case SimProperty.FogOfWar:
                updater = PropertyTextures.UpdateFogOfWar;
                break;

            case SimProperty.SolidDigAmount:
                updater = PropertyTextures.UpdateSolidDigAmount;
                break;

            case SimProperty.SolidLiquidGasMass:
                updater = PropertyTextures.UpdateSolidLiquidGasMass;
                break;

            case SimProperty.WorldLight:
                updater = PropertyTextures.UpdateWorldLight;
                break;

            case SimProperty.Temperature:
                updater = PropertyTextures.UpdateTemperature;
                break;

            case SimProperty.FallingSolid:
                updater = PropertyTextures.UpdateFallingSolidChange;
                break;

            case SimProperty.Radiation:
                updater = PropertyTextures.UpdateRadiation;
                break;

            default:
                throw new ArgumentException("No updater for property: " + property);
            }
            if (updater == null)
            {
                throw new InvalidOperationException("Missing texture updater: " + property);
            }
            else
            {
                running.Add(new TextureWorkItemCollection(this, buffer, min, max, updater));
            }
        }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public OilPaint(TextureBuffer pBuffer)
     : base(pBuffer, "OilPaint") {
     mRadius = 3;
     mIntensity = 20.0f;
 }
 //    *
 //	Default constructor.
 //	\param pBuffer Image buffer where to modify the image.
 //	
 public Lookup(TextureBuffer pBuffer)
     : base(pBuffer, "Lookup") {
     mParam = null;
 }
示例#51
0
 /// <summary>
 /// Binds the given buffer texture to an image unit.
 /// </summary>
 /// <param name="imageUnit">The image unit to use.</param>
 /// <param name="textureBuffer">The buffer texture to bind.</param>
 /// <param name="access">Specifies the type of access allowed on the image.</param>
 public void Bind(int imageUnit, TextureBuffer textureBuffer, TextureAccess access)
 {
     Bind(imageUnit, textureBuffer, 0, false, 0, access);
 }