class cv::ogl::Texture2D

Overview

Smart pointer for OpenGL 2D texture memory with reference counting. More…

#include <opengl.hpp>

class Texture2D
{
public:
    // enums

    enum Format;

    // construction

    Texture2D();

    Texture2D(
        int arows,
        int acols,
        Format aformat,
        unsigned int atexId,
        bool autoRelease = false
        );

    Texture2D(
        Size asize,
        Format aformat,
        unsigned int atexId,
        bool autoRelease = false
        );

    Texture2D(
        int arows,
        int acols,
        Format aformat,
        bool autoRelease = false
        );

    Texture2D(
        Size asize,
        Format aformat,
        bool autoRelease = false
        );

    Texture2D(
        InputArray arr,
        bool autoRelease = false
        );

    // methods

    void
    bind() const;

    int
    cols() const;

    void
    copyFrom(
        InputArray arr,
        bool autoRelease = false
        );

    void
    copyTo(
        OutputArray arr,
        int ddepth = CV_32F,
        bool autoRelease = false
        ) const;

    void
    create(
        int arows,
        int acols,
        Format aformat,
        bool autoRelease = false
        );

    void
    create(
        Size asize,
        Format aformat,
        bool autoRelease = false
        );

    bool
    empty() const;

    Format
    format() const;

    void
    release();

    int
    rows() const;

    void
    setAutoRelease(bool flag);

    Size
    size() const;

    unsigned int
    texId() const;
};

Detailed Documentation

Smart pointer for OpenGL 2D texture memory with reference counting.

Construction

Texture2D()

The constructors.

Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from host/device memory.

Texture2D(
    int arows,
    int acols,
    Format aformat,
    unsigned int atexId,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Texture2D(
    Size asize,
    Format aformat,
    unsigned int atexId,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Texture2D(
    int arows,
    int acols,
    Format aformat,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

arows Number of rows.
acols Number of columns.
aformat Image format. See cv::ogl::Texture2D::Format.
autoRelease Auto release mode (if true, release will be called in object’s destructor).
Texture2D(
    Size asize,
    Format aformat,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

asize 2D array size.
aformat Image format. See cv::ogl::Texture2D::Format.
autoRelease Auto release mode (if true, release will be called in object’s destructor).
Texture2D(
    InputArray arr,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

arr Input array (host or device memory, it can be Mat, cuda::GpuMat or ogl::Buffer).
autoRelease Auto release mode (if true, release will be called in object’s destructor).

Methods

void
bind() const

Binds texture to current active texture unit for GL_TEXTURE_2D target.

void
copyFrom(
    InputArray arr,
    bool autoRelease = false
    )

Copies from host/device memory to OpenGL texture.

Parameters:

arr Input array (host or device memory, it can be Mat, cuda::GpuMat or ogl::Buffer).
autoRelease Auto release mode (if true, release will be called in object’s destructor).
void
copyTo(
    OutputArray arr,
    int ddepth = CV_32F,
    bool autoRelease = false
    ) const

Copies from OpenGL texture to host/device memory or another OpenGL texture object.

Parameters:

arr Destination array (host or device memory, can be Mat, cuda::GpuMat, ogl::Buffer or ogl::Texture2D).
ddepth Destination depth.
autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture).
void
create(
    int arows,
    int acols,
    Format aformat,
    bool autoRelease = false
    )

Allocates memory for ogl::Texture2D object.

Parameters:

arows Number of rows.
acols Number of columns.
aformat Image format. See cv::ogl::Texture2D::Format.
autoRelease Auto release mode (if true, release will be called in object’s destructor).
void
create(
    Size asize,
    Format aformat,
    bool autoRelease = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

asize 2D array size.
aformat Image format. See cv::ogl::Texture2D::Format.
autoRelease Auto release mode (if true, release will be called in object’s destructor).
void
release()

Decrements the reference counter and destroys the texture object if needed.

The function will call setAutoRelease(true) .

void
setAutoRelease(bool flag)

Sets auto release mode.

The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was bound to a window it could be released at any time (user can close a window). If object’s destructor is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn’t destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context). This function can force ogl::Texture2D destructor to destroy OpenGL object.

Parameters:

flag Auto release mode (if true, release will be called in object’s destructor).
unsigned int
texId() const

get OpenGL opject id