1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__
5 * Copyright (c) 2014 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.
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/internal/common/owner-pointer.h>
24 #include <dali/internal/update/resources/resource-manager-declarations.h>
25 #include <dali/internal/render/gl-resources/context.h>
26 #include <dali/internal/render/gl-resources/texture-observer.h>
27 #include <dali/internal/render/renderers/scene-graph-renderer.h>
38 class NodeDataProvider;
41 * Used to render an image.
43 class ImageRenderer : public Renderer, public TextureObserver
47 typedef Dali::ImageActor::PixelArea PixelArea;
56 GRID_NINE_PATCH_NO_CENTER ///< Not supported yet.
60 * Create a new ImageRenderer.
61 * @param dataprovider to render
62 * @return The newly allocated ImageRenderer.
64 static ImageRenderer* New( NodeDataProvider& dataprovider );
69 virtual ~ImageRenderer();
72 * Set the texture used to render.
73 * @param[in] textureId The id of the texture used to render.
75 void SetTextureId( ResourceId textureId );
78 * Set the pixel area for the renderer
79 * @param[in] pixelArea An area within the texture, used when building UV coordinates.
81 void SetPixelArea( const ImageRenderer::PixelArea& pixelArea );
84 * Set 9 patch border for the image renderer
85 * @param[in] border The border for nine-patch meshes.
86 * @param[in] borderInPixels True if border is in pixels instead of percentages.
88 void SetNinePatchBorder( const Vector4& border, bool inPixels );
91 * Set whether the ImageRenderer should use blending
92 * @param[in] useBlend True if blending should be used.
94 void SetUseBlend( bool useBlend );
97 * Set the blending options.
98 * @param[in] options A bitmask of blending options.
100 void SetBlendingOptions( unsigned int options );
103 * Set the blend color.
104 * @param[in] color The new blend-color.
106 void SetBlendColor( const Vector4& color );
109 * Calculate the mesh data used by the ImageRenderer.
110 * @param[in] type The type of mesh data required; either quad, nine-patch or grid.
111 * @param[in] targetSize The size which the mesh data should fit inside.
112 * @param[in] usePixelArea whether to use pixel area or not
114 void CalculateMeshData( MeshType type, const Vector2& targetSize, bool usePixelArea );
117 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
119 virtual void GlContextDestroyed();
122 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
124 virtual void GlCleanup();
127 * @copydoc Dali::Internal::SceneGraph::Renderer::RequiresDepthTest()
129 virtual bool RequiresDepthTest() const;
132 * @copydoc Dali::Internal::SceneGraph::Renderer::CheckResources()
134 virtual bool CheckResources();
137 * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
139 virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
142 * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
144 virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
147 * @copydoc Dali::Internal::SceneGraph::Renderer::DoSetBlending()
149 virtual void DoSetBlending( Context& context, BufferIndex bufferIndex );
151 protected: // TextureObserver implementation
154 * @copydoc Dali::Internal::TextureObserver::TextureDiscarded()
156 virtual void TextureDiscarded( ResourceId textureId );
160 * Helper to update the vertex buffer.
162 void UpdateVertexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
165 * Helper to update the index buffer.
167 void UpdateIndexBuffer( Context& context, GLsizeiptr size, const GLvoid *data );
170 * Helper to generate mesh data when required
171 * @param[in] texture Texture from which to get UV data
173 void GenerateMeshData( Texture* texture );
176 * Helper to fill vertex/index buffers with quad data.
177 * (Quads are simple meshes, and thus have a specialised mesh generation method)
179 * @param[in] texture Texture from which to get UV data
181 * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
183 void SetQuadMeshData( Texture* texture, const Vector2& size, const PixelArea* pixelArea );
186 * Helper to fill vertex/index buffers with nine-patch data.
187 * (9-Patches are simple meshes, and thus have a specialised mesh generation method)
189 * @param[in] texture Texture from which to get UV data
190 * @param[in] size The target size.
191 * @param[in] border 9 patch border information.
192 * @param[in] borderInPixels True if border is in pixels instead of percentages.
193 * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
194 * @param[in] noCenter True if the center section of nine patch should not be rendered.
196 void SetNinePatchMeshData( Texture* texture, const Vector2& size, const Vector4& border, bool borderInPixels, const PixelArea* pixelArea, bool noCenter );
199 * Helper to fill vertex/index buffers with grid data.
200 * This can build grid meshes that are either of type Quad or type 9-Patch
202 * @param[in] size The target size.
203 * @param[in] border 9 patch border information (pass NULL for no border i.e. a standard Quad)
204 * @param[in] borderInPixels True if border is in pixels instead of percentages.
205 * @param[in] pixelArea An area within the texture, used when building UV coordinates. A value of NULL means use default image size.
207 void SetGridMeshData( Texture* texture, const Vector2& size, const Vector4* border, bool borderInPixels, const PixelArea* pixelArea );
210 * Helper to fill index buffer with uniform grid data.
211 * @param[in] indices pointer to indices buffer to be filled
212 * @param[in] rectanglesX number of columns for rectangles in grid
213 * @param[in] rectanglesY number of rows for rectangles in grid
215 void GenerateMeshIndices(GLushort* indices, int rectanglesX, int rectanglesY);
218 * Private constructor. @see New()
220 ImageRenderer( NodeDataProvider& dataprovider );
223 ImageRenderer( const ImageRenderer& );
226 ImageRenderer& operator=( const ImageRenderer& rhs );
232 OwnerPointer< GpuBuffer > mVertexBuffer;
233 OwnerPointer< GpuBuffer > mIndexBuffer;
236 PixelArea mPixelArea;
237 Vector2 mGeometrySize;
238 ResourceId mTextureId;
240 BlendingOptions mBlendingOptions;
243 MeshType mMeshType : 3; // 4 values fits in 3 bits just fine
244 bool mIsMeshGenerated : 1;
245 bool mBorderInPixels : 1;
246 bool mUseBlend : 1; ///< True if blending should be enabled, 1 bit is enough
247 bool mUsePixelArea : 1;
251 } // namespace SceneGraph
253 } // namespace Internal
257 #endif // __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__