Download Now

    Reference TContextManagedObject

    Declared in Codebot.Render.Contexts.pas on line 76

    TContextManagedObject provides a way to manage the lifetime of objects such as shaders, textures, and vertex buffers. If no collection is given to the constructor create then the object will be maintained by Ctx.Objects.
    Managed objects require a render context, so they must be created on a thread with a current render context, such as in the OnRenderStart, OnRender, or OnRenderStop events of TGraphicsBox. Any objects not freed by the user are freed when the render context is destroyed. A managed object which owns other managed objects should free them using FreeManaged in its destructor. These are the managed objects defined by the library:
    Codebot.Render.Shaders
    TVertexShader, TFragmentShader compile a single shader stage from source
    TShaderProgram links a vertex and fragment shader into a program. It can be
    created from source, files, or assets, and is made current with Push/Pop.
    Ctx.Shaders is a TShaderCollection which finds programs by name, loading
    name.vert and name.frag from the assets/shaders folder when they do not
    exist. Sources without a #version directive are given one matching the
    API selected in render.inc.
    Codebot.Render.Textures
    TTexture is a 2D texture loaded from a bitmap, stream, file, or RGBA pixel
    data with filter, wrap, and mipmap settings. It is bound to a texture
    slot with Push/Pop.
    Ctx.Textures is a TTextureCollection which finds textures by name, loading
    them from the assets/textures folder when they do not exist
    Codebot.Render.Buffers
    TFlatVertexBuffer, TVertexBuffer, TColorVertexBuffer, TTexVertexBuffer,
    TColorTexVertexBuffer, and TSkinVertexBuffer hold vertices in memory and
    upload them to an OpenGL buffer when drawn after a change. Their fields
    are vertex attributes 0, 1, 2, and so on in order. Without SetProgram
    they draw using a program from
    Ctx.Shaders named after the class, such as 'texvertexbuffer'.
    TTextureBuffer renders to a texture through a framebuffer with a depth buffer
    between StartRecording and StopRecording
    Codebot.Render.World
    TWorld maps a 2D virtual resolution onto a 3D perspective. It is returned by
    Ctx.World and optionally provides a camera, a skybox, and a ground grid.
    TCamera holds a position and direction applied to the modelview matrix
    TSkybox draws an inward facing textured cube around the camera. Its texture
    must be loaded by the user.
    Codebot.Render.Fonts
    TFont renders the glyphs of a TrueType font at a pixel size into a texture
    atlas and lays out text as quads in a TColorTexVertexBuffer
    Ctx.Fonts is a TFontCollection which finds fonts by name, loading name.ttf
    from the assets/fonts folder when they do not exist. Its DefaultFont is
    the roboto font provided with the library assets.
    TTextBlock draws a string with a font, position, scale, and color,
    rebuilding its vertices only when they change
      TContextManagedObject = class(IInterface)
      protected
        function QueryInterface(constref Iid: TGuid; out Obj): LongInt; cdecl ;
        function _AddRef: LongInt; cdecl ;
        function _Release: LongInt; cdecl ;
        { FreeManaged frees a managed object owned by this object and sets it to
          nil. While the render context is being destroyed it only sets it to nil,
          as the render context frees every managed object itself. Use it in place
          of Free in destructors. }
        procedure FreeManaged(var Obj);
      public
        { Create a new item managing its lifetime with a collection and name. If no
          collection is given it will be maintained by Ctx.Objects. }
        constructor Create(Collection: TContextCollection; const Name: string = '');
        { Destroy automatically removes the item from its collection }
        destructor Destroy; override;
        { Setting the name adds to or removes the item from a collection }
        property Name: string read FName write SetName;
      end;

    See also