void UIBatch::AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight) { unsigned topLeftColor, topRightColor, bottomLeftColor, bottomRightColor; if (!useGradient_) { // If alpha is 0, nothing will be rendered, so do not add the quad if (!(color_ & 0xff000000)) return; topLeftColor = color_; topRightColor = color_; bottomLeftColor = color_; bottomRightColor = color_; } else { topLeftColor = GetInterpolatedColor(x, y); topRightColor = GetInterpolatedColor(x + width, y); bottomLeftColor = GetInterpolatedColor(x, y + height); bottomRightColor = GetInterpolatedColor(x + width, y + height); } const IntVector2& screenPos = element_->GetScreenPosition(); float left = (float)(x + screenPos.x_) - posAdjust; float right = left + (float)width; float top = (float)(y + screenPos.y_) - posAdjust; float bottom = top + (float)height; float leftUV = texOffsetX * invTextureSize_.x_; float topUV = texOffsetY * invTextureSize_.y_; float rightUV = (texOffsetX + (texWidth ? texWidth : width)) * invTextureSize_.x_; float bottomUV = (texOffsetY + (texHeight ? texHeight : height)) * invTextureSize_.y_; unsigned begin = vertexData_->Size(); vertexData_->Resize(begin + 6 * UI_VERTEX_SIZE); float* dest = &(vertexData_->At(begin)); vertexEnd_ = vertexData_->Size(); *dest++ = left; *dest++ = top; *dest++ = 0.0f; *((unsigned*)dest) = topLeftColor; dest++; *dest++ = leftUV; *dest++ = topUV; *dest++ = right; *dest++ = top; *dest++ = 0.0f; *((unsigned*)dest) = topRightColor; dest++; *dest++ = rightUV; *dest++ = topUV; *dest++ = left; *dest++ = bottom; *dest++ = 0.0f; *((unsigned*)dest) = bottomLeftColor; dest++; *dest++ = leftUV; *dest++ = bottomUV; *dest++ = right; *dest++ = top; *dest++ = 0.0f; *((unsigned*)dest) = topRightColor; dest++; *dest++ = rightUV; *dest++ = topUV; *dest++ = right; *dest++ = bottom; *dest++ = 0.0f; *((unsigned*)dest) = bottomRightColor; dest++; *dest++ = rightUV; *dest++ = bottomUV; *dest++ = left; *dest++ = bottom; *dest++ = 0.0f; *((unsigned*)dest) = bottomLeftColor; dest++; *dest++ = leftUV; *dest++ = bottomUV; }
void UIBatch::AddQuad(float x, float y, float width, float height, int texOffsetX, int texOffsetY, int texWidth, int texHeight) { unsigned topLeftColor, topRightColor, bottomLeftColor, bottomRightColor; if (!useGradient_) { // If alpha is 0, nothing will be rendered, so do not add the quad if (!(color_ & 0xff000000)) return; topLeftColor = color_; topRightColor = color_; bottomLeftColor = color_; bottomRightColor = color_; } else { topLeftColor = GetInterpolatedColor(x, y); topRightColor = GetInterpolatedColor(x + width, y); bottomLeftColor = GetInterpolatedColor(x, y + height); bottomRightColor = GetInterpolatedColor(x + width, y + height); } const IntVector2& screenPos = element_->GetScreenPosition(); float left = x + screenPos.x_ - posAdjust.x_; float right = left + width; float top = y + screenPos.y_ - posAdjust.x_; float bottom = top + height; float leftUV = texOffsetX * invTextureSize_.x_; float topUV = texOffsetY * invTextureSize_.y_; float rightUV = (texOffsetX + (texWidth ? texWidth : width)) * invTextureSize_.x_; float bottomUV = (texOffsetY + (texHeight ? texHeight : height)) * invTextureSize_.y_; unsigned begin = vertexData_->Size(); vertexData_->Resize(begin + 6 * UI_VERTEX_SIZE); float* dest = &(vertexData_->At(begin)); vertexEnd_ = vertexData_->Size(); dest[0] = left; dest[1] = top; dest[2] = 0.0f; ((unsigned&)dest[3]) = topLeftColor; dest[4] = leftUV; dest[5] = topUV; dest[6] = right; dest[7] = top; dest[8] = 0.0f; ((unsigned&)dest[9]) = topRightColor; dest[10] = rightUV; dest[11] = topUV; dest[12] = left; dest[13] = bottom; dest[14] = 0.0f; ((unsigned&)dest[15]) = bottomLeftColor; dest[16] = leftUV; dest[17] = bottomUV; dest[18] = right; dest[19] = top; dest[20] = 0.0f; ((unsigned&)dest[21]) = topRightColor; dest[22] = rightUV; dest[23] = topUV; dest[24] = right; dest[25] = bottom; dest[26] = 0.0f; ((unsigned&)dest[27]) = bottomRightColor; dest[28] = rightUV; dest[29] = bottomUV; dest[30] = left; dest[31] = bottom; dest[32] = 0.0f; ((unsigned&)dest[33]) = bottomLeftColor; dest[34] = leftUV; dest[35] = bottomUV; }
void UIBatch::AddQuad(const Matrix3x4& transform, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight) { unsigned topLeftColor, topRightColor, bottomLeftColor, bottomRightColor; if (!useGradient_) { // If alpha is 0, nothing will be rendered, so do not add the quad if (!(color_ & 0xff000000)) return; topLeftColor = color_; topRightColor = color_; bottomLeftColor = color_; bottomRightColor = color_; } else { topLeftColor = GetInterpolatedColor(x, y); topRightColor = GetInterpolatedColor(x + width, y); bottomLeftColor = GetInterpolatedColor(x, y + height); bottomRightColor = GetInterpolatedColor(x + width, y + height); } Vector3 v1 = (transform * Vector3((float)x, (float)y, 0.0f)) - posAdjustVec; Vector3 v2 = (transform * Vector3((float)x + (float)width, (float)y, 0.0f)) - posAdjustVec; Vector3 v3 = (transform * Vector3((float)x, (float)y + (float)height, 0.0f)) - posAdjustVec; Vector3 v4 = (transform * Vector3((float)x + (float)width, (float)y + (float)height, 0.0f)) - posAdjustVec; float leftUV = ((float)texOffsetX) * invTextureSize_.x_; float topUV = ((float)texOffsetY) * invTextureSize_.y_; float rightUV = ((float)(texOffsetX + (texWidth ? texWidth : width))) * invTextureSize_.x_; float bottomUV = ((float)(texOffsetY + (texHeight ? texHeight : height))) * invTextureSize_.y_; unsigned begin = vertexData_->Size(); vertexData_->Resize(begin + 6 * UI_VERTEX_SIZE); float* dest = &(vertexData_->At(begin)); vertexEnd_ = vertexData_->Size(); *dest++ = v1.x_; *dest++ = v1.y_; *dest++ = 0.0f; *((unsigned*)dest) = topLeftColor; dest++; *dest++ = leftUV; *dest++ = topUV; *dest++ = v2.x_; *dest++ = v2.y_; *dest++ = 0.0f; *((unsigned*)dest) = topRightColor; dest++; *dest++ = rightUV; *dest++ = topUV; *dest++ = v3.x_; *dest++ = v3.y_; *dest++ = 0.0f; *((unsigned*)dest) = bottomLeftColor; dest++; *dest++ = leftUV; *dest++ = bottomUV; *dest++ = v2.x_; *dest++ = v2.y_; *dest++ = 0.0f; *((unsigned*)dest) = topRightColor; dest++; *dest++ = rightUV; *dest++ = topUV; *dest++ = v4.x_; *dest++ = v4.y_; *dest++ = 0.0f; *((unsigned*)dest) = bottomRightColor; dest++; *dest++ = rightUV; *dest++ = bottomUV; *dest++ = v3.x_; *dest++ = v3.y_; *dest++ = 0.0f; *((unsigned*)dest) = bottomLeftColor; dest++; *dest++ = leftUV; *dest++ = bottomUV; }
void UIBatch::AddQuad(const Matrix3x4& transform, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight) { unsigned topLeftColor, topRightColor, bottomLeftColor, bottomRightColor; if (!useGradient_) { // If alpha is 0, nothing will be rendered, so do not add the quad if (!(color_ & 0xff000000)) return; topLeftColor = color_; topRightColor = color_; bottomLeftColor = color_; bottomRightColor = color_; } else { topLeftColor = GetInterpolatedColor(x, y); topRightColor = GetInterpolatedColor(x + width, y); bottomLeftColor = GetInterpolatedColor(x, y + height); bottomRightColor = GetInterpolatedColor(x + width, y + height); } Vector3 v1 = (transform * Vector3((float)x, (float)y, 0.0f)) - posAdjust; Vector3 v2 = (transform * Vector3((float)x + (float)width, (float)y, 0.0f)) - posAdjust; Vector3 v3 = (transform * Vector3((float)x, (float)y + (float)height, 0.0f)) - posAdjust; Vector3 v4 = (transform * Vector3((float)x + (float)width, (float)y + (float)height, 0.0f)) - posAdjust; float leftUV = ((float)texOffsetX) * invTextureSize_.x_; float topUV = ((float)texOffsetY) * invTextureSize_.y_; float rightUV = ((float)(texOffsetX + (texWidth ? texWidth : width))) * invTextureSize_.x_; float bottomUV = ((float)(texOffsetY + (texHeight ? texHeight : height))) * invTextureSize_.y_; unsigned begin = vertexData_->Size(); vertexData_->Resize(begin + 6 * UI_VERTEX_SIZE); float* dest = &(vertexData_->At(begin)); vertexEnd_ = vertexData_->Size(); dest[0] = v1.x_; dest[1] = v1.y_; dest[2] = 0.0f; ((unsigned&)dest[3]) = topLeftColor; dest[4] = leftUV; dest[5] = topUV; dest[6] = v2.x_; dest[7] = v2.y_; dest[8] = 0.0f; ((unsigned&)dest[9]) = topRightColor; dest[10] = rightUV; dest[11] = topUV; dest[12] = v3.x_; dest[13] = v3.y_; dest[14] = 0.0f; ((unsigned&)dest[15]) = bottomLeftColor; dest[16] = leftUV; dest[17] = bottomUV; dest[18] = v2.x_; dest[19] = v2.y_; dest[20] = 0.0f; ((unsigned&)dest[21]) = topRightColor; dest[22] = rightUV; dest[23] = topUV; dest[24] = v4.x_; dest[25] = v4.y_; dest[26] = 0.0f; ((unsigned&)dest[27]) = bottomRightColor; dest[28] = rightUV; dest[29] = bottomUV; dest[30] = v3.x_; dest[31] = v3.y_; dest[32] = 0.0f; ((unsigned&)dest[33]) = bottomLeftColor; dest[34] = leftUV; dest[35] = bottomUV; }