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 void DestroyGraphicsObjects();
73 inline Graphics::SamplerAddressMode GetGraphicsSamplerAddressMode(WrapMode mode) const
77 case WrapMode::REPEAT:
78 return Graphics::SamplerAddressMode::REPEAT;
79 case WrapMode::MIRRORED_REPEAT:
80 return Graphics::SamplerAddressMode::MIRRORED_REPEAT;
81 case WrapMode::CLAMP_TO_EDGE:
82 return Graphics::SamplerAddressMode::CLAMP_TO_EDGE;
83 case WrapMode::DEFAULT:
84 return Graphics::SamplerAddressMode::CLAMP_TO_EDGE;
89 inline Graphics::SamplerMipmapMode GetGraphicsSamplerMipmapMode(FilterMode mode) const
93 case FilterMode::LINEAR_MIPMAP_LINEAR:
94 return Graphics::SamplerMipmapMode::LINEAR;
95 case FilterMode::NEAREST_MIPMAP_LINEAR:
96 return Graphics::SamplerMipmapMode::LINEAR;
97 case FilterMode::NEAREST_MIPMAP_NEAREST:
98 return Graphics::SamplerMipmapMode::NEAREST;
99 case FilterMode::LINEAR_MIPMAP_NEAREST:
100 return Graphics::SamplerMipmapMode::NEAREST;
102 return Graphics::SamplerMipmapMode::NONE;
107 inline Graphics::SamplerFilter GetGraphicsFilter(FilterMode mode) const
111 case FilterMode::LINEAR:
112 case FilterMode::LINEAR_MIPMAP_LINEAR:
113 case FilterMode::LINEAR_MIPMAP_NEAREST:
114 return Graphics::SamplerFilter::LINEAR;
115 case FilterMode::NEAREST:
116 case FilterMode::NEAREST_MIPMAP_LINEAR:
117 case FilterMode::NEAREST_MIPMAP_NEAREST:
118 return Graphics::SamplerFilter::NEAREST;
119 case FilterMode::DEFAULT:
120 return Graphics::SamplerFilter::LINEAR;
121 case FilterMode::NONE:
122 return Graphics::SamplerFilter::NEAREST;
130 * Sets the filter modes for an existing sampler
131 * @param[in] sampler The sampler
132 * @param[in] minFilterMode The filter to use under minification
133 * @param[in] magFilterMode The filter to use under magnification
135 inline void SetFilterMode(unsigned int minFilterMode, unsigned int magFilterMode)
137 mMinificationFilter = static_cast<Dali::FilterMode::Type>(minFilterMode);
138 mMagnificationFilter = static_cast<Dali::FilterMode::Type>(magFilterMode);
143 * Sets the wrap mode for an existing sampler
144 * @param[in] sampler The sampler
145 * @param[in] rWrapMode Wrapping mode in z direction
146 * @param[in] sWrapMode Wrapping mode in x direction
147 * @param[in] tWrapMode Wrapping mode in y direction
149 inline void SetWrapMode(unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode)
151 mRWrapMode = static_cast<Dali::WrapMode::Type>(rWrapMode);
152 mSWrapMode = static_cast<Dali::WrapMode::Type>(sWrapMode);
153 mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
158 * Check if the sampler has default values
160 inline bool IsDefaultSampler()
162 return (mMagnificationFilter == FilterMode::DEFAULT &&
163 mMinificationFilter == FilterMode::DEFAULT &&
164 mSWrapMode == WrapMode::DEFAULT &&
165 mTWrapMode == WrapMode::DEFAULT &&
166 mRWrapMode == WrapMode::DEFAULT);
169 void Initialize(Graphics::Controller& graphicsController);
171 Graphics::Sampler* CreateGraphicsObject();
173 Graphics::Controller* mGraphicsController;
174 Graphics::UniquePtr<Graphics::Sampler> mGraphicsSampler;
176 FilterMode mMinificationFilter : 4; ///< The minify filter
177 FilterMode mMagnificationFilter : 4; ///< The magnify filter
178 WrapMode mSWrapMode : 4; ///< The horizontal wrap mode
179 WrapMode mTWrapMode : 4; ///< The vertical wrap mode
180 WrapMode mRWrapMode : 4; ///< The vertical wrap mode
181 bool mIsDirty : 1; ///< If parameters have been set thru API
184 } // namespace Render
186 } // namespace Internal
190 #endif // DALI_INTERNAL_RENDER_SAMPLER_H