mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 01:16:35 +02:00
Fix bevel quads
This commit is contained in:
parent
e8e1f81880
commit
bdaf8a8a32
1 changed files with 44 additions and 34 deletions
|
@ -1026,12 +1026,12 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int
|
||||||
}
|
}
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 2; // vertices
|
const int FLOATS_PER_VERTEX = 2; // vertices
|
||||||
const int vertices = 8;
|
const int NUM_VERTICES = 12;
|
||||||
|
|
||||||
if (!details.isCreated) {
|
if (!details.isCreated) {
|
||||||
|
|
||||||
details.isCreated = true;
|
details.isCreated = true;
|
||||||
details.vertices = vertices;
|
details.vertices = NUM_VERTICES;
|
||||||
details.vertexSize = FLOATS_PER_VERTEX;
|
details.vertexSize = FLOATS_PER_VERTEX;
|
||||||
|
|
||||||
gpu::BufferPointer verticesBuffer(new gpu::Buffer());
|
gpu::BufferPointer verticesBuffer(new gpu::Buffer());
|
||||||
|
@ -1044,62 +1044,72 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int
|
||||||
details.streamFormat = streamFormat;
|
details.streamFormat = streamFormat;
|
||||||
details.stream = stream;
|
details.stream = stream;
|
||||||
|
|
||||||
details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0);
|
details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ));
|
||||||
details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA));
|
details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA));
|
||||||
|
|
||||||
details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride);
|
details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride);
|
||||||
details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride);
|
details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride);
|
||||||
|
|
||||||
|
|
||||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
int vertexPoints = NUM_VERTICES * FLOATS_PER_VERTEX;
|
||||||
GLfloat* vertexBuffer = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
|
GLfloat vertexBuffer[vertexPoints]; // only vertices, no normals because we're a 2D quad
|
||||||
GLfloat* vertex = vertexBuffer;
|
|
||||||
int vertexPoint = 0;
|
int vertexPoint = 0;
|
||||||
|
|
||||||
// left side
|
// left side quad
|
||||||
vertex[vertexPoint++] = x;
|
vertexBuffer[vertexPoint++] = x;
|
||||||
vertex[vertexPoint++] = y + bevelDistance;
|
vertexBuffer[vertexPoint++] = y + bevelDistance;
|
||||||
|
|
||||||
vertex[vertexPoint++] = x;
|
vertexBuffer[vertexPoint++] = x + bevelDistance;
|
||||||
vertex[vertexPoint++] = y + height - bevelDistance;
|
vertexBuffer[vertexPoint++] = y;
|
||||||
|
|
||||||
// top side
|
|
||||||
vertex[vertexPoint++] = x + bevelDistance;
|
|
||||||
vertex[vertexPoint++] = y + height;
|
|
||||||
|
|
||||||
vertex[vertexPoint++] = x + width - bevelDistance;
|
vertexBuffer[vertexPoint++] = x + bevelDistance;
|
||||||
vertex[vertexPoint++] = y + height;
|
vertexBuffer[vertexPoint++] = y + height;
|
||||||
|
|
||||||
|
vertexBuffer[vertexPoint++] = x;
|
||||||
|
vertexBuffer[vertexPoint++] = y + height - bevelDistance;
|
||||||
|
|
||||||
// right
|
// middle quad
|
||||||
vertex[vertexPoint++] = x + width;
|
vertexBuffer[vertexPoint++] = x + bevelDistance;
|
||||||
vertex[vertexPoint++] = y + height - bevelDistance;
|
vertexBuffer[vertexPoint++] = y;
|
||||||
vertex[vertexPoint++] = x + width;
|
|
||||||
vertex[vertexPoint++] = y + bevelDistance;
|
vertexBuffer[vertexPoint++] = x + width - bevelDistance;
|
||||||
|
vertexBuffer[vertexPoint++] = y;
|
||||||
|
|
||||||
|
vertexBuffer[vertexPoint++] = x + width - bevelDistance;
|
||||||
|
vertexBuffer[vertexPoint++] = y + height;
|
||||||
|
|
||||||
|
vertexBuffer[vertexPoint++] = x + bevelDistance;
|
||||||
|
vertexBuffer[vertexPoint++] = y + height;
|
||||||
|
|
||||||
// bottom
|
// right side quad
|
||||||
vertex[vertexPoint++] = x + width - bevelDistance;
|
vertexBuffer[vertexPoint++] = x + width - bevelDistance;
|
||||||
vertex[vertexPoint++] = y;
|
vertexBuffer[vertexPoint++] = y;
|
||||||
vertex[vertexPoint++] = x +bevelDistance;
|
|
||||||
vertex[vertexPoint++] = y;
|
vertexBuffer[vertexPoint++] = x + width;
|
||||||
|
vertexBuffer[vertexPoint++] = y + bevelDistance;
|
||||||
const int NUM_COLOR_SCALARS_PER_QUAD = 8;
|
|
||||||
|
vertexBuffer[vertexPoint++] = x + width;
|
||||||
|
vertexBuffer[vertexPoint++] = y + height - bevelDistance;
|
||||||
|
|
||||||
|
vertexBuffer[vertexPoint++] = x + width - bevelDistance;
|
||||||
|
vertexBuffer[vertexPoint++] = y + height;
|
||||||
|
|
||||||
int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
|
int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
|
||||||
((int(color.y * 255.0f) & 0xFF) << 8) |
|
((int(color.y * 255.0f) & 0xFF) << 8) |
|
||||||
((int(color.z * 255.0f) & 0xFF) << 16) |
|
((int(color.z * 255.0f) & 0xFF) << 16) |
|
||||||
((int(color.w * 255.0f) & 0xFF) << 24);
|
((int(color.w * 255.0f) & 0xFF) << 24);
|
||||||
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor,
|
int colors[NUM_VERTICES] = { compactColor, compactColor, compactColor, compactColor,
|
||||||
compactColor, compactColor, compactColor, compactColor };
|
compactColor, compactColor, compactColor, compactColor,
|
||||||
|
compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
|
|
||||||
delete[] vertexBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.setInputFormat(details.streamFormat);
|
batch.setInputFormat(details.streamFormat);
|
||||||
batch.setInputStream(0, *details.stream);
|
batch.setInputStream(0, *details.stream);
|
||||||
batch.draw(gpu::QUADS, 4, 0);
|
batch.draw(gpu::QUADS, details.vertices, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {
|
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {
|
||||||
|
|
Loading…
Reference in a new issue