From: Tom Robinson Date: Wed, 6 Jul 2016 18:14:33 +0000 (+0100) Subject: Updated Model3dView control to use SetTexture X-Git-Tag: dali_1.1.43~19^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=28658e9b0c89fced72173c582b9c5635e07bd6f1;ds=sidebyside Updated Model3dView control to use SetTexture Change-Id: I5799a2bbe540b9297de3e0b5581f0f89d93fa107 --- diff --git a/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp b/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp index fc75b7a..56f1efb 100644 --- a/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp +++ b/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -43,6 +44,35 @@ namespace Internal namespace { +// Texture indices are constants. +enum TextureIndex +{ + DIFFUSE_TEXTURE_INDEX, + NORMAL_TEXTURE_INDEX, + GLOSS_TEXTURE_INDEX +}; + +/** + * @brief Loads a texture from a file. + * @param[in] imageUrl The URL of the file + * @return A texture if loading succeeds, an empty handle otherwise + */ +Texture LoadTexture( const char* imageUrl ) +{ + Texture texture; + Dali::BitmapLoader loader = Dali::BitmapLoader::New( imageUrl ); + loader.Load(); + PixelData pixelData = loader.GetPixelData(); + if( pixelData ) + { + texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() ); + texture.Upload( pixelData ); + texture.GenerateMipmaps(); + } + + return texture; +} + // Type registration BaseHandle Create() { @@ -265,10 +295,6 @@ void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vec Model3dView::Model3dView() : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) { - mTexture0Url = ""; - mTexture1Url = ""; - mTexture2Url = ""; - mIlluminationType = Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP; mCameraFOV = Math::PI_OVER_180 * 45.f; @@ -588,41 +614,54 @@ void Model3dView::CreateMaterial() void Model3dView::LoadTextures() { if( !mTextureSet ) - return ; - - if( (mTexture0Url != "") && (mIlluminationType != Toolkit::Model3dView::DIFFUSE) ) { - std::string imgUrl = mImagesUrl + mTexture0Url; - - //Load textures - Image tex0 = ResourceImage::New( imgUrl ); - if( tex0 ) - { - mTextureSet.SetImage( 0u, tex0 ); - } + return; } - if( (mTexture1Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) ) + Sampler sampler = Sampler::New(); + sampler.SetFilterMode( FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR_MIPMAP_LINEAR ); + + // Setup diffuse texture. + if( !mTexture0Url.empty() && ( mIlluminationType != Toolkit::Model3dView::DIFFUSE ) ) { - std::string imgUrl = mImagesUrl + mTexture1Url; + std::string imageUrl = mImagesUrl + mTexture0Url; //Load textures - Image tex1 = ResourceImage::New( imgUrl ); - if (tex1) + Texture diffuseTexture = LoadTexture( imageUrl.c_str() ); + if( diffuseTexture ) { - mTextureSet.SetImage( 1u, tex1 ); + mTextureSet.SetTexture( DIFFUSE_TEXTURE_INDEX, diffuseTexture ); + mTextureSet.SetSampler( DIFFUSE_TEXTURE_INDEX, sampler ); } } - if( (mTexture2Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) ) + if( mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP ) { - std::string imgUrl = mImagesUrl + mTexture2Url; + // Setup normal map texture. + if( !mTexture1Url.empty() ) + { + std::string imageUrl = mImagesUrl + mTexture1Url; - //Load textures - Image tex2 = ResourceImage::New( imgUrl ); - if( tex2 ) + //Load textures + Texture normalTexture = LoadTexture( imageUrl.c_str() ); + if( normalTexture ) + { + mTextureSet.SetTexture( NORMAL_TEXTURE_INDEX, normalTexture ); + mTextureSet.SetSampler( NORMAL_TEXTURE_INDEX, sampler ); + } + } + if( !mTexture2Url.empty() ) { - mTextureSet.SetImage( 2u, tex2 ); + // Setup gloss map texture. + std::string imageUrl = mImagesUrl + mTexture2Url; + + //Load textures + Texture glossTexture = LoadTexture( imageUrl.c_str() ); + if( glossTexture ) + { + mTextureSet.SetTexture( GLOSS_TEXTURE_INDEX, glossTexture ); + mTextureSet.SetSampler( GLOSS_TEXTURE_INDEX, sampler ); + } } } }