mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:07:58 +02:00
No need to use a texture for the cursor; we can just use a fragment shader.
This commit is contained in:
parent
6930174a9e
commit
b7b1b018ee
3 changed files with 18 additions and 47 deletions
|
@ -11,10 +11,22 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
// the cursor texture
|
// the inner radius of the outline, squared
|
||||||
uniform sampler2D cursorMap;
|
const float SQUARED_OUTLINE_INNER_RADIUS = 0.81;
|
||||||
|
|
||||||
|
// the outer radius of the outline, squared
|
||||||
|
const float SQUARED_OUTLINE_OUTER_RADIUS = 1.0;
|
||||||
|
|
||||||
|
// the inner radius of the inset, squared
|
||||||
|
const float SQUARED_INSET_INNER_RADIUS = 0.855625;
|
||||||
|
|
||||||
|
// the outer radius of the inset, squared
|
||||||
|
const float SQUARED_INSET_OUTER_RADIUS = 0.950625;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// just multiply the color by the cursor texture
|
// use the distance to compute the ring color, then multiply it by the varying color
|
||||||
gl_FragColor = gl_Color * texture2D(cursorMap, gl_TexCoord[0].st);
|
float squaredDistance = dot(gl_TexCoord[0].st, gl_TexCoord[0].st);
|
||||||
|
float alpha = step(SQUARED_OUTLINE_INNER_RADIUS, squaredDistance) * step(squaredDistance, SQUARED_OUTLINE_OUTER_RADIUS);
|
||||||
|
float white = step(SQUARED_INSET_INNER_RADIUS, squaredDistance) * step(squaredDistance, SQUARED_INSET_OUTER_RADIUS);
|
||||||
|
gl_FragColor = gl_Color * vec4(white, white, white, alpha);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,6 @@ REGISTER_META_OBJECT(StaticModelRenderer)
|
||||||
|
|
||||||
static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
|
static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
|
||||||
|
|
||||||
MetavoxelSystem::MetavoxelSystem() :
|
|
||||||
_cursorTexture(QOpenGLTexture::Target2D) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void MetavoxelSystem::init() {
|
void MetavoxelSystem::init() {
|
||||||
MetavoxelClientManager::init();
|
MetavoxelClientManager::init();
|
||||||
DefaultMetavoxelRendererImplementation::init();
|
DefaultMetavoxelRendererImplementation::init();
|
||||||
|
@ -155,33 +151,6 @@ int HeightfieldCursorRenderVisitor::visit(MetavoxelInfo& info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
|
void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
|
||||||
// create the cursor texture lazily
|
|
||||||
if (!_cursorTexture.isCreated()) {
|
|
||||||
const int CURSOR_TEXTURE_SIZE = 512;
|
|
||||||
QImage cursorImage(CURSOR_TEXTURE_SIZE, CURSOR_TEXTURE_SIZE, QImage::Format_ARGB32_Premultiplied);
|
|
||||||
cursorImage.fill(0x0);
|
|
||||||
{
|
|
||||||
QPainter painter(&cursorImage);
|
|
||||||
const int ELLIPSE_EDGE = 10;
|
|
||||||
const int OUTER_WIDTH = 10;
|
|
||||||
QPen outerPen;
|
|
||||||
outerPen.setWidth(OUTER_WIDTH);
|
|
||||||
painter.setPen(outerPen);
|
|
||||||
const int HALF_TEXTURE_SIZE = CURSOR_TEXTURE_SIZE / 2;
|
|
||||||
painter.drawEllipse(QPoint(HALF_TEXTURE_SIZE, HALF_TEXTURE_SIZE), HALF_TEXTURE_SIZE - ELLIPSE_EDGE,
|
|
||||||
HALF_TEXTURE_SIZE - ELLIPSE_EDGE);
|
|
||||||
QPen innerPen(Qt::white);
|
|
||||||
const int INNER_WIDTH = 6;
|
|
||||||
innerPen.setWidth(INNER_WIDTH);
|
|
||||||
painter.setPen(innerPen);
|
|
||||||
painter.drawEllipse(QPoint(HALF_TEXTURE_SIZE, HALF_TEXTURE_SIZE), HALF_TEXTURE_SIZE - ELLIPSE_EDGE,
|
|
||||||
HALF_TEXTURE_SIZE - ELLIPSE_EDGE);
|
|
||||||
}
|
|
||||||
_cursorTexture.setData(cursorImage, QOpenGLTexture::DontGenerateMipMaps);
|
|
||||||
_cursorTexture.setWrapMode(QOpenGLTexture::ClampToEdge);
|
|
||||||
_cursorTexture.setMinificationFilter(QOpenGLTexture::Linear);
|
|
||||||
}
|
|
||||||
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
@ -196,21 +165,16 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE4);
|
glActiveTexture(GL_TEXTURE4);
|
||||||
float scale = 1.0f / radius;
|
float scale = 1.0f / radius;
|
||||||
glm::vec4 sCoefficients(scale, 0.0f, 0.0f, 0.5f - scale * position.x);
|
glm::vec4 sCoefficients(scale, 0.0f, 0.0f, -scale * position.x);
|
||||||
glm::vec4 tCoefficients(0.0f, 0.0f, scale, 0.5f - scale * position.z);
|
glm::vec4 tCoefficients(0.0f, 0.0f, scale, -scale * position.z);
|
||||||
glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&sCoefficients);
|
glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&sCoefficients);
|
||||||
glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&tCoefficients);
|
glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&tCoefficients);
|
||||||
|
|
||||||
_cursorTexture.bind(1);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
glm::vec3 extents(radius, radius, radius);
|
glm::vec3 extents(radius, radius, radius);
|
||||||
HeightfieldCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
|
HeightfieldCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
|
||||||
guideToAugmented(visitor);
|
guideToAugmented(visitor);
|
||||||
|
|
||||||
_cursorTexture.release(1);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release();
|
DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release();
|
||||||
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLTexture>
|
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
@ -32,8 +31,6 @@ class MetavoxelSystem : public MetavoxelClientManager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MetavoxelSystem();
|
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
virtual MetavoxelLOD getLOD();
|
virtual MetavoxelLOD getLOD();
|
||||||
|
@ -64,8 +61,6 @@ private:
|
||||||
MetavoxelLOD _lod;
|
MetavoxelLOD _lod;
|
||||||
QReadWriteLock _lodLock;
|
QReadWriteLock _lodLock;
|
||||||
Frustum _frustum;
|
Frustum _frustum;
|
||||||
|
|
||||||
QOpenGLTexture _cursorTexture;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Describes contents of a point in a point buffer.
|
/// Describes contents of a point in a point buffer.
|
||||||
|
|
Loading…
Reference in a new issue