1 #ifndef DALI_INTERNAL_RENDER_SAMPLER_H
2 #define DALI_INTERNAL_RENDER_SAMPLER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <dali/graphics-api/graphics-controller.h>
21 #include <dali/public-api/actors/sampling.h>
22 #include <dali/public-api/rendering/sampler.h>
31 * The sampler class holds the min/mag filter and texture wrap modes.
32 * It's graphics counterpart is only created when needed, and also
33 * only created when the filters and wrap modes are not default
38 using FilterMode = Dali::FilterMode::Type;
39 using WrapMode = Dali::WrapMode::Type;
51 bool operator==(const Sampler& rhs) const
53 return ((mMinificationFilter == rhs.mMinificationFilter) &&
54 (mMagnificationFilter == rhs.mMagnificationFilter) &&
55 (mSWrapMode == rhs.mSWrapMode) &&
56 (mTWrapMode == rhs.mTWrapMode) &&
57 (mRWrapMode == rhs.mRWrapMode));
60 bool operator!=(const Sampler& rhs) const
62 return !(*this == rhs);
66 * Returns Graphics API sampler object
67 * @return Pointer to API sampler or nullptr
69 const Dali::Graphics::Sampler* GetGraphicsObject();
71 [[nodiscard]] static inline Graphics::SamplerAddressMode GetGraphicsSamplerAddressMode(WrapMode mode)
75 case WrapMode::REPEAT:
76 return Graphics::SamplerAddressMode::REPEAT;
77 case WrapMode::MIRRORED_REPEAT:
78 return Graphics::SamplerAddressMode::MIRRORED_REPEAT;
79 case WrapMode::CLAMP_TO_EDGE:
80 case WrapMode::DEFAULT:
81 return Graphics::SamplerAddressMode::CLAMP_TO_EDGE;
86 [[nodiscard]] static inline Graphics::SamplerMipmapMode GetGraphicsSamplerMipmapMode(FilterMode mode)
90 case FilterMode::LINEAR_MIPMAP_LINEAR:
91 case FilterMode::NEAREST_MIPMAP_LINEAR:
92 return Graphics::SamplerMipmapMode::LINEAR;
93 case FilterMode::NEAREST_MIPMAP_NEAREST:
94 case FilterMode::LINEAR_MIPMAP_NEAREST:
95 return Graphics::SamplerMipmapMode::NEAREST;
97 return Graphics::SamplerMipmapMode::NONE;
102 [[nodiscard]] static inline Graphics::SamplerFilter GetGraphicsFilter(FilterMode mode)
106 case FilterMode::LINEAR:
107 case FilterMode::LINEAR_MIPMAP_LINEAR:
108 case FilterMode::LINEAR_MIPMAP_NEAREST:
109 return Graphics::SamplerFilter::LINEAR;
110 case FilterMode::NEAREST:
111 case FilterMode::NEAREST_MIPMAP_LINEAR:
112 case FilterMode::NEAREST_MIPMAP_NEAREST:
113 return Graphics::SamplerFilter::NEAREST;
114 case FilterMode::DEFAULT:
115 return Graphics::SamplerFilter::LINEAR;
116 case FilterMode::NONE:
117 return Graphics::SamplerFilter::NEAREST;
125 * Sets the filter modes for an existing sampler
126 * @param[in] sampler The sampler
127 * @param[in] minFilterMode The filter to use under minification
128 * @param[in] magFilterMode The filter to use under magnification
130 inline void SetFilterMode(unsigned int minFilterMode, unsigned int magFilterMode)
132 mMinificationFilter = static_cast<Dali::FilterMode::Type>(minFilterMode);
133 mMagnificationFilter = static_cast<Dali::FilterMode::Type>(magFilterMode);
138 * Sets the wrap mode for an existing sampler
139 * @param[in] sampler The sampler
140 * @param[in] rWrapMode Wrapping mode in z direction
141 * @param[in] sWrapMode Wrapping mode in x direction
142 * @param[in] tWrapMode Wrapping mode in y direction
144 inline void SetWrapMode(unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode)
146 mRWrapMode = static_cast<Dali::WrapMode::Type>(rWrapMode);
147 mSWrapMode = static_cast<Dali::WrapMode::Type>(sWrapMode);
148 mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
153 * Check if the sampler has default values
155 [[nodiscard]] inline bool IsDefaultSampler() const
157 return (mMagnificationFilter == FilterMode::DEFAULT &&
158 mMinificationFilter == FilterMode::DEFAULT &&
159 mSWrapMode == WrapMode::DEFAULT &&
160 mTWrapMode == WrapMode::DEFAULT &&
161 mRWrapMode == WrapMode::DEFAULT);
164 void Initialize(Graphics::Controller& graphicsController);
166 Graphics::Sampler* CreateGraphicsObject();
168 Graphics::Controller* mGraphicsController;
169 Graphics::UniquePtr<Graphics::Sampler> mGraphicsSampler;
171 FilterMode mMinificationFilter : 4; ///< The minify filter
172 FilterMode mMagnificationFilter : 4; ///< The magnify filter
173 WrapMode mSWrapMode : 4; ///< The horizontal wrap mode
174 WrapMode mTWrapMode : 4; ///< The vertical wrap mode
175 WrapMode mRWrapMode : 4; ///< The vertical wrap mode
176 bool mIsDirty : 1; ///< If parameters have been set thru API
179 } // namespace Render
181 } // namespace Internal
185 #endif // DALI_INTERNAL_RENDER_SAMPLER_H