mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 13:24:02 +02:00
Working on porting to mac compatible shaders
This commit is contained in:
parent
230d761ec3
commit
dc1cc84c1c
4 changed files with 21 additions and 29 deletions
|
@ -41,16 +41,6 @@
|
||||||
#include "sdf_text_vert.h"
|
#include "sdf_text_vert.h"
|
||||||
#include "sdf_text_frag.h"
|
#include "sdf_text_frag.h"
|
||||||
|
|
||||||
namespace Shaders {
|
|
||||||
// Normally we could use 'enum class' to avoid namespace pollution,
|
|
||||||
// but we want easy conversion to GLuint
|
|
||||||
namespace Attributes {
|
|
||||||
enum {
|
|
||||||
Position = 0, TexCoord = 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions for reading binary data from an IO device
|
// Helper functions for reading binary data from an IO device
|
||||||
template<class T>
|
template<class T>
|
||||||
void readStream(QIODevice & in, T & t) {
|
void readStream(QIODevice & in, T & t) {
|
||||||
|
@ -290,7 +280,7 @@ QRectF Glyph::textureBounds(const glm::vec2 & textureSize) const {
|
||||||
|
|
||||||
void Font::setupGL() {
|
void Font::setupGL() {
|
||||||
_texture = TexturePtr(
|
_texture = TexturePtr(
|
||||||
new QOpenGLTexture(_image, QOpenGLTexture::DontGenerateMipMaps));
|
new QOpenGLTexture(_image, QOpenGLTexture::GenerateMipMaps));
|
||||||
_program = ProgramPtr(new QOpenGLShaderProgram());
|
_program = ProgramPtr(new QOpenGLShaderProgram());
|
||||||
if (!_program->create()) {
|
if (!_program->create()) {
|
||||||
qFatal("Could not create text shader");
|
qFatal("Could not create text shader");
|
||||||
|
@ -334,7 +324,6 @@ void Font::setupGL() {
|
||||||
_vertices->bind();
|
_vertices->bind();
|
||||||
_vertices->allocate(&vertexData[0],
|
_vertices->allocate(&vertexData[0],
|
||||||
sizeof(TextureVertex) * vertexData.size());
|
sizeof(TextureVertex) * vertexData.size());
|
||||||
|
|
||||||
_indices = BufferPtr(new QOpenGLBuffer(QOpenGLBuffer::IndexBuffer));
|
_indices = BufferPtr(new QOpenGLBuffer(QOpenGLBuffer::IndexBuffer));
|
||||||
_indices->create();
|
_indices->create();
|
||||||
_indices->bind();
|
_indices->bind();
|
||||||
|
@ -342,13 +331,12 @@ void Font::setupGL() {
|
||||||
|
|
||||||
GLsizei stride = (GLsizei) sizeof(TextureVertex);
|
GLsizei stride = (GLsizei) sizeof(TextureVertex);
|
||||||
void* offset = (void*) offsetof(TextureVertex, tex);
|
void* offset = (void*) offsetof(TextureVertex, tex);
|
||||||
|
int posLoc = _program->attributeLocation("Position");
|
||||||
glEnableVertexAttribArray(Shaders::Attributes::Position);
|
int texLoc = _program->attributeLocation("TexCoord");
|
||||||
glVertexAttribPointer(Shaders::Attributes::Position, 3, GL_FLOAT, false,
|
glEnableVertexAttribArray(posLoc);
|
||||||
stride, nullptr);
|
glVertexAttribPointer(posLoc, 3, GL_FLOAT, false, stride, nullptr);
|
||||||
glEnableVertexAttribArray(Shaders::Attributes::TexCoord);
|
glEnableVertexAttribArray(texLoc);
|
||||||
glVertexAttribPointer(Shaders::Attributes::TexCoord, 2, GL_FLOAT, false,
|
glVertexAttribPointer(texLoc, 2, GL_FLOAT, false, stride, offset);
|
||||||
stride, offset);
|
|
||||||
_vao->release();
|
_vao->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,6 +412,8 @@ glm::vec2 Font::drawString(float x, float y, const QString & str,
|
||||||
if (effectType == TextRenderer::OUTLINE_EFFECT) {
|
if (effectType == TextRenderer::OUTLINE_EFFECT) {
|
||||||
_program->setUniformValue("Outline", true);
|
_program->setUniformValue("Outline", true);
|
||||||
}
|
}
|
||||||
|
// Needed?
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
_texture->bind();
|
_texture->bind();
|
||||||
_vao->bind();
|
_vao->bind();
|
||||||
|
|
||||||
|
@ -481,6 +471,8 @@ glm::vec2 Font::drawString(float x, float y, const QString & str,
|
||||||
|
|
||||||
_vao->release();
|
_vao->release();
|
||||||
_program->release();
|
_program->release();
|
||||||
|
// FIXME, needed?
|
||||||
|
// glDisable(GL_TEXTURE_2D);
|
||||||
return advance;
|
return advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// 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
|
||||||
|
|
||||||
uniform sampler2D Font;
|
uniform sampler2D Font;
|
||||||
uniform vec4 Color = vec4(1);
|
uniform vec4 Color;
|
||||||
uniform bool Outline = false;
|
uniform bool Outline;
|
||||||
|
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const float outlineExpansion = 0.2;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// retrieve signed distance
|
// retrieve signed distance
|
||||||
float sdf = texture(Font, vTexCoord).r;
|
float sdf = texture2D(Font, vTexCoord).r;
|
||||||
if (Outline) {
|
if (Outline) {
|
||||||
if (sdf > interiorCutoff) {
|
if (sdf > interiorCutoff) {
|
||||||
sdf = 1.0 - sdf;
|
sdf = 1.0 - sdf;
|
||||||
|
|
|
@ -10,15 +10,15 @@
|
||||||
// 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
|
||||||
//
|
//
|
||||||
|
|
||||||
uniform mat4 Projection = mat4(1);
|
uniform mat4 Projection;
|
||||||
uniform mat4 ModelView = mat4(1);
|
uniform mat4 ModelView;
|
||||||
|
|
||||||
layout(location = 0) in vec3 Position;
|
attribute vec3 Position;
|
||||||
layout(location = 1) in vec2 TexCoord;
|
attribute vec2 TexCoord;
|
||||||
|
|
||||||
out vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vTexCoord = TexCoord;
|
vTexCoord = TexCoord;
|
||||||
gl_Position = Projection * ModelView * vec4(Position, 1);
|
gl_Position = Projection * ModelView * vec4(Position, 1.0);
|
||||||
}
|
}
|
|
@ -160,7 +160,7 @@ void QTestWindow::draw() {
|
||||||
|
|
||||||
// Draw the text itself
|
// Draw the text itself
|
||||||
_textRenderer[i]->draw(offsets[i].x, offsets[i].y, str,
|
_textRenderer[i]->draw(offsets[i].x, offsets[i].y, str,
|
||||||
glm::vec4(COLORS[i], 1.0f), glm::vec2(200, 200));
|
glm::vec4(COLORS[i], 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
_context->swapBuffers(this);
|
_context->swapBuffers(this);
|
||||||
|
|
Loading…
Reference in a new issue