Class: SDL2::Texture

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

Overview

This class represents the texture associated with a renderer.

Constant Summary collapse

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:



2405
2406
2407
2408
2409
2410
# File 'ext/sdl2_ext/video.c', line 2405

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:



2328
2329
2330
2331
2332
2333
# File 'ext/sdl2_ext/video.c', line 2328

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:



2345
2346
2347
2348
2349
# File 'ext/sdl2_ext/video.c', line 2345

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:



2299
2300
2301
2302
2303
2304
# File 'ext/sdl2_ext/video.c', line 2299

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:



2315
2316
2317
2318
2319
# File 'ext/sdl2_ext/video.c', line 2315

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

#color_modInteger

Get an additional color value used in render copy operations.

Returns:

  • (Integer)

    the current red, green, and blue color value.



2357
2358
2359
2360
2361
2362
# File 'ext/sdl2_ext/video.c', line 2357

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)

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

Returns:

  • (rgb)


2372
2373
2374
2375
2376
2377
2378
# File 'ext/sdl2_ext/video.c', line 2372

static VALUE Texture_set_color_mod(VALUE self, VALUE rgb)
{
    SDL_Color color = Color_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



2456
2457
2458
2459
2460
2461
2462
2463
# File 'ext/sdl2_ext/video.c', line 2456

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:



2286
2287
2288
2289
2290
# File 'ext/sdl2_ext/video.c', line 2286

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:



2385
2386
2387
2388
2389
2390
# File 'ext/sdl2_ext/video.c', line 2385

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:



2433
2434
2435
2436
2437
2438
# File 'ext/sdl2_ext/video.c', line 2433

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



2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
# File 'ext/sdl2_ext/video.c', line 2441

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:



2419
2420
2421
2422
2423
2424
# File 'ext/sdl2_ext/video.c', line 2419

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