2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiEffects_RendererGraphicsEngineRenderTextureCache.cpp
20 * @brief Implementation of class for render textures cache
24 #include <renderer/graphics-engine/FUiEffects_RendererGraphicsEngineOpenGLImplementation.h>
25 #include <renderer/graphics-engine/FUiEffects_RendererGraphicsEngineRenderTextureCache.h>
27 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace GraphicsEngine
30 RenderTextureCache::RenderTextureCache(Render *aRender):
36 RenderTextureCache::~RenderTextureCache()
41 RenderTextureCache::DropCache(void)
48 RenderTextureCache::DestroyCache(void)
52 glDeleteTextures(1, &_textureId);
59 RenderTextureCache::GetGlInternalFormat(Tizen::Ui::Effects::_Renderer::EngineModel::TextureProperty::InternalFormat::Value internalFormat)
61 switch (internalFormat)
63 case EngineModel::TextureProperty::InternalFormat::ONE_COMPONENT:
65 case EngineModel::TextureProperty::InternalFormat::TWO_COMPONENTS:
67 case EngineModel::TextureProperty::InternalFormat::THREE_COMPONENTS:
69 case EngineModel::TextureProperty::InternalFormat::FOUR_COMPONENTS:
71 case EngineModel::TextureProperty::InternalFormat::DEPTH_COMPONENT:
72 return GL_DEPTH_COMPONENT;
73 case EngineModel::TextureProperty::InternalFormat::DEPTH_COMPONENT_16:
74 return GL_DEPTH_COMPONENT16;
75 case EngineModel::TextureProperty::InternalFormat::DEPTH_COMPONENT_24:
76 ThrowJmp("GL_DEPTH_COMPONENT24 not allowed under GLES2");
78 case EngineModel::TextureProperty::InternalFormat::DEPTH_COMPONENT_32:
79 ThrowJmp("GL_DEPTH_COMPONENT32 not allowed under GLES2");
81 case EngineModel::TextureProperty::InternalFormat::RGB:
83 case EngineModel::TextureProperty::InternalFormat::RGBA:
85 case EngineModel::TextureProperty::InternalFormat::BGRA:
92 RenderTextureCache::GetGlDataFormat(Tizen::Ui::Effects::_Renderer::EngineModel::TextureProperty::DataFormat::Value dataFormat)
96 case EngineModel::TextureProperty::DataFormat::RGB:
98 case EngineModel::TextureProperty::DataFormat::BGR:
99 ThrowJmp("GL_BGR not allowed under GLES2");
101 case EngineModel::TextureProperty::DataFormat::RGBA:
103 case EngineModel::TextureProperty::DataFormat::BGRA:
105 case EngineModel::TextureProperty::DataFormat::LUMINANCE:
107 case EngineModel::TextureProperty::DataFormat::LUMINANCE_ALPHA:
108 return GL_LUMINANCE_ALPHA;
110 ThrowJmp("RenderTextureCache::getGLDataFormat: unknown data format");
114 RenderTextureCache::GetGlDataType(Tizen::Ui::Effects::_Renderer::EngineModel::TextureProperty::DataType::Value dataType)
118 case EngineModel::TextureProperty::DataType::UNSIGNED_BYTE:
119 return GL_UNSIGNED_BYTE;
120 case EngineModel::TextureProperty::DataType::BYTE:
122 case EngineModel::TextureProperty::DataType::UNSIGNED_SHORT:
123 return GL_UNSIGNED_SHORT;
124 case EngineModel::TextureProperty::DataType::SHORT:
126 case EngineModel::TextureProperty::DataType::UNSIGNED_INT:
127 return GL_UNSIGNED_INT;
128 case EngineModel::TextureProperty::DataType::INT:
130 case EngineModel::TextureProperty::DataType::FLOAT:
132 case EngineModel::TextureProperty::DataType::UNSIGNED_SHORT_565:
133 return GL_UNSIGNED_SHORT_5_6_5;
135 ThrowJmp("RenderTextureCache::getGLDataType: unknown data type");
139 RenderTextureCache::GetGlFilterType(Tizen::Ui::Effects::_Renderer::EngineModel::TextureProperty::FilterType::Value filterType)
143 case EngineModel::TextureProperty::FilterType::NEAREST:
145 case EngineModel::TextureProperty::FilterType::LINEAR:
147 case EngineModel::TextureProperty::FilterType::NEAREST_MIPMAP_NEAREST:
148 return GL_NEAREST_MIPMAP_NEAREST;
149 case EngineModel::TextureProperty::FilterType::LINEAR_MIPMAP_NEAREST:
150 return GL_LINEAR_MIPMAP_NEAREST;
151 case EngineModel::TextureProperty::FilterType::NEAREST_MIPMAP_LINEAR:
152 return GL_NEAREST_MIPMAP_LINEAR;
153 case EngineModel::TextureProperty::FilterType::LINEAR_MIPMAP_LINEAR:
154 return GL_LINEAR_MIPMAP_LINEAR;
156 ThrowJmp("RenderTextureCache::getGLFilterType: unknown filter type");
160 RenderTextureCache::GetGlWrapType(Tizen::Ui::Effects::_Renderer::EngineModel::TextureProperty::WrapType::Value wrapType)
164 case EngineModel::TextureProperty::WrapType::CLAMP:
165 ThrowJmp("GL_CLAMP not allowed under GLES2");
167 case EngineModel::TextureProperty::WrapType::CLAMP_TO_BORDER:
168 ThrowJmp("GL_CLAMP_TO_BORDER not allowed under GLES2");
170 case EngineModel::TextureProperty::WrapType::CLAMP_TO_EDGE:
171 return GL_CLAMP_TO_EDGE;
172 case EngineModel::TextureProperty::WrapType::MIRRORED_REPEAT:
173 return GL_MIRRORED_REPEAT;
174 case EngineModel::TextureProperty::WrapType::REPEAT:
177 ThrowJmp("RenderTextureCache::getGLWrapType: unknown wrap type");
181 RenderTexture2dCache::RenderTexture2dCache(Render* pRender, EngineModel::Texture2dProperty* pTexture):
182 RenderTextureCache(pRender),
187 RenderTexture2dCache::~RenderTexture2dCache(void)
192 RenderTexture2dCache::Die(void)
200 RenderTexture2dCache::DestroyCache(void)
204 __pTexture->SetCache(RenderTexture2DCachePtr());
208 RenderTextureCache::DestroyCache();
214 RenderTexture2dCache::Validate(Render* pRender)
216 Validate(pRender, 0);
221 RenderTexture2dCache::Validate(Render*, GLuint stage)
229 glGenTextures(1, &_textureId);
231 glActiveTexture(GL_TEXTURE0 + stage);
232 glBindTexture(GL_TEXTURE_2D, _textureId);
233 const size_t numMipMaps = __pTexture->GetNumMipmaps();
235 GLenum internalFormat = GetGlInternalFormat(__pTexture->GetInternalFormat());
236 GLenum dataFormat = GetGlDataFormat(__pTexture->GetDataFormat());
237 GLenum dataType = GetGlDataType(__pTexture->GetDataType());
239 for (size_t i = 0; numMipMaps > i; ++i)
241 glTexImage2D(GL_TEXTURE_2D, static_cast<GLint>(i), internalFormat,
242 static_cast<GLsizei>(__pTexture->GetWidth(i)),
243 static_cast<GLsizei>(__pTexture->GetHeight(i)),
244 0, dataFormat, dataType,
245 __pTexture->GetData(i));
248 if (__pTexture->GenerateMipmaps())
250 glGenerateMipmap(GL_TEXTURE_2D);
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GetGlFilterType(__pTexture->GetMinFilter()));
254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GetGlFilterType(__pTexture->GetMagFilter()));
256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrapType(__pTexture->GetWrapS()));
257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrapType(__pTexture->GetWrapT()));
264 RenderTexture2dCache::Bind(Render* pRender, GLuint stage)
268 Validate(pRender, stage);
272 glActiveTexture(GL_TEXTURE0 + stage);
273 glBindTexture(GL_TEXTURE_2D, _textureId);
278 }}}}} // Tizen::Ui::Effects::_Renderer::GraphicsEngine