, __childrenCount(0)
, __backgroundColor(0.0f, 0.0f, 0.0f, 0.0f) // fully transparent rectangle object by default
, __objectColor(0.0f, 0.0f, 0.0f, 0.0f)
+ , __pVertices(null)
+ , __pIndices(null)
+ , __vertexCount(0)
+ , __indexCount(0)
, __pLayer(null)
, __activeLight()
, __pMesh(null)
memset(__extraSurfaceUpdated, true, sizeof(bool) * EXTRA_SURFACE_MAX);
__activeLight.Construct();
+
+ AllocateVertexBuffer(4, 6);
}
_GlNode::~_GlNode(void)
}
}
+ if (__pVertices)
+ {
+ delete [] __pVertices;
+ __pVertices = null;
+ }
+
+ if (__pIndices)
+ {
+ delete [] __pIndices;
+ __pIndices = null;
+ }
+
if (__pMesh)
{
delete __pMesh;
// Set texture info
// __pTextureInfo = reinterpret_cast<TextureInfo*>(pSurfaceImpl->GetNativeHandle());
-
- // test for atlas
-// bool useAtlas = false;
-// float atlasWidth, atlasHeight;
-
- // Calc texture coordinates
-#ifdef __USE_TEXTURE_ATLAS__
- if (!pTextureInfo->atlas)
- {
-#endif
- if (__useStencil)
- {
- if (element.__useContentBounds)
- {
- __pVertices[3] = element.__contentBounds.x;
- __pVertices[4] = element.__contentBounds.y;
-
- __pVertices[8] = element.__contentBounds.x + element.__contentBounds.width;
- __pVertices[9] = element.__contentBounds.y;
-
- __pVertices[13] = element.__contentBounds.x;
- __pVertices[14] = element.__contentBounds.y + element.__contentBounds.height;
-
- __pVertices[18] = element.__contentBounds.x + element.__contentBounds.width;
- __pVertices[19] = element.__contentBounds.y + element.__contentBounds.height;
- }
- else
- {
- __pVertices[3] = 0.0f;
- __pVertices[4] = 0.0f;
-
- __pVertices[8] = 1.0f;
- __pVertices[9] = 0.0f;
-
- __pVertices[13] = 0.0f;
- __pVertices[14] = 1.0f;
-
- __pVertices[18] = 1.0f;
- __pVertices[19] = 1.0f;
- }
- }
- else
- {
- if (element.__useContentBounds)
- {
- __pVertices[3] = element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width;
- __pVertices[4] = element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height;
-
- __pVertices[8] = element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width;
- __pVertices[9] = element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height;
-
- __pVertices[13] = element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width;
- __pVertices[14] = element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height;
-
- __pVertices[18] = element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width;
- __pVertices[19] = element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height;
- }
- else
- {
- __pVertices[3] = __visibleRect.Left() / __bounds.Width();
- __pVertices[4] = __visibleRect.Top() / __bounds.Height();
-
- __pVertices[8] = (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width();
- __pVertices[9] = __visibleRect.Top() / __bounds.Height();
-
- __pVertices[13] = __visibleRect.Left() / __bounds.Width();
- __pVertices[14] = (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height();
-
- __pVertices[18] = (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width();
- __pVertices[19] = (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height();
- }
- }
-#ifdef __USE_TEXTURE_ATLAS__
- }
- else
- {
-
- _TextureAtlas* pAtlas = reinterpret_cast<_TextureAtlas*>(pTextureInfo->atlas);
-
- float atlasWidth = pAtlas->GetTextureInfo().width;
- float atlasHeight = pAtlas->GetTextureInfo().height;
- // use texture atlas
- if (__useStencil)
- {
- if (element.__useContentBounds)
- {
- __pVertices[3] = (pTextureInfo->x + element.__contentBounds.x * pTextureInfo->width) / atlasWidth;
- __pVertices[4] = (pTextureInfo->y + element.__contentBounds.y * pTextureInfo->height) / atlasHeight;
-
- __pVertices[8] = (pTextureInfo->x + (element.__contentBounds.x + element.__contentBounds.width) * pTextureInfo->width) / atlasWidth;
- __pVertices[9] = (pTextureInfo->y + element.__contentBounds.y * pTextureInfo->height) / atlasHeight;
-
- __pVertices[13] = (pTextureInfo->x + element.__contentBounds.x * pTextureInfo->width) / atlasWidth;
- __pVertices[14] = (pTextureInfo->y + (element.__contentBounds.y + element.__contentBounds.height) * pTextureInfo->height) / atlasHeight;
-
- __pVertices[18] = (pTextureInfo->x + (element.__contentBounds.x + element.__contentBounds.width) * pTextureInfo->width) / atlasWidth;
- __pVertices[19] = (pTextureInfo->y + (element.__contentBounds.y + element.__contentBounds.height) * pTextureInfo->height) / atlasHeight;
- }
- else
- {
- __pVertices[3] = pTextureInfo->x / atlasWidth;
- __pVertices[4] = pTextureInfo->y / atlasHeight;
-
- __pVertices[8] = (pTextureInfo->x + pTextureInfo->width) / atlasWidth;
- __pVertices[9] = pTextureInfo->y / atlasHeight;
-
- __pVertices[13] = pTextureInfo->x / atlasWidth;
- __pVertices[14] = (pTextureInfo->y + pTextureInfo->height) / atlasHeight;
-
- __pVertices[18] = (pTextureInfo->x + pTextureInfo->width) / atlasWidth;
- __pVertices[19] = (pTextureInfo->y + pTextureInfo->height) / atlasHeight;
- }
- }
- else
- {
-
-
- if (element.__useContentBounds)
- {
- __pVertices[3] = ((element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[4] = ((element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[8] = ((element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[9] = ((element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[13] = ((element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[14] = ((element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[18] = ((element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[19] = ((element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
- }
- else
- {
- __pVertices[3] = (__visibleRect.Left() / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[4] = (__visibleRect.Top() / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[8] = ((__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[9] = (__visibleRect.Top() / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[13] = (__visibleRect.Left() / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[14] = ((__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
-
- __pVertices[18] = ((__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
- __pVertices[19] = ((__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
- }
- }
- }
-#endif
-
- if (__pVertices[3] < 0.0f || __pVertices[4] < 0.0f || __pVertices[18] > 1.0f || __pVertices[19] > 1.0f)
- {
- __textureRepeated = true;
- }
- else
- {
- __textureRepeated = false;
- }
}
}
else
__pFilter = null;
}
- if (element.__decomposedMatrixToTop.GetMatrixType() >= MATRIX4_Scale || __pMesh)
+ ShaderProgram* pShaderProgram = element.GetSharedData().geometry.GetShaderProgram();
+
+ if (unlikely(pShaderProgram))
{
- __useTransform = true;
+ if (!__pShaderProgram || !pShaderProgram->Equals(*__pShaderProgram))
+ {
+ if (__pShaderProgram)
+ {
+ delete __pShaderProgram;
+ __pShaderProgram = null;
+ }
+
+ __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
+ SysAssertf(__pShaderProgram, "failed to create shader program");
+ }
}
else
{
- __useTransform = false;
+ if (__pShaderProgram)
+ {
+ delete __pShaderProgram;
+ __pShaderProgram = null;
+ }
}
- // Set vertices
- if (__useStencil)
+ CalcVertexCoordinates(element);
+
+ if (__pMesh || __useTransform || __useStencil || __pFilter)
{
- if (__useTransform)
+ __findItemInQueue = false;
+ }
+ else
+ {
+ __findItemInQueue = true;
+ }
+
+ __syncNeeded = false;
+
+ return E_SUCCESS;
+}
+
+VisualElementSurface*
+_GlNode::GetSurface(void) const
+{
+ return __pSurface;
+}
+
+void
+_GlNode::CalcVertexCoordinates(_VisualElementImpl& element)
+{
+ float texX[4] = {0, };
+ float texY[4] = {0, };
+ float vertexX[4] = {0, };
+ float vertexY[4] = {0, };
+ int i = 0, index = 0, countX = 0, countY = 0;
+ int vertexCount, indexCount;
+
+ if (__pSurface)
+ {
+ _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*__pSurface);
+ TextureInfo* pTextureInfo = reinterpret_cast<TextureInfo*>(pSurfaceImpl->GetNativeHandle());
+
+#ifdef __USE_TEXTURE_ATLAS__
+ if (!pTextureInfo->atlas)
{
- __pVertices[0] = 0.0f;
- __pVertices[1] = 0.0f;
- __pVertices[2] = 0.0f;
+#endif
+ if (__useStencil)
+ {
+ if (pTextureInfo->useBorder)
+ {
+ // TODO: consider the case: __bounds.width < left border + right border
+ texX[0] = 0.0f;
+ texX[1] = (float)pTextureInfo->leftBorder / (float)pTextureInfo->width;
+ texX[2] = (float)(pTextureInfo->width - pTextureInfo->rightBorder) / (float)pTextureInfo->width;
+ texX[3] = 1.0f;
+
+ texY[0] = 0.0f;
+ texY[1] = (float)pTextureInfo->topBorder / (float)pTextureInfo->height;
+ texY[2] = (float)(pTextureInfo->height - pTextureInfo->bottomBorder) / (float)pTextureInfo->height;
+ texY[3] = 1.0f;
+
+ vertexX[0] = 0.0f;
+ vertexX[1] = pTextureInfo->leftBorder;
+ vertexX[2] = __bounds.Width() - pTextureInfo->rightBorder;
+ vertexX[3] = __bounds.Width();
+
+ vertexY[0] = 0.0f;
+ vertexY[1] = pTextureInfo->topBorder;
+ vertexY[2] = __bounds.Height() - pTextureInfo->bottomBorder;
+ vertexY[3] = __bounds.Height();
+
+ countX = countY = 4;
+
+ __textureRepeated = false;
+ }
+ else
+ {
+ if (element.__useContentBounds)
+ {
+ texX[0] = element.__contentBounds.x;
+ texX[1] = element.__contentBounds.x + element.__contentBounds.width;
+
+ texY[0] = element.__contentBounds.y;
+ texY[1] = element.__contentBounds.y + element.__contentBounds.height;
+
+ if (texX[0] < 0.0f || texY[0] < 0.0f || texX[1] > 1.0f || texY[1] > 1.0f)
+ {
+ __textureRepeated = true;
+ }
+ else
+ {
+ __textureRepeated = false;
+ }
+ }
+ else
+ {
+ texX[0] = 0.0f;
+ texX[1] = 1.0f;
- __pVertices[5] = __bounds.Width();
- __pVertices[6] = 0.0f;
- __pVertices[7] = 0.0f;
+ texY[0] = 0.0f;
+ texY[1] = 1.0f;
+
+ __textureRepeated = false;
+ }
- __pVertices[10] = 0.0f;
- __pVertices[11] = __bounds.Height();
- __pVertices[12] = 0.0f;
+ vertexX[0] = 0.0f;
+ vertexX[1] = __bounds.Width();
- __pVertices[15] = __bounds.Width();
- __pVertices[16] = __bounds.Height();
- __pVertices[17] = 0.0f;
+ vertexY[0] = 0.0f;
+ vertexY[1] = __bounds.Height();
+
+ countX = countY = 2;
+ }
+ }
+ else
+ {
+ float x1 = __visibleRect.Left() / __bounds.Width();
+ float y1 = __visibleRect.Top() / __bounds.Height();
+ float x2 = __visibleRect.Right() / __bounds.Width();
+ float y2 = __visibleRect.Bottom() / __bounds.Height();
+
+ if (pTextureInfo->useBorder)
+ {
+ // TODO: consider the case: __bounds.width < left border + right border
+ float borderX1 = (float)pTextureInfo->leftBorder / (float)pTextureInfo->width;
+ float borderY1 = (float)pTextureInfo->topBorder / (float)pTextureInfo->height;
+ float borderX2 = (float)(pTextureInfo->width - pTextureInfo->rightBorder) / (float)pTextureInfo->width;
+ float borderY2 = (float)(pTextureInfo->height - pTextureInfo->bottomBorder) / (float)pTextureInfo->height;
+
+ if (x1 < borderX1)
+ {
+ texX[countX] = x1;
+ vertexX[countX++] = __visibleRect.Left();
+
+ texX[countX] = borderX1;
+ vertexX[countX++] = __visibleRect.Left() + (borderX1 - x1) * pTextureInfo->width;
+ }
+ else
+ {
+ texX[countX] = x1;
+ vertexX[countX++] = __visibleRect.Left();
+ }
+
+ if (x2 > borderX2)
+ {
+ texX[countX] = borderX2;
+ vertexX[countX++] = __visibleRect.Right() - (x2 - borderX2) * pTextureInfo->width;
+
+ texX[countX] = x2;
+ vertexX[countX++] = __visibleRect.Right();
+ }
+ else
+ {
+ texX[countX] = x2;
+ vertexX[countX++] = __visibleRect.Right();
+ }
+
+ if (y1 < borderY1)
+ {
+ texY[countY] = y1;
+ vertexY[countY++] = __visibleRect.Top();
+
+ texY[countY] = borderY1;
+ vertexY[countY++] = __visibleRect.Top() + (borderY1 - y1) * pTextureInfo->height;
+ }
+ else
+ {
+ texY[countY] = y1;
+ vertexY[countY++] = __visibleRect.Top();
+ }
+
+ if (y2 > borderY2)
+ {
+ texY[countY] = borderY2;
+ vertexY[countY++] = __visibleRect.Bottom() - (y2 - borderY2) * pTextureInfo->height;
+
+ texY[countY] = y2;
+ vertexY[countY++] = __visibleRect.Bottom();
+ }
+ else
+ {
+ texY[countY] = y2;
+ vertexY[countY++] = __visibleRect.Bottom();
+ }
+
+ __textureRepeated = false;
+ }
+ else
+ {
+ if (element.__useContentBounds)
+ {
+ texX[0] = element.__contentBounds.x + x1 * element.__contentBounds.width;
+ texX[1] = element.__contentBounds.x + x2 * element.__contentBounds.width;
+
+ texY[0] = element.__contentBounds.y + y1 * element.__contentBounds.height;
+ texY[1] = element.__contentBounds.y + y2 * element.__contentBounds.height;
+
+ if (texX[0] < 0.0f || texY[0] < 0.0f || texX[1] > 1.0f || texY[1] > 1.0f)
+ {
+ __textureRepeated = true;
+ }
+ else
+ {
+ __textureRepeated = false;
+ }
+ }
+ else
+ {
+ texX[0] = x1;
+ texX[1] = x2;
+
+ texY[0] = y1;
+ texY[1] = y2;
+
+ __textureRepeated = false;
+ }
+
+ vertexX[0] = __visibleRect.Left();
+ vertexX[1] = __visibleRect.Right();
+
+ vertexY[0] = __visibleRect.Top();
+ vertexY[1] = __visibleRect.Bottom();
+
+ countX = countY = 2;
+ }
+ }
+#ifdef __USE_TEXTURE_ATLAS__
}
else
{
- __pVertices[0] = __transform.matrix[3][0];
- __pVertices[1] = __transform.matrix[3][1];
- __pVertices[2] = 0.0f;
+ _TextureAtlas* pAtlas = reinterpret_cast<_TextureAtlas*>(pTextureInfo->atlas);
+
+ float atlasWidth = pAtlas->GetTextureInfo().width;
+ float atlasHeight = pAtlas->GetTextureInfo().height;
+
+ // TODO: implement texture border code
- __pVertices[5] = __transform.matrix[3][0] + __bounds.Width();
- __pVertices[6] = __transform.matrix[3][1];
- __pVertices[7] = 0.0f;
+ // use texture atlas
+ if (__useStencil)
+ {
+ if (element.__useContentBounds)
+ {
+ __pVertices[3] = (pTextureInfo->x + element.__contentBounds.x * pTextureInfo->width) / atlasWidth;
+ __pVertices[4] = (pTextureInfo->y + element.__contentBounds.y * pTextureInfo->height) / atlasHeight;
- __pVertices[10] = __transform.matrix[3][0];
- __pVertices[11] = __transform.matrix[3][1] + __bounds.Height();
- __pVertices[12] = 0.0f;
+ __pVertices[8] = (pTextureInfo->x + (element.__contentBounds.x + element.__contentBounds.width) * pTextureInfo->width) / atlasWidth;
+ __pVertices[9] = (pTextureInfo->y + element.__contentBounds.y * pTextureInfo->height) / atlasHeight;
- __pVertices[15] = __transform.matrix[3][0] + __bounds.Width();
- __pVertices[16] = __transform.matrix[3][1] + __bounds.Height();
- __pVertices[17] = 0.0f;
+ __pVertices[13] = (pTextureInfo->x + element.__contentBounds.x * pTextureInfo->width) / atlasWidth;
+ __pVertices[14] = (pTextureInfo->y + (element.__contentBounds.y + element.__contentBounds.height) * pTextureInfo->height) / atlasHeight;
- __transform.matrix[3][0] = 0.0f;
- __transform.matrix[3][1] = 0.0f;
+ __pVertices[18] = (pTextureInfo->x + (element.__contentBounds.x + element.__contentBounds.width) * pTextureInfo->width) / atlasWidth;
+ __pVertices[19] = (pTextureInfo->y + (element.__contentBounds.y + element.__contentBounds.height) * pTextureInfo->height) / atlasHeight;
+
+ if (__pVertices[3] < 0.0f || __pVertices[4] < 0.0f || __pVertices[18] > 1.0f || __pVertices[19] > 1.0f)
+ {
+ __textureRepeated = true;
+ }
+ else
+ {
+ __textureRepeated = false;
+ }
+ }
+ else
+ {
+ __pVertices[3] = pTextureInfo->x / atlasWidth;
+ __pVertices[4] = pTextureInfo->y / atlasHeight;
+
+ __pVertices[8] = (pTextureInfo->x + pTextureInfo->width) / atlasWidth;
+ __pVertices[9] = pTextureInfo->y / atlasHeight;
+
+ __pVertices[13] = pTextureInfo->x / atlasWidth;
+ __pVertices[14] = (pTextureInfo->y + pTextureInfo->height) / atlasHeight;
+
+ __pVertices[18] = (pTextureInfo->x + pTextureInfo->width) / atlasWidth;
+ __pVertices[19] = (pTextureInfo->y + pTextureInfo->height) / atlasHeight;
+ }
+ }
+ else
+ {
+ if (element.__useContentBounds)
+ {
+ __pVertices[3] = ((element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[4] = ((element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[8] = ((element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[9] = ((element.__contentBounds.y + __visibleRect.Top() / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[13] = ((element.__contentBounds.x + __visibleRect.Left() / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[14] = ((element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[18] = ((element.__contentBounds.x + (__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * element.__contentBounds.width) * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[19] = ((element.__contentBounds.y + (__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * element.__contentBounds.height) * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ if (__pVertices[3] < 0.0f || __pVertices[4] < 0.0f || __pVertices[18] > 1.0f || __pVertices[19] > 1.0f)
+ {
+ __textureRepeated = true;
+ }
+ else
+ {
+ __textureRepeated = false;
+ }
+ }
+ else
+ {
+ __pVertices[3] = (__visibleRect.Left() / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[4] = (__visibleRect.Top() / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[8] = ((__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[9] = (__visibleRect.Top() / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[13] = (__visibleRect.Left() / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[14] = ((__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+
+ __pVertices[18] = ((__visibleRect.Left() + __visibleRect.Width()) / __bounds.Width() * pTextureInfo->width + pTextureInfo->x) / atlasWidth;
+ __pVertices[19] = ((__visibleRect.Top() + __visibleRect.Height()) / __bounds.Height() * pTextureInfo->height + pTextureInfo->y) / atlasHeight;
+ }
+ }
}
+#endif
}
else
{
- if (__useTransform)
+ if (__useStencil)
{
- __pVertices[0] = __visibleRect.Left();
- __pVertices[1] = __visibleRect.Top();
- __pVertices[2] = 0.0f;
-
- __pVertices[5] = __visibleRect.Left() + __visibleRect.Width();
- __pVertices[6] = __visibleRect.Top();
- __pVertices[7] = 0.0f;
-
- __pVertices[10] = __visibleRect.Left();
- __pVertices[11] = __visibleRect.Top() + __visibleRect.Height();
- __pVertices[12] = 0.0f;
+ vertexX[0] = 0.0f;
+ vertexX[1] = __bounds.Width();
- __pVertices[15] = __visibleRect.Left() + __visibleRect.Width();
- __pVertices[16] = __visibleRect.Top() + __visibleRect.Height();
- __pVertices[17] = 0.0f;
+ vertexY[0] = 0.0f;
+ vertexY[1] = __bounds.Height();
}
else
{
- __pVertices[0] = __transform.matrix[3][0] + __visibleRect.Left();
- __pVertices[1] = __transform.matrix[3][1] + __visibleRect.Top();
- __pVertices[2] = 0.0f;
+ vertexX[0] = __visibleRect.Left();
+ vertexX[1] = __visibleRect.Right();
- __pVertices[5] = __transform.matrix[3][0] + __visibleRect.Left() + __visibleRect.Width();
- __pVertices[6] = __transform.matrix[3][1] + __visibleRect.Top();
- __pVertices[7] = 0.0f;
+ vertexY[0] = __visibleRect.Top();
+ vertexY[1] = __visibleRect.Bottom();
+ }
- __pVertices[10] = __transform.matrix[3][0] + __visibleRect.Left();
- __pVertices[11] = __transform.matrix[3][1] + __visibleRect.Top() + __visibleRect.Height();
- __pVertices[12] = 0.0f;
+ countX = countY = 2;
+ }
- __pVertices[15] = __transform.matrix[3][0] + __visibleRect.Left() + __visibleRect.Width();
- __pVertices[16] = __transform.matrix[3][1] + __visibleRect.Top() + __visibleRect.Height();
- __pVertices[17] = 0.0f;
+ if (element.__decomposedMatrixToTop.GetMatrixType() >= MATRIX4_Scale || __pMesh)
+ {
+ __useTransform = true;
+ }
+ else
+ {
+ __useTransform = false;
- __transform.matrix[3][0] = 0.0f;
- __transform.matrix[3][1] = 0.0f;
+ for (i = 0; i < countX; i++)
+ {
+ vertexX[i] += __transform.matrix[3][0];
+ }
+
+ for (i = 0; i < countY; i++)
+ {
+ vertexY[i] += __transform.matrix[3][1];
}
+
+ __visibleRect.OffsetRect(__transform.matrix[3][0], __transform.matrix[3][1]);
+
+ __transform.matrix[3][0] = 0.0f;
+ __transform.matrix[3][1] = 0.0f;
}
- ShaderProgram* pShaderProgram = element.GetSharedData().geometry.GetShaderProgram();
+ vertexCount = countX * countY;
+ indexCount = (countX - 1) * (countY - 1) * 6;
- if (unlikely(pShaderProgram))
+ AllocateVertexBuffer(vertexCount, indexCount);
+
+ // set vertex buffer
+ for (int y = 0; y < countY; y++)
{
- if (!__pShaderProgram || !pShaderProgram->Equals(*__pShaderProgram))
+ for (int x = 0; x < countX; x++)
{
- if (__pShaderProgram)
- {
- delete __pShaderProgram;
- __pShaderProgram = null;
- }
-
- __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
- SysAssertf(__pShaderProgram, "failed to create shader program");
+ // x, y, z
+ __pVertices[index++] = vertexX[x];
+ __pVertices[index++] = vertexY[y];
+ __pVertices[index++] = 0.0f;
+
+ // s, t
+ __pVertices[index++] = texX[x];
+ __pVertices[index++] = texY[y];
}
}
- else
+
+ index = 0;
+
+ // set index buffer
+ for (int y = 0; y < countY - 1; y++)
{
- if (__pShaderProgram)
+ i = y * countX;
+
+ for (int x = 0; x < countX - 1; x++)
{
- delete __pShaderProgram;
- __pShaderProgram = null;
+ __pIndices[index++] = i;
+ __pIndices[index++] = i + 1;
+ __pIndices[index++] = i + countX;
+
+ __pIndices[index++] = i + 1;
+ __pIndices[index++] = i + countX;
+ __pIndices[index++] = i + countX + 1;
+
+ i++;
}
}
+}
- if (__pMesh || __useTransform || __useStencil || __pFilter)
- {
- __findItemInQueue = false;
- }
- else
+bool
+_GlNode::AllocateVertexBuffer(int vertexCount, int indexCount)
+{
+ if (__vertexCount != vertexCount)
{
- __findItemInQueue = true;
- }
+ if (__pVertices)
+ {
+ delete [] __pVertices;
+ __pVertices = null;
+ }
- __syncNeeded = false;
+ __pVertices = new (std::nothrow) float[vertexCount * 5];
+ SysTryReturnResult(NID_UI_ANIM, __pVertices, false, "[E_OUT_OF_MEMORY] Memory allocation failed.");
- return E_SUCCESS;
-}
+ if (__pIndices)
+ {
+ delete [] __pIndices;
+ __pIndices = null;
+ }
-VisualElementSurface*
-_GlNode::GetSurface(void) const
-{
- return __pSurface;
+ __pIndices = new (std::nothrow) unsigned short int[indexCount];
+ SysTryReturnResult(NID_UI_ANIM, __pIndices, false, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+ __vertexCount = vertexCount;
+ __indexCount = indexCount;
+ }
+
+ return true;
}
}}} // Tizen::Ui::Animations
#include "FUiAnimVisualElementFilter.h"
#include "FUiAnim_VisualElementFilterImpl.h"
-
#include "FUiAnim_GlLoader.h"
#include "FUiAnim_Debug.h"
#define CHECK_GL_CONTEXT() ASSERT(__pGlContext, "Invalid render manager status(no context)");
#endif
-#define VERTEX_BUFFER_STRIDE 3
-#define TEX_COORD_BUFFER_STRIDE 2
-
-#define VE_RENDER_OBJECT_VERTEX_COUNT_MAX 120
+#define VE_RENDER_OBJECT_VERTEX_COUNT_MAX 100
+#define VE_RENDER_OBJECT_INDEX_COUNT_MAX 150
#define VE_RENDER_QUEUE_COUNT_MAX 100
+
#define OFFSET (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1)
#define SURF_IMPL(__SURF) static_cast<_GlVisualElementSurfaceImpl*>(_VisualElementSurfaceImpl::GetInstance(__SURF))
, __pMaterial(null)
, __pFilter(null)
, __pVertexBuffer(null)
- , __pTexCoordBuffer(null)
+ , __pIndexBuffer(null)
, __geoType(0)
, __pVertices(null)
, __pTexCoords(null)
, __pNormals(null)
, __pIndices(null)
, __vertexCount(0)
+ , __indexCount(0)
+ , __vertexStride(0)
+ , __texCoordStride(0)
, __pProgram(null)
, __aPosition(-1)
, __aTexCoord(-1)
{
result r = E_SUCCESS;
- __pVertexBuffer = new (std::nothrow) float[VE_RENDER_OBJECT_VERTEX_COUNT_MAX * VERTEX_BUFFER_STRIDE];
+ __pVertexBuffer = new (std::nothrow) float[VE_RENDER_OBJECT_VERTEX_COUNT_MAX * 5];
SysTryCatch(NID_UI_ANIM, __pVertexBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
- __pTexCoordBuffer = new (std::nothrow) float[VE_RENDER_OBJECT_VERTEX_COUNT_MAX * TEX_COORD_BUFFER_STRIDE];
- SysTryCatch(NID_UI_ANIM, __pTexCoordBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+ __pIndexBuffer = new (std::nothrow) unsigned short int[VE_RENDER_OBJECT_INDEX_COUNT_MAX];
+ SysTryCatch(NID_UI_ANIM, __pIndexBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
return E_SUCCESS;
CATCH:
delete [] __pVertexBuffer;
- delete [] __pTexCoordBuffer;
+ delete [] __pIndexBuffer;
return r;
}
delete [] __pVertexBuffer;
__pVertexBuffer = null;
- delete [] __pTexCoordBuffer;
- __pTexCoordBuffer = null;
+ delete [] __pIndexBuffer;
+ __pIndexBuffer = null;
return E_SUCCESS;
}
void
_GlRenderQueue::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask)
{
- int vertexIndex = 0, textureIndex = 0;
int shaderType = 0;
static _GlCompositor* pCompositor = null;
__useDepthTest = false;
__pMesh = null;
- __bounds.SetRect(pNode->__pVertices[0], pNode->__pVertices[1],
- pNode->__pVertices[15] - pNode->__pVertices[0], pNode->__pVertices[16] - pNode->__pVertices[1]);
-
- __vertexCount = 6;
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[0];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[1];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[2];
+ __bounds = pNode->__visibleRect;
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[5];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[6];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[7];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[10];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[11];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[12];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[5];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[6];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[7];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[10];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[11];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[12];
+ __geoType = GL_TRIANGLES;
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[15];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[16];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[17];
+ memcpy(__pVertexBuffer, pNode->__pVertices, pNode->__vertexCount * 5 * sizeof(float));
+ memcpy(__pIndexBuffer, pNode->__pIndices, pNode->__indexCount * sizeof(unsigned short int));
- __geoType = GL_TRIANGLES;
+ __vertexStride = 5 * sizeof(float);
+ __vertexCount = pNode->__vertexCount;
+ __indexCount = pNode->__indexCount;
__pVertices = __pVertexBuffer;
+ __pIndices = __pIndexBuffer;
if (pNode->__pSurface)
{
__isTexUpdated = false;
}
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[3];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[4];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[8];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[9];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[13];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[14];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[8];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[9];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[13];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[14];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[18];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[19];
-
- __pTexCoords = __pTexCoordBuffer;
+ __pTexCoords = &(__pVertexBuffer[3]);
+ __texCoordStride = 5 * sizeof(float);
if (_FloatCompare(pNode->__opacity, 1.0f))
{
return;
}
- __pVertices = pMeshImpl->__pVertices;
-
__vertexCount = pMeshImpl->__countOfVertex;
+ __pVertices = pMeshImpl->__pVertices;
+ __vertexStride = 3 * sizeof(float);
+
if (pNode->__pSurface && pMeshImpl->IsTextureCoordinateEnabled())
{
__pSurfaceInfo = SURF_IMPL(*pNode->__pSurface);
}
__pTexCoords = pMeshImpl->__pTexCoordinates;
+ __texCoordStride = 2 * sizeof(float);
if (_FloatCompare(pNode->__opacity, 1.0f))
{
{
__pProgram = GetShaderProgram(shaderType);
}
- if(__pProgram)
+
+ if (__pProgram)
{
__pProgram = new ShaderProgram(*__pProgram);
void
_GlRenderQueue::_RenderObject::AddVertices(_GlNode* pNode)
{
- int vertexIndex, textureIndex;
-
- vertexIndex = __vertexCount * VERTEX_BUFFER_STRIDE;
- textureIndex = __vertexCount * TEX_COORD_BUFFER_STRIDE;
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[0];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[1];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[2];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[5];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[6];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[7];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[10];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[11];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[12];
-
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[5];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[6];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[7];
+ float* pVertexBuffer = __pVertexBuffer + __vertexCount * 5;
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[10];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[11];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[12];
+ memcpy(pVertexBuffer, pNode->__pVertices, pNode->__vertexCount * 5 * sizeof(float));
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[15];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[16];
- __pVertexBuffer[vertexIndex++] = pNode->__pVertices[17];
-
- if (pNode->__pSurface)
+ for (int i = 0; i < pNode->__indexCount; i++)
{
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[3];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[4];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[8];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[9];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[13];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[14];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[8];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[9];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[13];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[14];
-
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[18];
- __pTexCoordBuffer[textureIndex++] = pNode->__pVertices[19];
+ __pIndexBuffer[__indexCount + i] = pNode->__pIndices[i] + __vertexCount;
}
- __vertexCount += 6;
-
- _Rectanglef bounds = _Rectanglef(pNode->__pVertices[0], pNode->__pVertices[1],
- pNode->__pVertices[15] - pNode->__pVertices[0], pNode->__pVertices[16] - pNode->__pVertices[1]);
+ __vertexCount += pNode->__vertexCount;
+ __indexCount += pNode->__indexCount;
- __bounds.Union(bounds);
+ __bounds.Union(pNode->__visibleRect);
return;
}
// && __pRenderQueue[index].__pMaterial == pNode->__pMaterial // TODO: check light
)
{
- if (unlikely(__pRenderQueue[index].__vertexCount >= VE_RENDER_OBJECT_VERTEX_COUNT_MAX - 6))
+ if (unlikely(__pRenderQueue[index].__vertexCount >= VE_RENDER_OBJECT_VERTEX_COUNT_MAX - pNode->__vertexCount
+ || __pRenderQueue[index].__indexCount >= VE_RENDER_OBJECT_INDEX_COUNT_MAX - pNode->__indexCount))
{
PRINT("_GlRenderManager::FindRenderObject: Vertex buffer is full. Use next slot.\n");
return -1;
return index;
}
- if (__pRenderQueue[index].__bounds.IsIntersected(bounds))
+ if (__pRenderQueue[index].__bounds.IsIntersected(pNode->__visibleRect))
{
return -1;
}
// __pTempNode->__pVertices[18] = 1.0f;
// __pTempNode->__pVertices[19] = 1.0f;
+ // index buffer
+// __pTempNode->__pIndices[0] = 0;
+// __pTempNode->__pIndices[1] = 1;
+// __pTempNode->__pIndices[2] = 2;
+// __pTempNode->__pIndices[3] = 1;
+// __pTempNode->__pIndices[4] = 2;
+// __pTempNode->__pIndices[5] = 3;
+
// __pTempNode->__transform.SetAsIdentity();
// __pTempNode->__useTransform = false;
// __pTempNode->__textureRepeated = false;
pGlContext->UseShaderProgram(pProgramImpl);
// Set attribute
- glVertexAttribPointer(pRenderObjects[i].__aPosition, 3, GL_FLOAT, GL_FALSE, VERTEX_BUFFER_STRIDE * sizeof(float), pRenderObjects[i].__pVertices);
- glVertexAttribPointer(pRenderObjects[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, TEX_COORD_BUFFER_STRIDE * sizeof(float), pRenderObjects[i].__pTexCoords);
+ glVertexAttribPointer(pRenderObjects[i].__aPosition, 3, GL_FLOAT, GL_FALSE, pRenderObjects[i].__vertexStride, pRenderObjects[i].__pVertices);
+ glVertexAttribPointer(pRenderObjects[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, pRenderObjects[i].__texCoordStride, pRenderObjects[i].__pTexCoords);
glVertexAttribPointer(pRenderObjects[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderObjects[i].__pColors);
glVertexAttribPointer(pRenderObjects[i].__aNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), pRenderObjects[i].__pNormals);