当前位置: 首页>>代码示例>>C++>>正文


C++ TextureCache::get方法代码示例

本文整理汇总了C++中TextureCache::get方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureCache::get方法的具体用法?C++ TextureCache::get怎么用?C++ TextureCache::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextureCache的用法示例。


在下文中一共展示了TextureCache::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void TextureSource::get_texels_2x2(
    TextureCache&               texture_cache,
    const int                   ix,
    const int                   iy,
    Color4f&                    t00,
    Color4f&                    t10,
    Color4f&                    t01,
    Color4f&                    t11) const
{
    const Vector<size_t, 2> p00 =
        constrain_to_canvas(
            m_texture_instance.get_addressing_mode(),
            m_texture_props.m_canvas_width,
            m_texture_props.m_canvas_height,
            ix + 0,
            iy + 0);

    const Vector<size_t, 2> p11 =
        constrain_to_canvas(
            m_texture_instance.get_addressing_mode(),
            m_texture_props.m_canvas_width,
            m_texture_props.m_canvas_height,
            ix + 1,
            iy + 1);

    const Vector<size_t, 2> p10(p11.x, p00.y);
    const Vector<size_t, 2> p01(p00.x, p11.y);

    // Compute the coordinates of the tile containing each texel.
    const size_t tile_x_00 = truncate<size_t>(p00.x * m_texture_props.m_rcp_tile_width);
    const size_t tile_y_00 = truncate<size_t>(p00.y * m_texture_props.m_rcp_tile_height);
    const size_t tile_x_11 = truncate<size_t>(p11.x * m_texture_props.m_rcp_tile_width);
    const size_t tile_y_11 = truncate<size_t>(p11.y * m_texture_props.m_rcp_tile_height);

    // Check whether all four texels are part of the same tile.
    const size_t tile_x_mask = tile_x_00 ^ tile_x_11;
    const size_t tile_y_mask = tile_y_00 ^ tile_y_11;

    if (tile_x_mask | tile_y_mask)
    {
        // Compute the tile space coordinates of each texel.
        const size_t pixel_x_00 = p00.x - tile_x_00 * m_texture_props.m_tile_width;
        const size_t pixel_y_00 = p00.y - tile_y_00 * m_texture_props.m_tile_height;
        const size_t pixel_x_11 = p11.x - tile_x_11 * m_texture_props.m_tile_width;
        const size_t pixel_y_11 = p11.y - tile_y_11 * m_texture_props.m_tile_height;

        // Sample the tile.
        sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_00, tile_y_00, pixel_x_00, pixel_y_00, t00);
        sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_11, tile_y_00, pixel_x_11, pixel_y_00, t10);
        sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_00, tile_y_11, pixel_x_00, pixel_y_11, t01);
        sample_tile(texture_cache, m_assembly_uid, m_texture_uid, tile_x_11, tile_y_11, pixel_x_11, pixel_y_11, t11);
    }
    else
    {
        // Compute the tile space coordinates of each texel.
        const size_t org_x = tile_x_00 * m_texture_props.m_tile_width;
        const size_t org_y = tile_y_00 * m_texture_props.m_tile_height;
        const size_t pixel_x_00 = p00.x - org_x;
        const size_t pixel_y_00 = p00.y - org_y;
        const size_t pixel_x_11 = p11.x - org_x;
        const size_t pixel_y_11 = p11.y - org_y;

        // Retrieve the tile.
        const Tile& tile =
            texture_cache.get(
                m_assembly_uid,
                m_texture_uid,
                tile_x_00,
                tile_y_00);

        // Sample the tile.
        if (tile.get_channel_count() == 3)
        {
            Color3f rgb;

            tile.get_pixel(pixel_x_00, pixel_y_00, rgb);
            t00[0] = rgb[0];
            t00[1] = rgb[1];
            t00[2] = rgb[2];
            t00[3] = 1.0f;

            tile.get_pixel(pixel_x_11, pixel_y_00, rgb);
            t10[0] = rgb[0];
            t10[1] = rgb[1];
            t10[2] = rgb[2];
            t10[3] = 1.0f;

            tile.get_pixel(pixel_x_00, pixel_y_11, rgb);
            t01[0] = rgb[0];
            t01[1] = rgb[1];
            t01[2] = rgb[2];
            t01[3] = 1.0f;

            tile.get_pixel(pixel_x_11, pixel_y_11, rgb);
            t11[0] = rgb[0];
            t11[1] = rgb[1];
            t11[2] = rgb[2];
            t11[3] = 1.0f;
        }
        else
//.........这里部分代码省略.........
开发者ID:caomw,项目名称:appleseed,代码行数:101,代码来源:texturesource.cpp


注:本文中的TextureCache::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。