Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 1 file). Show all
Unified · Split
| @@ -1026,12 +1026,12 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int · 1025 unmodified lines | ||
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | const int FLOATS_PER_VERTEX = 2; // vertices |
| 1029 | − const int vertices = 8; | |
| 1029 | + const int NUM_VERTICES = 12; | |
| 1030 | 1030 | |
| 1031 | 1031 | if (!details.isCreated) { |
| 1032 | 1032 | |
| 1033 | 1033 | details.isCreated = true; |
| 1034 | − details.vertices = vertices; | |
| 1034 | + details.vertices = NUM_VERTICES; | |
| 1035 | 1035 | details.vertexSize = FLOATS_PER_VERTEX; |
| 1036 | 1036 | |
| 1037 | 1037 | gpu::BufferPointer verticesBuffer(new gpu::Buffer()); |
| @@ -1044,62 +1044,72 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int · 6 unmodified lines | ||
| 1044 | 1044 | details.streamFormat = streamFormat; |
| 1045 | 1045 | details.stream = stream; |
| 1046 | 1046 | |
| 1047 | − details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); | |
| 1047 | + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ)); | |
| 1048 | 1048 | details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); |
| 1049 | 1049 | |
| 1050 | 1050 | details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); |
| 1051 | 1051 | details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); |
| 1052 | 1052 | |
| 1053 | 1053 | |
| 1054 | − int vertexPoints = vertices * FLOATS_PER_VERTEX; | |
| 1055 | − GLfloat* vertexBuffer = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad | |
| 1056 | − GLfloat* vertex = vertexBuffer; | |
| 1054 | + int vertexPoints = NUM_VERTICES * FLOATS_PER_VERTEX; | |
| 1055 | + GLfloat vertexBuffer[vertexPoints]; // only vertices, no normals because we're a 2D quad | |
| 1057 | 1056 | int vertexPoint = 0; |
| 1058 | 1057 | |
| 1059 | − // left side | |
| 1060 | − vertex[vertexPoint++] = x; | |
| 1061 | − vertex[vertexPoint++] = y + bevelDistance; | |
| 1058 | + // left side quad | |
| 1059 | + vertexBuffer[vertexPoint++] = x; | |
| 1060 | + vertexBuffer[vertexPoint++] = y + bevelDistance; | |
| 1061 | + | |
| 1062 | + vertexBuffer[vertexPoint++] = x + bevelDistance; | |
| 1063 | + vertexBuffer[vertexPoint++] = y; | |
| 1064 | + | |
| 1065 | + vertexBuffer[vertexPoint++] = x + bevelDistance; | |
| 1066 | + vertexBuffer[vertexPoint++] = y + height; | |
| 1067 | + | |
| 1068 | + vertexBuffer[vertexPoint++] = x; | |
| 1069 | + vertexBuffer[vertexPoint++] = y + height - bevelDistance; | |
| 1070 | + | |
| 1071 | + // middle quad | |
| 1072 | + vertexBuffer[vertexPoint++] = x + bevelDistance; | |
| 1073 | + vertexBuffer[vertexPoint++] = y; | |
| 1062 | 1074 | |
| 1063 | − vertex[vertexPoint++] = x; | |
| 1064 | − vertex[vertexPoint++] = y + height - bevelDistance; | |
| 1075 | + vertexBuffer[vertexPoint++] = x + width - bevelDistance; | |
| 1076 | + vertexBuffer[vertexPoint++] = y; | |
| 1077 | + | |
| 1078 | + vertexBuffer[vertexPoint++] = x + width - bevelDistance; | |
| 1079 | + vertexBuffer[vertexPoint++] = y + height; | |
| 1080 | + | |
| 1081 | + vertexBuffer[vertexPoint++] = x + bevelDistance; | |
| 1082 | + vertexBuffer[vertexPoint++] = y + height; | |
| 1065 | 1083 | |
| 1066 | − // top side | |
| 1067 | − vertex[vertexPoint++] = x + bevelDistance; | |
| 1068 | − vertex[vertexPoint++] = y + height; | |
| 1084 | + // right side quad | |
| 1085 | + vertexBuffer[vertexPoint++] = x + width - bevelDistance; | |
| 1086 | + vertexBuffer[vertexPoint++] = y; | |
| 1087 | + | |
| 1088 | + vertexBuffer[vertexPoint++] = x + width; | |
| 1089 | + vertexBuffer[vertexPoint++] = y + bevelDistance; | |
| 1090 | + | |
| 1091 | + vertexBuffer[vertexPoint++] = x + width; | |
| 1092 | + vertexBuffer[vertexPoint++] = y + height - bevelDistance; | |
| 1093 | + | |
| 1094 | + vertexBuffer[vertexPoint++] = x + width - bevelDistance; | |
| 1095 | + vertexBuffer[vertexPoint++] = y + height; | |
| 1069 | 1096 | |
| 1070 | − vertex[vertexPoint++] = x + width - bevelDistance; | |
| 1071 | − vertex[vertexPoint++] = y + height; | |
| 1072 | − | |
| 1073 | − // right | |
| 1074 | − vertex[vertexPoint++] = x + width; | |
| 1075 | − vertex[vertexPoint++] = y + height - bevelDistance; | |
| 1076 | − vertex[vertexPoint++] = x + width; | |
| 1077 | − vertex[vertexPoint++] = y + bevelDistance; | |
| 1078 | − | |
| 1079 | − // bottom | |
| 1080 | − vertex[vertexPoint++] = x + width - bevelDistance; | |
| 1081 | − vertex[vertexPoint++] = y; | |
| 1082 | − vertex[vertexPoint++] = x +bevelDistance; | |
| 1083 | − vertex[vertexPoint++] = y; | |
| 1084 | − | |
| 1085 | − const int NUM_COLOR_SCALARS_PER_QUAD = 8; | |
| 1086 | 1097 | int compactColor = ((int(color.x * 255.0f) & 0xFF)) | |
| 1087 | 1098 | ((int(color.y * 255.0f) & 0xFF) << 8) | |
| 1088 | 1099 | ((int(color.z * 255.0f) & 0xFF) << 16) | |
| 1089 | 1100 | ((int(color.w * 255.0f) & 0xFF) << 24); |
| 1090 | − int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor, | |
| 1091 | − compactColor, compactColor, compactColor, compactColor }; | |
| 1101 | + int colors[NUM_VERTICES] = { compactColor, compactColor, compactColor, compactColor, | |
| 1102 | + compactColor, compactColor, compactColor, compactColor, | |
| 1103 | + compactColor, compactColor, compactColor, compactColor }; | |
| 1092 | 1104 | |
| 1093 | 1105 | |
| 1094 | 1106 | details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer); |
| 1095 | 1107 | details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); |
| 1096 | − | |
| 1097 | − delete[] vertexBuffer; | |
| 1098 | 1108 | } |
| 1099 | 1109 | |
| 1100 | 1110 | batch.setInputFormat(details.streamFormat); |
| 1101 | 1111 | batch.setInputStream(0, *details.stream); |
| 1102 | − batch.draw(gpu::QUADS, 4, 0); | |
| 1112 | + batch.draw(gpu::QUADS, details.vertices, 0); | |
| 1103 | 1113 | } |
| 1104 | 1114 | |
| 1105 | 1115 | void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { |