TextureInstance::TextureInstance(
    const char*             name,
    const ParamArray&       params,
    const char*             texture_name,
    const Transformd&       transform)
  : Entity(g_class_uid, params)
  , impl(new Impl())
{
    set_name(name);

    impl->m_transform = transform;
    impl->m_texture_name = texture_name;

    // todo: retrieve the lighting conditions.
    impl->m_lighting_conditions = LightingConditions(IlluminantCIED65, XYZCMFCIE196410Deg);

    // No bound texture yet.
    m_texture = 0;

    const EntityDefMessageContext message_context("texture instance", this);

    // Retrieve the texture addressing mode.
    const string addressing_mode =
        m_params.get_optional<string>("addressing_mode", "wrap", make_vector("clamp", "wrap"), message_context);
    if (addressing_mode == "clamp")
        m_addressing_mode = TextureAddressingClamp;
    else m_addressing_mode = TextureAddressingWrap;

    // Retrieve the texture filtering mode.
    const string filtering_mode =
        m_params.get_optional<string>("filtering_mode", "bilinear", make_vector("nearest", "bilinear"), message_context);
    if (filtering_mode == "nearest")
        m_filtering_mode = TextureFilteringNearest;
    else m_filtering_mode = TextureFilteringBilinear;

    // Retrieve the texture alpha mode.
    const string alpha_mode =
        m_params.get_optional<string>("alpha_mode", "alpha_channel", make_vector("alpha_channel", "luminance", "detect"), message_context);
    if (alpha_mode == "alpha_channel")
        m_alpha_mode = TextureAlphaModeAlphaChannel;
    else if (alpha_mode == "luminance")
        m_alpha_mode = TextureAlphaModeLuminance;
    else m_alpha_mode = TextureAlphaModeDetect;

    // Until a texture is bound, the effective alpha mode is simply the user-selected alpha mode.
    m_effective_alpha_mode = m_alpha_mode;
}
Exemple #2
0
TextureInstance::TextureInstance(
    const char*             name,
    const ParamArray&       params,
    const char*             texture_name,
    const Transformd&       transform)
  : Entity(g_class_uid, params)
  , impl(new Impl())
{
    set_name(name);

    impl->m_transform = transform;
    impl->m_texture_name = texture_name;

    // todo: retrieve the lighting conditions.
    impl->m_lighting_conditions = LightingConditions(IlluminantCIED65, XYZCMFCIE196410Deg);

    m_texture = 0;

    // Retrieve the texture addressing mode.
    const string addressing_mode = m_params.get_required<string>("addressing_mode", "wrap");
    if (addressing_mode == "clamp")
        m_addressing_mode = TextureAddressingClamp;
    else if (addressing_mode == "wrap")
        m_addressing_mode = TextureAddressingWrap;
    else
    {
        RENDERER_LOG_ERROR(
            "invalid value \"%s\" for parameter \"addressing_mode\", "
            "using default value \"wrap\".",
            addressing_mode.c_str());
        m_addressing_mode = TextureAddressingWrap;
    }

    // Retrieve the texture filtering mode.
    const string filtering_mode = m_params.get_required<string>("filtering_mode", "bilinear");
    if (filtering_mode == "nearest")
        m_filtering_mode = TextureFilteringNearest;
    else if (filtering_mode == "bilinear")
        m_filtering_mode = TextureFilteringBilinear;
    else
    {
        RENDERER_LOG_ERROR(
            "invalid value \"%s\" for parameter \"filtering_mode\", "
            "using default value \"bilinear\".",
            filtering_mode.c_str());
        m_filtering_mode = TextureFilteringBilinear;
    }

    // Retrieve the texture alpha mode.
    const string alpha_mode = m_params.get_optional<string>("alpha_mode", "alpha_channel");
    if (alpha_mode == "alpha_channel")
        m_alpha_mode = TextureAlphaModeAlphaChannel;
    else if (alpha_mode == "luminance")
        m_alpha_mode = TextureAlphaModeLuminance;
    else if (alpha_mode == "detect")
        m_alpha_mode = TextureAlphaModeDetect;
    else
    {
        RENDERER_LOG_ERROR(
            "invalid value \"%s\" for parameter \"alpha_mode\", "
            "using default value \"alpha_channel\".",
            alpha_mode.c_str());
        m_alpha_mode = TextureAlphaModeAlphaChannel;
    }

    // Until a texture is bound, the effective alpha mode is simply the user-selected alpha mode.
    m_effective_alpha_mode = m_alpha_mode;
}