/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
#include <dali/integration-api/debug.h>
#include <dali/public-api/common/dali-vector.h>
#include <dali/public-api/object/property-array.h>
+#include <dali/public-api/rendering/decorated-visual-renderer.h>
#include <typeinfo>
// INTERNAL INCLUDES
{
namespace
{
-const int CUSTOM_PROPERTY_COUNT(6); // alignment + corner/border
+static constexpr int32_t CUSTOM_PROPERTY_COUNT(1); // alignment
DALI_ENUM_TO_STRING_TABLE_BEGIN(UNITS)
DALI_ENUM_TO_STRING_WITH_SCOPE(Toolkit::GradientVisual::Units, OBJECT_BOUNDING_BOX)
DALI_ENUM_TO_STRING_TABLE_END(SPREAD_METHOD)
// uniform names
-const char* const UNIFORM_ALIGNMENT_MATRIX_NAME("uAlignmentMatrix");
+static constexpr std::string_view UNIFORM_ALIGNMENT_MATRIX_NAME("uAlignmentMatrix");
+static constexpr std::string_view UNIFORM_TEXTURE_COORDINATE_SCALE_FACTOR_NAME("uTextureCoordinateScaleFactor");
// default offset value
-const unsigned int DEFAULT_OFFSET_MINIMUM = 0.0f;
-const unsigned int DEFAULT_OFFSET_MAXIMUM = 1.0f;
+static constexpr float DEFAULT_OFFSET_MINIMUM = 0.0f;
+static constexpr float DEFAULT_OFFSET_MAXIMUM = 1.0f;
VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[16] =
{
Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
Shader shader = GenerateShader();
- //Set up the texture set
+ // Set up the texture set
TextureSet textureSet = TextureSet::New();
Dali::Texture lookupTexture = mGradient->GenerateLookupTexture();
textureSet.SetTexture(0u, lookupTexture);
sampler.SetWrapMode(wrap, wrap);
textureSet.SetSampler(0u, sampler);
- mImpl->mRenderer = VisualRenderer::New(geometry, shader);
+ mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
mImpl->mRenderer.SetTextures(textureSet);
mImpl->mRenderer.RegisterUniqueProperty(UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform);
- //Register transform properties
+ float textureSize = static_cast<float>(lookupTexture.GetWidth());
+ mImpl->mRenderer.RegisterUniqueProperty(UNIFORM_TEXTURE_COORDINATE_SCALE_FACTOR_NAME, (textureSize - 1.0f) / textureSize);
+
+ // Register transform properties
mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
}