History

Fix bevel quads

Atlante45 committed 11 years ago

Commit bdaf8a81 parent e8e1f811 file · +45 −35Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 1 file). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+45−35
@@ -1026,12 +1026,12 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int · 1025 unmodified lines
10261026 }
10271027
10281028 const int FLOATS_PER_VERTEX = 2; // vertices
1029− const int vertices = 8;
1029+ const int NUM_VERTICES = 12;
10301030
10311031 if (!details.isCreated) {
10321032
10331033 details.isCreated = true;
1034− details.vertices = vertices;
1034+ details.vertices = NUM_VERTICES;
10351035 details.vertexSize = FLOATS_PER_VERTEX;
10361036
10371037 gpu::BufferPointer verticesBuffer(new gpu::Buffer());
@@ -1044,62 +1044,72 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int · 6 unmodified lines
10441044 details.streamFormat = streamFormat;
10451045 details.stream = stream;
10461046
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));
10481048 details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA));
10491049
10501050 details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride);
10511051 details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride);
10521052
10531053
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
10571056 int vertexPoint = 0;
10581057
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;
10621074
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;
10651083
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;
10691096
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;
10861097 int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
10871098 ((int(color.y * 255.0f) & 0xFF) << 8) |
10881099 ((int(color.z * 255.0f) & 0xFF) << 16) |
10891100 ((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 };
10921104
10931105
10941106 details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
10951107 details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
1096−
1097− delete[] vertexBuffer;
10981108 }
10991109
11001110 batch.setInputFormat(details.streamFormat);
11011111 batch.setInputStream(0, *details.stream);
1102− batch.draw(gpu::QUADS, 4, 0);
1112+ batch.draw(gpu::QUADS, details.vertices, 0);
11031113 }
11041114
11051115 void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {