Class: SDL2::Texture

Inherits:
Object
  • Object
show all
Defined in:
video.c,
video.c

Overview

This class represents the texture associated with a renderer.

Constant Summary

ACCESS_STATIC =

texture access pattern - changes rarely, not lockable

INT2NUM(SDL_TEXTUREACCESS_STATIC)
ACCESS_STREAMING =

texture access pattern - changes frequently, lockable

INT2NUM(SDL_TEXTUREACCESS_STREAMING)
ACCESS_TARGET =

texture access pattern - can be used as a render target

INT2NUM(SDL_TEXTUREACCESS_TARGET)

Instance Method Summary collapse

Instance Method Details

#access_patternInteger

Get the access pattern allowed for the texture.

The return value is one of the following:

Returns:

  • (Integer)

See Also:



1912
1913
1914
1915
1916
1917
# File 'video.c', line 1912

static VALUE Texture_access_pattern(VALUE self)
{
    int access;
    HANDLE_ERROR(SDL_QueryTexture(Get_SDL_Texture(self), NULL, &access, NULL, NULL));
    return INT2FIX(access);
}

#alpha_modInteger

Get an additional alpha value used in render copy operations.

Returns:

  • (Integer)

    the current alpha value

See Also:



1835
1836
1837
1838
1839
1840
# File 'video.c', line 1835

static VALUE Texture_alpha_mod(VALUE self)
{
    Uint8 alpha;
    HANDLE_ERROR(SDL_GetTextureAlphaMod(Get_SDL_Texture(self), &alpha));
    return INT2FIX(alpha);
}

#alpha_mod=(alpha) ⇒ alpha

Set an additional alpha value used in render copy operations.

Parameters:

  • alpha (Integer)

    the alpha value multiplied into copy operation, from 0 to 255

Returns:

  • (alpha)

See Also:



1852
1853
1854
1855
1856
# File 'video.c', line 1852

static VALUE Texture_set_alpha_mod(VALUE self, VALUE alpha)
{
    HANDLE_ERROR(SDL_SetTextureAlphaMod(Get_SDL_Texture(self), NUM2UCHAR(alpha)));
    return alpha;
}

#blend_modeInteger

Get the blending mode of the texture.

Returns:

  • (Integer)

    blend mode

See Also:



1806
1807
1808
1809
1810
1811
# File 'video.c', line 1806

static VALUE Texture_blend_mode(VALUE self)
{
    SDL_BlendMode mode;
    HANDLE_ERROR(SDL_GetTextureBlendMode(Get_SDL_Texture(self), &mode));
    return INT2FIX(mode);
}

#blend_mode=(mode) ⇒ mode

Set the blending model of the texture.

Parameters:

  • mode (Integer)

    blending mode

Returns:

  • (mode)

See Also:



1822
1823
1824
1825
1826
# File 'video.c', line 1822

static VALUE Texture_set_blend_mode(VALUE self, VALUE mode)
{
    HANDLE_ERROR(SDL_SetTextureBlendMode(Get_SDL_Texture(self), NUM2INT(mode)));
    return mode;
}

#color_mod[Integer, Integer, Integer]

Get an additional color value used in render copy operations.

Returns:

  • ([Integer, Integer, Integer])

    the current red, green, and blue color value.



1864
1865
1866
1867
1868
1869
# File 'video.c', line 1864

static VALUE Texture_color_mod(VALUE self)
{
    Uint8 r, g, b;
    HANDLE_ERROR(SDL_GetTextureColorMod(Get_SDL_Texture(self), &r, &g, &b));
    return rb_ary_new3(3, INT2FIX(r), INT2FIX(g), INT2FIX(b));
}

#color_mod=(rgb) ⇒ rgb

Set an additional color value used in render copy operations.

Parameters:

  • rgb ([Integer, Integer, Integer])

    the red, green, and blue color value multiplied into copy operations.

Returns:

  • (rgb)


1879
1880
1881
1882
1883
1884
1885
# File 'video.c', line 1879

static VALUE Texture_set_color_mod(VALUE self, VALUE rgb)
{
    SDL_Color color = Array_to_SDL_Color(rgb);
    HANDLE_ERROR(SDL_SetTextureColorMod(Get_SDL_Texture(self),
                                        color.r, color.g, color.b));
    return rgb;
}

#debug_infoHash<String=>Object>

Returns (GC) debugging information

Returns:

  • (Hash<String=>Object>)

    (GC) debugging information



1963
1964
1965
1966
1967
1968
1969
1970
# File 'video.c', line 1963

static VALUE Texture_debug_info(VALUE self)
{
    Texture* t = Get_Texture(self);
    VALUE info = rb_hash_new();
    rb_hash_aset(info, rb_str_new2("destroy?"), INT2BOOL(t->texture == NULL));
    rb_hash_aset(info, rb_str_new2("refcount"), INT2NUM(t->refcount));
    return info;
}

#destroyObject

Destroy the texture and deallocate memory.

See Also:



1793
1794
1795
1796
1797
# File 'video.c', line 1793

static VALUE Texture_destroy(VALUE self)
{
    Texture_destroy_internal(Get_Texture(self));
    return Qnil;
}

#destroy?Boolean

Return true if the texture is destroyed.

Returns:

  • (Boolean)

#formatSDL2::PixelFormat

Get the format of the texture.

Returns:



1892
1893
1894
1895
1896
1897
# File 'video.c', line 1892

static VALUE Texture_format(VALUE self)
{
    Uint32 format;
    HANDLE_ERROR(SDL_QueryTexture(Get_SDL_Texture(self), &format, NULL, NULL, NULL));
    return PixelFormat_new(format);
}

#hInteger

Get the height of the texture.

Returns:

  • (Integer)

See Also:



1940
1941
1942
1943
1944
1945
# File 'video.c', line 1940

static VALUE Texture_h(VALUE self)
{
    int h;
    HANDLE_ERROR(SDL_QueryTexture(Get_SDL_Texture(self), NULL, NULL, NULL, &h));
    return INT2FIX(h);
}

#inspectString

Returns inspection string

Returns:

  • (String)

    inspection string



1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
# File 'video.c', line 1948

static VALUE Texture_inspect(VALUE self)
{
    Texture* t = Get_Texture(self);
    Uint32 format;
    int access, w, h;
    if (!t->texture)
        return rb_sprintf("<%s: (destroyed)>", rb_obj_classname(self));

    HANDLE_ERROR(SDL_QueryTexture(t->texture, &format, &access, &w, &h));
    return rb_sprintf("<%s:%p format=%s access=%d w=%d h=%d>",
                      rb_obj_classname(self), (void*)self, SDL_GetPixelFormatName(format),
                      access, w, h);
}

#wInteger

Get the width of the texture.

Returns:

  • (Integer)

See Also:



1926
1927
1928
1929
1930
1931
# File 'video.c', line 1926

static VALUE Texture_w(VALUE self)
{
    int w;
    HANDLE_ERROR(SDL_QueryTexture(Get_SDL_Texture(self), NULL, NULL, &w, NULL));
    return INT2FIX(w);
}