1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H
5 * Copyright (c) 2018 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.
24 #include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
25 #include <dali/public-api/rendering/sampler.h>
26 #include <dali/public-api/rendering/texture.h>
27 #include <dali/graphics-api/graphics-api-accessor.h>
28 #include <dali/graphics-api/graphics-api-texture.h>
29 #include <dali/integration-api/graphics/graphics.h>
30 #include <dali/internal/common/message.h>
31 #include <dali/internal/event/rendering/texture-impl.h>
32 #include <dali/internal/update/rendering/scene-graph-sampler.h>
42 * The SceneGraph::Texture object wraps the Graphics texture object, and is owned
43 * by the UpdateManager. It is used by SceneGraphRenderer to set up RenderCommands.
48 typedef Dali::TextureType::Type Type;
52 * @param[in] type The type of the texture
53 * @param[in] format The format of the pixel data
54 * @param[in] size The size of the texture
56 Texture( Type type, Pixel::Format format, ImageDimensions size );
59 * Constructor from native image
60 * @param[in] nativeImageInterface The native image
62 Texture( NativeImageInterfacePtr nativeImageInterface );
70 * Initialize the texture object with the Graphics API when added to UpdateManager
72 * @param[in] graphics The Graphics API
74 void Initialize( Integration::Graphics::Graphics& graphics );
77 * Retrieve wheter the texture has an alpha channel
78 * @return True if the texture has alpha channel, false otherwise
80 bool HasAlphaChannel();
83 * Get the type of the texture
84 * @return Type of the texture
92 * Check if the texture is a native image
93 * @return if the texture is a native image
95 bool IsNativeImage() const
101 * Get the Graphics object associated with this texture
102 * @return The graphics object.
104 const Graphics::API::Accessor<Graphics::API::Texture>& GetGfxObject() const;
107 * Get the texture id associated with the graphics texture
114 public: // From messages
116 * Uploads data to Graphics
117 * @param[in] pixelData The pixel data object
118 * @param[in] params The parameters for the upload
120 void UploadTexture( PixelDataPtr pixelData, const Internal::Texture::UploadParams& params );
125 void GenerateMipmaps();
129 Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
130 Graphics::API::Accessor<Graphics::API::Texture> mGraphicsTexture; ///< Graphics texture
132 NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
133 SceneGraph::Sampler mSampler; ///< The current sampler state
134 uint32_t mId; ///< The Graphics texture handle
135 uint16_t mWidth; ///< Width of the texture
136 uint16_t mHeight; ///< Height of the texture
137 uint16_t mMaxMipMapLevel; ///< Maximum mipmap level
138 Type mType:2; ///< Type of the texture
139 bool mHasAlpha : 1; ///< Whether the format has an alpha channel
140 bool mIsCompressed : 1; ///< Whether the format is compressed
144 inline void UploadTextureMessage( EventThreadServices& eventThreadServices, SceneGraph::Texture& texture, PixelDataPtr pixelData, const Internal::Texture::UploadParams& params )
146 typedef MessageValue2< SceneGraph::Texture, PixelDataPtr, Internal::Texture::UploadParams > LocalType;
148 // Reserve some memory inside the message queue
149 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
151 // Construct message in the message queue memory; note that delete should not be called on the return value
152 new (slot) LocalType( &texture, &SceneGraph::Texture::UploadTexture, pixelData, params );
155 inline void GenerateMipmapsMessage( EventThreadServices& eventThreadServices, SceneGraph::Texture& texture )
157 typedef Message< SceneGraph::Texture > LocalType;
159 // Reserve some memory inside the message queue
160 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
162 // Construct message in the message queue memory; note that delete should not be called on the return value
163 new (slot) LocalType( &texture, &SceneGraph::Texture::GenerateMipmaps );
166 } // namespace SceneGraph
168 } // namespace Internal
173 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H