mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
Working on mac functionality
This commit is contained in:
parent
5abf08817e
commit
0034a14fc1
13 changed files with 108 additions and 542 deletions
|
@ -1068,6 +1068,7 @@ void Application::paintGL() {
|
||||||
uvec2 finalSize = toGlm(size);
|
uvec2 finalSize = toGlm(size);
|
||||||
// Ensure the rendering context commands are completed when rendering
|
// Ensure the rendering context commands are completed when rendering
|
||||||
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||||
|
glFinish();
|
||||||
_offscreenContext->doneCurrent();
|
_offscreenContext->doneCurrent();
|
||||||
Q_ASSERT(!QOpenGLContext::currentContext());
|
Q_ASSERT(!QOpenGLContext::currentContext());
|
||||||
displayPlugin->preDisplay();
|
displayPlugin->preDisplay();
|
||||||
|
|
|
@ -1,324 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Bradley Austin Davis on 2015/05/29
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
#include "OglplusHelpers.h"
|
|
||||||
|
|
||||||
#include <NumericalConstants.h>
|
|
||||||
|
|
||||||
using namespace oglplus;
|
|
||||||
using namespace oglplus::shapes;
|
|
||||||
|
|
||||||
static const char * SIMPLE_TEXTURED_VS = R"VS(#version 410 core
|
|
||||||
#pragma line __LINE__
|
|
||||||
|
|
||||||
uniform mat4 Projection = mat4(1);
|
|
||||||
uniform mat4 ModelView = mat4(1);
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 Position;
|
|
||||||
layout(location = 1) in vec2 TexCoord;
|
|
||||||
|
|
||||||
out vec2 vTexCoord;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = Projection * ModelView * vec4(Position, 1);
|
|
||||||
vTexCoord = TexCoord;
|
|
||||||
}
|
|
||||||
|
|
||||||
)VS";
|
|
||||||
|
|
||||||
static const char * SIMPLE_TEXTURED_FS = R"FS(#version 410 core
|
|
||||||
#pragma line __LINE__
|
|
||||||
|
|
||||||
uniform sampler2D sampler;
|
|
||||||
uniform float Alpha = 1.0;
|
|
||||||
|
|
||||||
in vec2 vTexCoord;
|
|
||||||
out vec4 vFragColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 c = texture(sampler, vTexCoord);
|
|
||||||
c.a = min(Alpha, c.a);
|
|
||||||
vFragColor = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
)FS";
|
|
||||||
|
|
||||||
|
|
||||||
ProgramPtr loadDefaultShader() {
|
|
||||||
ProgramPtr result;
|
|
||||||
compileProgram(result, SIMPLE_TEXTURED_VS, SIMPLE_TEXTURED_FS);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void compileProgram(ProgramPtr & result, const std::string& vs, const std::string& fs) {
|
|
||||||
using namespace oglplus;
|
|
||||||
try {
|
|
||||||
result = ProgramPtr(new Program());
|
|
||||||
// attach the shaders to the program
|
|
||||||
result->AttachShader(
|
|
||||||
VertexShader()
|
|
||||||
.Source(GLSLSource(vs))
|
|
||||||
.Compile()
|
|
||||||
);
|
|
||||||
result->AttachShader(
|
|
||||||
FragmentShader()
|
|
||||||
.Source(GLSLSource(fs))
|
|
||||||
.Compile()
|
|
||||||
);
|
|
||||||
result->Link();
|
|
||||||
} catch (ProgramBuildError & err) {
|
|
||||||
Q_UNUSED(err);
|
|
||||||
Q_ASSERT_X(false, "compileProgram", "Failed to build shader program");
|
|
||||||
qFatal((const char*)err.Message);
|
|
||||||
result.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ShapeWrapperPtr loadPlane(ProgramPtr program, float aspect) {
|
|
||||||
using namespace oglplus;
|
|
||||||
Vec3f a(1, 0, 0);
|
|
||||||
Vec3f b(0, 1, 0);
|
|
||||||
if (aspect > 1) {
|
|
||||||
b[1] /= aspect;
|
|
||||||
} else {
|
|
||||||
a[0] *= aspect;
|
|
||||||
}
|
|
||||||
return ShapeWrapperPtr(
|
|
||||||
new shapes::ShapeWrapper({ "Position", "TexCoord" }, shapes::Plane(a, b), *program)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a point's cartesian coordinates on a sphere from pitch and yaw
|
|
||||||
static glm::vec3 getPoint(float yaw, float pitch) {
|
|
||||||
return glm::vec3(glm::cos(-pitch) * (-glm::sin(yaw)),
|
|
||||||
glm::sin(-pitch),
|
|
||||||
glm::cos(-pitch) * (-glm::cos(yaw)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SphereSection : public DrawingInstructionWriter, public DrawMode {
|
|
||||||
public:
|
|
||||||
using IndexArray = std::vector<GLuint>;
|
|
||||||
using PosArray = std::vector<float>;
|
|
||||||
using TexArray = std::vector<float>;
|
|
||||||
/// The type of the index container returned by Indices()
|
|
||||||
// vertex positions
|
|
||||||
PosArray _pos_data;
|
|
||||||
// vertex tex coords
|
|
||||||
TexArray _tex_data;
|
|
||||||
IndexArray _idx_data;
|
|
||||||
unsigned int _prim_count{ 0 };
|
|
||||||
|
|
||||||
public:
|
|
||||||
SphereSection(
|
|
||||||
const float fov,
|
|
||||||
const float aspectRatio,
|
|
||||||
const int slices_,
|
|
||||||
const int stacks_) {
|
|
||||||
//UV mapping source: http://www.mvps.org/directx/articles/spheremap.htm
|
|
||||||
if (fov >= PI) {
|
|
||||||
qDebug() << "TexturedHemisphere::buildVBO(): FOV greater or equal than Pi will create issues";
|
|
||||||
}
|
|
||||||
|
|
||||||
int gridSize = std::max(slices_, stacks_);
|
|
||||||
int gridSizeLog2 = 1;
|
|
||||||
while (1 << gridSizeLog2 < gridSize) {
|
|
||||||
++gridSizeLog2;
|
|
||||||
}
|
|
||||||
gridSize = (1 << gridSizeLog2) + 1;
|
|
||||||
// Compute number of vertices needed
|
|
||||||
int vertices = gridSize * gridSize;
|
|
||||||
_pos_data.resize(vertices * 3);
|
|
||||||
_tex_data.resize(vertices * 2);
|
|
||||||
|
|
||||||
// Compute vertices positions and texture UV coordinate
|
|
||||||
for (int y = 0; y <= gridSize; ++y) {
|
|
||||||
for (int x = 0; x <= gridSize; ++x) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < gridSize; i++) {
|
|
||||||
float stacksRatio = (float)i / (float)(gridSize - 1); // First stack is 0.0f, last stack is 1.0f
|
|
||||||
// abs(theta) <= fov / 2.0f
|
|
||||||
float pitch = -fov * (stacksRatio - 0.5f);
|
|
||||||
for (int j = 0; j < gridSize; j++) {
|
|
||||||
float slicesRatio = (float)j / (float)(gridSize - 1); // First slice is 0.0f, last slice is 1.0f
|
|
||||||
// abs(phi) <= fov * aspectRatio / 2.0f
|
|
||||||
float yaw = -fov * aspectRatio * (slicesRatio - 0.5f);
|
|
||||||
int vertex = i * gridSize + j;
|
|
||||||
int posOffset = vertex * 3;
|
|
||||||
int texOffset = vertex * 2;
|
|
||||||
vec3 pos = getPoint(yaw, pitch);
|
|
||||||
_pos_data[posOffset] = pos.x;
|
|
||||||
_pos_data[posOffset + 1] = pos.y;
|
|
||||||
_pos_data[posOffset + 2] = pos.z;
|
|
||||||
_tex_data[texOffset] = slicesRatio;
|
|
||||||
_tex_data[texOffset + 1] = stacksRatio;
|
|
||||||
}
|
|
||||||
} // done with vertices
|
|
||||||
|
|
||||||
int rowLen = gridSize;
|
|
||||||
|
|
||||||
// gridsize now refers to the triangles, not the vertices, so reduce by one
|
|
||||||
// or die by fencepost error http://en.wikipedia.org/wiki/Off-by-one_error
|
|
||||||
--gridSize;
|
|
||||||
int quads = gridSize * gridSize;
|
|
||||||
for (int t = 0; t < quads; ++t) {
|
|
||||||
int x =
|
|
||||||
((t & 0x0001) >> 0) |
|
|
||||||
((t & 0x0004) >> 1) |
|
|
||||||
((t & 0x0010) >> 2) |
|
|
||||||
((t & 0x0040) >> 3) |
|
|
||||||
((t & 0x0100) >> 4) |
|
|
||||||
((t & 0x0400) >> 5) |
|
|
||||||
((t & 0x1000) >> 6) |
|
|
||||||
((t & 0x4000) >> 7);
|
|
||||||
int y =
|
|
||||||
((t & 0x0002) >> 1) |
|
|
||||||
((t & 0x0008) >> 2) |
|
|
||||||
((t & 0x0020) >> 3) |
|
|
||||||
((t & 0x0080) >> 4) |
|
|
||||||
((t & 0x0200) >> 5) |
|
|
||||||
((t & 0x0800) >> 6) |
|
|
||||||
((t & 0x2000) >> 7) |
|
|
||||||
((t & 0x8000) >> 8);
|
|
||||||
int i = x * (rowLen) + y;
|
|
||||||
|
|
||||||
_idx_data.push_back(i);
|
|
||||||
_idx_data.push_back(i + 1);
|
|
||||||
_idx_data.push_back(i + rowLen + 1);
|
|
||||||
|
|
||||||
_idx_data.push_back(i + rowLen + 1);
|
|
||||||
_idx_data.push_back(i + rowLen);
|
|
||||||
_idx_data.push_back(i);
|
|
||||||
}
|
|
||||||
_prim_count = quads * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the winding direction of faces
|
|
||||||
FaceOrientation FaceWinding(void) const {
|
|
||||||
return FaceOrientation::CCW;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef GLuint(SphereSection::*VertexAttribFunc)(std::vector<GLfloat>&) const;
|
|
||||||
|
|
||||||
/// Makes the vertex positions and returns the number of values per vertex
|
|
||||||
template <typename T>
|
|
||||||
GLuint Positions(std::vector<T>& dest) const {
|
|
||||||
dest.clear();
|
|
||||||
dest.insert(dest.begin(), _pos_data.begin(), _pos_data.end());
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes the vertex normals and returns the number of values per vertex
|
|
||||||
template <typename T>
|
|
||||||
GLuint Normals(std::vector<T>& dest) const {
|
|
||||||
dest.clear();
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes the vertex tangents and returns the number of values per vertex
|
|
||||||
template <typename T>
|
|
||||||
GLuint Tangents(std::vector<T>& dest) const {
|
|
||||||
dest.clear();
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes the vertex bi-tangents and returns the number of values per vertex
|
|
||||||
template <typename T>
|
|
||||||
GLuint Bitangents(std::vector<T>& dest) const {
|
|
||||||
dest.clear();
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes the texture coordinates returns the number of values per vertex
|
|
||||||
template <typename T>
|
|
||||||
GLuint TexCoordinates(std::vector<T>& dest) const {
|
|
||||||
dest.clear();
|
|
||||||
dest.insert(dest.begin(), _tex_data.begin(), _tex_data.end());
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef VertexAttribsInfo<
|
|
||||||
SphereSection,
|
|
||||||
std::tuple<
|
|
||||||
VertexPositionsTag,
|
|
||||||
VertexNormalsTag,
|
|
||||||
VertexTangentsTag,
|
|
||||||
VertexBitangentsTag,
|
|
||||||
VertexTexCoordinatesTag
|
|
||||||
>
|
|
||||||
> VertexAttribs;
|
|
||||||
|
|
||||||
Spheref MakeBoundingSphere(void) const {
|
|
||||||
GLfloat min_x = _pos_data[3], max_x = _pos_data[3];
|
|
||||||
GLfloat min_y = _pos_data[4], max_y = _pos_data[4];
|
|
||||||
GLfloat min_z = _pos_data[5], max_z = _pos_data[5];
|
|
||||||
for (std::size_t v = 0, vn = _pos_data.size() / 3; v != vn; ++v) {
|
|
||||||
GLfloat x = _pos_data[v * 3 + 0];
|
|
||||||
GLfloat y = _pos_data[v * 3 + 1];
|
|
||||||
GLfloat z = _pos_data[v * 3 + 2];
|
|
||||||
|
|
||||||
if (min_x > x) min_x = x;
|
|
||||||
if (min_y > y) min_y = y;
|
|
||||||
if (min_z > z) min_z = z;
|
|
||||||
if (max_x < x) max_x = x;
|
|
||||||
if (max_y < y) max_y = y;
|
|
||||||
if (max_z < z) max_z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3f c(
|
|
||||||
(min_x + max_x) * 0.5f,
|
|
||||||
(min_y + max_y) * 0.5f,
|
|
||||||
(min_z + max_z) * 0.5f
|
|
||||||
);
|
|
||||||
|
|
||||||
return Spheref(
|
|
||||||
c.x(), c.y(), c.z(),
|
|
||||||
Distance(c, Vec3f(min_x, min_y, min_z))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Queries the bounding sphere coordinates and dimensions
|
|
||||||
template <typename T>
|
|
||||||
void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const {
|
|
||||||
bounding_sphere = oglplus::Sphere<T>(MakeBoundingSphere());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Returns element indices that are used with the drawing instructions
|
|
||||||
const IndexArray & Indices(Default = Default()) const {
|
|
||||||
return _idx_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the instructions for rendering of faces
|
|
||||||
DrawingInstructions Instructions(PrimitiveType primitive) const {
|
|
||||||
DrawingInstructions instr = this->MakeInstructions();
|
|
||||||
DrawOperation operation;
|
|
||||||
operation.method = DrawOperation::Method::DrawElements;
|
|
||||||
operation.mode = primitive;
|
|
||||||
operation.first = 0;
|
|
||||||
operation.count = _prim_count * 3;
|
|
||||||
operation.restart_index = DrawOperation::NoRestartIndex();
|
|
||||||
operation.phase = 0;
|
|
||||||
this->AddInstruction(instr, operation);
|
|
||||||
return std::move(instr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the instructions for rendering of faces
|
|
||||||
DrawingInstructions Instructions(Default = Default()) const {
|
|
||||||
return Instructions(PrimitiveType::Triangles);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ShapeWrapperPtr loadSphereSection(ProgramPtr program, float fov, float aspect, int slices, int stacks) {
|
|
||||||
using namespace oglplus;
|
|
||||||
return ShapeWrapperPtr(
|
|
||||||
new shapes::ShapeWrapper({ "Position", "TexCoord" }, SphereSection(fov, aspect, slices, stacks), *program)
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,150 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Bradley Austin Davis on 2015/05/26
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <GLMHelpers.h>
|
|
||||||
|
|
||||||
#pragma warning(disable : 4068)
|
|
||||||
|
|
||||||
#define OGLPLUS_USE_GLEW 1
|
|
||||||
#define OGLPLUS_USE_GLCOREARB_H 0
|
|
||||||
#define OGLPLUS_USE_BOOST_CONFIG 1
|
|
||||||
#define OGLPLUS_NO_SITE_CONFIG 1
|
|
||||||
#define OGLPLUS_LOW_PROFILE 1
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <oglplus/gl.hpp>
|
|
||||||
|
|
||||||
#include <oglplus/all.hpp>
|
|
||||||
#include <oglplus/interop/glm.hpp>
|
|
||||||
#include <oglplus/bound/texture.hpp>
|
|
||||||
#include <oglplus/bound/framebuffer.hpp>
|
|
||||||
#include <oglplus/bound/renderbuffer.hpp>
|
|
||||||
#include <oglplus/shapes/wrapper.hpp>
|
|
||||||
#include <oglplus/shapes/plane.hpp>
|
|
||||||
|
|
||||||
#include <NumericalConstants.h>
|
|
||||||
|
|
||||||
using FramebufferPtr = std::shared_ptr<oglplus::Framebuffer>;
|
|
||||||
using ShapeWrapperPtr = std::shared_ptr<oglplus::shapes::ShapeWrapper>;
|
|
||||||
using BufferPtr = std::shared_ptr<oglplus::Buffer>;
|
|
||||||
using VertexArrayPtr = std::shared_ptr<oglplus::VertexArray>;
|
|
||||||
using ProgramPtr = std::shared_ptr<oglplus::Program>;
|
|
||||||
using Mat4Uniform = oglplus::Uniform<mat4>;
|
|
||||||
|
|
||||||
ProgramPtr loadDefaultShader();
|
|
||||||
void compileProgram(ProgramPtr & result, const std::string& vs, const std::string& fs);
|
|
||||||
ShapeWrapperPtr loadPlane(ProgramPtr program, float aspect = 1.0f);
|
|
||||||
ShapeWrapperPtr loadSphereSection(ProgramPtr program, float fov = PI / 3.0f * 2.0f, float aspect = 16.0f / 9.0f, int slices = 32, int stacks = 32);
|
|
||||||
|
|
||||||
|
|
||||||
// A basic wrapper for constructing a framebuffer with a renderbuffer
|
|
||||||
// for the depth attachment and an undefined type for the color attachement
|
|
||||||
// This allows us to reuse the basic framebuffer code for both the Mirror
|
|
||||||
// FBO as well as the Oculus swap textures we will use to render the scene
|
|
||||||
// Though we don't really need depth at all for the mirror FBO, or even an
|
|
||||||
// FBO, but using one means I can just use a glBlitFramebuffer to get it onto
|
|
||||||
// the screen.
|
|
||||||
template <
|
|
||||||
typename C,
|
|
||||||
typename D
|
|
||||||
>
|
|
||||||
struct FramebufferWrapper {
|
|
||||||
uvec2 size;
|
|
||||||
oglplus::Framebuffer fbo;
|
|
||||||
C color;
|
|
||||||
D depth;
|
|
||||||
|
|
||||||
FramebufferWrapper() {}
|
|
||||||
|
|
||||||
virtual ~FramebufferWrapper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Init(const uvec2 & size) {
|
|
||||||
this->size = size;
|
|
||||||
initColor();
|
|
||||||
initDepth();
|
|
||||||
initDone();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
void Bound(F f) {
|
|
||||||
Bound(oglplus::Framebuffer::Target::Draw, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
void Bound(oglplus::Framebuffer::Target target , F f) {
|
|
||||||
fbo.Bind(target);
|
|
||||||
onBind(target);
|
|
||||||
f();
|
|
||||||
onUnbind(target);
|
|
||||||
oglplus::DefaultFramebuffer().Bind(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Viewport() {
|
|
||||||
oglplus::Context::Viewport(size.x, size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void onBind(oglplus::Framebuffer::Target target) {}
|
|
||||||
virtual void onUnbind(oglplus::Framebuffer::Target target) {}
|
|
||||||
|
|
||||||
static GLenum toEnum(oglplus::Framebuffer::Target target) {
|
|
||||||
switch (target) {
|
|
||||||
case oglplus::Framebuffer::Target::Draw:
|
|
||||||
return GL_DRAW_FRAMEBUFFER;
|
|
||||||
case oglplus::Framebuffer::Target::Read:
|
|
||||||
return GL_READ_FRAMEBUFFER;
|
|
||||||
default:
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return GL_FRAMEBUFFER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void initDepth() {}
|
|
||||||
|
|
||||||
virtual void initColor() {}
|
|
||||||
|
|
||||||
virtual void initDone() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BasicFramebufferWrapper : public FramebufferWrapper <oglplus::Texture, oglplus::Renderbuffer> {
|
|
||||||
protected:
|
|
||||||
virtual void initDepth() override {
|
|
||||||
using namespace oglplus;
|
|
||||||
Context::Bound(Renderbuffer::Target::Renderbuffer, depth)
|
|
||||||
.Storage(
|
|
||||||
PixelDataInternalFormat::DepthComponent,
|
|
||||||
size.x, size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void initColor() override {
|
|
||||||
using namespace oglplus;
|
|
||||||
Context::Bound(oglplus::Texture::Target::_2D, color)
|
|
||||||
.MinFilter(TextureMinFilter::Linear)
|
|
||||||
.MagFilter(TextureMagFilter::Linear)
|
|
||||||
.WrapS(TextureWrap::ClampToEdge)
|
|
||||||
.WrapT(TextureWrap::ClampToEdge)
|
|
||||||
.Image2D(
|
|
||||||
0, PixelDataInternalFormat::RGBA8,
|
|
||||||
size.x, size.y,
|
|
||||||
0, PixelDataFormat::RGB, PixelDataType::UnsignedByte, nullptr
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void initDone() override {
|
|
||||||
using namespace oglplus;
|
|
||||||
static const Framebuffer::Target target = Framebuffer::Target::Draw;
|
|
||||||
Bound(target, [&] {
|
|
||||||
fbo.AttachTexture(target, FramebufferAttachment::Color, color, 0);
|
|
||||||
fbo.AttachRenderbuffer(target, FramebufferAttachment::Depth, depth);
|
|
||||||
fbo.Complete(target);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using BasicFramebufferWrapperPtr = std::shared_ptr<BasicFramebufferWrapper>;
|
|
|
@ -36,15 +36,36 @@ void OpenGLDisplayPlugin::finishFrame() {
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static float PLANE_VERTICES[] = {
|
||||||
|
-1, -1, 0, 0,
|
||||||
|
-1, +1, 0, 1,
|
||||||
|
+1, -1, 1, 0,
|
||||||
|
+1, +1, 1, 1,
|
||||||
|
};
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::customizeContext(PluginContainer * container) {
|
void OpenGLDisplayPlugin::customizeContext(PluginContainer * container) {
|
||||||
using namespace oglplus;
|
using namespace oglplus;
|
||||||
Context::BlendFunc(BlendFunction::SrcAlpha, BlendFunction::OneMinusSrcAlpha);
|
Context::BlendFunc(BlendFunction::SrcAlpha, BlendFunction::OneMinusSrcAlpha);
|
||||||
Context::Disable(Capability::Blend);
|
Context::Disable(Capability::Blend);
|
||||||
Context::Disable(Capability::DepthTest);
|
Context::Disable(Capability::DepthTest);
|
||||||
Context::Disable(Capability::CullFace);
|
Context::Disable(Capability::CullFace);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
_program = loadDefaultShader();
|
_program = loadDefaultShader();
|
||||||
_plane = loadPlane(_program);
|
auto attribs = _program->ActiveAttribs();
|
||||||
Context::ClearColor(0, 0, 0, 1);
|
for(size_t i = 0; i < attribs.Size(); ++i) {
|
||||||
|
auto attrib = attribs.At(i);
|
||||||
|
if (String("Position") == attrib.Name()) {
|
||||||
|
_positionAttribute = attrib.Index();
|
||||||
|
} else if (String("TexCoord") == attrib.Name()) {
|
||||||
|
_texCoordAttribute = attrib.Index();
|
||||||
|
}
|
||||||
|
qDebug() << attrib.Name().c_str();
|
||||||
|
}
|
||||||
|
_vertexBuffer.reset(new oglplus::Buffer());
|
||||||
|
_vertexBuffer->Bind(Buffer::Target::Array);
|
||||||
|
_vertexBuffer->Data(Buffer::Target::Array, BufferData(PLANE_VERTICES));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::activate(PluginContainer * container) {
|
void OpenGLDisplayPlugin::activate(PluginContainer * container) {
|
||||||
|
@ -56,8 +77,9 @@ void OpenGLDisplayPlugin::deactivate() {
|
||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
Q_ASSERT(0 == glGetError());
|
Q_ASSERT(0 == glGetError());
|
||||||
_plane.reset();
|
_vertexBuffer.reset();
|
||||||
_program.reset();
|
// glDeleteBuffers(1, &_vertexBuffer);
|
||||||
|
// _vertexBuffer = 0;
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,10 +129,18 @@ void OpenGLDisplayPlugin::display(
|
||||||
|
|
||||||
uvec2 size = getRecommendedRenderSize();
|
uvec2 size = getRecommendedRenderSize();
|
||||||
Context::Viewport(size.x, size.y);
|
Context::Viewport(size.x, size.y);
|
||||||
|
glClearColor(1, 0, 1, 1);
|
||||||
Context::Clear().ColorBuffer();
|
Context::Clear().ColorBuffer();
|
||||||
|
|
||||||
_program->Bind();
|
_program->Bind();
|
||||||
glBindTexture(GL_TEXTURE_2D, finalTexture);
|
glBindTexture(GL_TEXTURE_2D, finalTexture);
|
||||||
_plane->Use();
|
_vertexBuffer->Bind(Buffer::Target::Array);
|
||||||
_plane->Draw();
|
glEnableVertexAttribArray(_positionAttribute);
|
||||||
|
glVertexAttribPointer(_positionAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
|
||||||
|
glEnableVertexAttribArray(_texCoordAttribute);
|
||||||
|
glVertexAttribPointer(_texCoordAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)(sizeof(float) * 2));
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
//glDisableVertexAttribArray(_positionAttribute);
|
||||||
|
//glDisableVertexAttribArray(_texCoordAttribute);
|
||||||
|
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,9 @@ protected:
|
||||||
|
|
||||||
QTimer _timer;
|
QTimer _timer;
|
||||||
ProgramPtr _program;
|
ProgramPtr _program;
|
||||||
ShapeWrapperPtr _plane;
|
BufferPtr _vertexBuffer;
|
||||||
|
GLint _positionAttribute{0};
|
||||||
|
GLint _texCoordAttribute{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#ifndef gpu__GPUConfig__
|
#ifndef gpu__GPUConfig__
|
||||||
#define gpu__GPUConfig__
|
#define gpu__GPUConfig__
|
||||||
|
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES 1
|
#define GL_GLEXT_PROTOTYPES 1
|
||||||
|
|
||||||
|
@ -24,8 +23,12 @@
|
||||||
#define GPU_FEATURE_PROFILE GPU_LEGACY
|
#define GPU_FEATURE_PROFILE GPU_LEGACY
|
||||||
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
|
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
|
||||||
|
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
#include <OpenGL/glext.h>
|
||||||
|
|
||||||
#elif defined(WIN32)
|
#elif defined(WIN32)
|
||||||
#include <windowshacks.h>
|
#include <windowshacks.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
#include <GL/wglew.h>
|
#include <GL/wglew.h>
|
||||||
|
|
||||||
#define GPU_FEATURE_PROFILE GPU_CORE
|
#define GPU_FEATURE_PROFILE GPU_CORE
|
||||||
|
@ -35,8 +38,9 @@
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define GPU_FEATURE_PROFILE GPU_LEGACY
|
#define GPU_FEATURE_PROFILE GPU_CORE
|
||||||
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
|
#define GPU_TRANSFORM_PROFILE GPU_CORE
|
||||||
|
#include <GL/glew.h>
|
||||||
#include <GL/glxew.h>
|
#include <GL/glxew.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,6 +14,14 @@ add_dependency_external_projects(glm)
|
||||||
find_package(GLM REQUIRED)
|
find_package(GLM REQUIRED)
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
|
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
add_dependency_external_projects(boostconfig)
|
||||||
|
find_package(BoostConfig REQUIRED)
|
||||||
|
target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
add_dependency_external_projects(oglplus)
|
||||||
|
find_package(OGLPLUS REQUIRED)
|
||||||
|
target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS})
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
if (USE_NSIGHT)
|
if (USE_NSIGHT)
|
||||||
# try to find the Nsight package and add it to the build if we find it
|
# try to find the Nsight package and add it to the build if we find it
|
||||||
|
@ -24,14 +32,6 @@ if (WIN32)
|
||||||
target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}")
|
target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}")
|
||||||
endif ()
|
endif ()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_dependency_external_projects(boostconfig)
|
|
||||||
find_package(BoostConfig REQUIRED)
|
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
add_dependency_external_projects(oglplus)
|
|
||||||
find_package(OGLPLUS REQUIRED)
|
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS})
|
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
||||||
link_hifi_libraries(animation fbx shared gpu model render)
|
link_hifi_libraries(animation fbx shared gpu model render)
|
||||||
|
|
|
@ -41,23 +41,31 @@ GlWindow::~GlWindow() {
|
||||||
|
|
||||||
|
|
||||||
bool GlWindow::makeCurrent() {
|
bool GlWindow::makeCurrent() {
|
||||||
bool makeCurrentResult = _context->makeCurrent(this);
|
bool makeCurrentResult = _context->makeCurrent(this);
|
||||||
Q_ASSERT(makeCurrentResult);
|
Q_ASSERT(makeCurrentResult);
|
||||||
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
|
|
||||||
Q_ASSERT(_context == currentContext);
|
std::call_once(_reportOnce, []{
|
||||||
|
qDebug() << "GL Version: " << QString((const char*) glGetString(GL_VERSION));
|
||||||
|
qDebug() << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
|
qDebug() << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR));
|
||||||
|
qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
|
||||||
|
});
|
||||||
|
|
||||||
|
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
|
||||||
|
Q_ASSERT(_context == currentContext);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (!_logger) {
|
if (!_logger) {
|
||||||
_logger = new QOpenGLDebugLogger(this);
|
_logger = new QOpenGLDebugLogger(this);
|
||||||
if (_logger->initialize()) {
|
if (_logger->initialize()) {
|
||||||
connect(_logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message) {
|
connect(_logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message) {
|
||||||
qDebug() << message;
|
qDebug() << message;
|
||||||
});
|
});
|
||||||
_logger->disableMessages(QOpenGLDebugMessage::AnySource, QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity);
|
_logger->disableMessages(QOpenGLDebugMessage::AnySource, QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity);
|
||||||
_logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging);
|
_logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return makeCurrentResult;
|
return makeCurrentResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlWindow::doneCurrent() {
|
void GlWindow::doneCurrent() {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#ifndef hifi_GlWindow_h
|
#ifndef hifi_GlWindow_h
|
||||||
#define hifi_GlWindow_h
|
#define hifi_GlWindow_h
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
class QOpenGLContext;
|
class QOpenGLContext;
|
||||||
|
@ -25,6 +27,7 @@ public:
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::once_flag _reportOnce;
|
||||||
QOpenGLContext* _context{ nullptr };
|
QOpenGLContext* _context{ nullptr };
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
QOpenGLDebugLogger* _logger{ nullptr };
|
QOpenGLDebugLogger* _logger{ nullptr };
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include "OffscreenGlCanvas.h"
|
#include "OffscreenGlCanvas.h"
|
||||||
#include <QOpenGLDebugLogger>
|
#include <QOpenGLDebugLogger>
|
||||||
|
#include <GLHelpers.cpp>
|
||||||
|
|
||||||
|
|
||||||
OffscreenGlCanvas::OffscreenGlCanvas() {
|
OffscreenGlCanvas::OffscreenGlCanvas() {
|
||||||
}
|
}
|
||||||
|
@ -33,19 +35,9 @@ void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) {
|
||||||
_context.setFormat(sharedContext->format());
|
_context.setFormat(sharedContext->format());
|
||||||
_context.setShareContext(sharedContext);
|
_context.setShareContext(sharedContext);
|
||||||
} else {
|
} else {
|
||||||
QSurfaceFormat format;
|
_context.setFormat(getDefaultOpenGlSurfaceFormat());
|
||||||
format.setDepthBufferSize(16);
|
|
||||||
format.setStencilBufferSize(8);
|
|
||||||
format.setMajorVersion(4);
|
|
||||||
format.setMinorVersion(1);
|
|
||||||
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile);
|
|
||||||
#ifdef DEBUG
|
|
||||||
format.setOption(QSurfaceFormat::DebugContext);
|
|
||||||
#endif
|
|
||||||
_context.setFormat(format);
|
|
||||||
}
|
}
|
||||||
_context.create();
|
_context.create();
|
||||||
|
|
||||||
_offscreenSurface.setFormat(_context.format());
|
_offscreenSurface.setFormat(_context.format());
|
||||||
_offscreenSurface.create();
|
_offscreenSurface.create();
|
||||||
|
|
||||||
|
@ -53,6 +45,14 @@ void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) {
|
||||||
|
|
||||||
bool OffscreenGlCanvas::makeCurrent() {
|
bool OffscreenGlCanvas::makeCurrent() {
|
||||||
bool result = _context.makeCurrent(&_offscreenSurface);
|
bool result = _context.makeCurrent(&_offscreenSurface);
|
||||||
|
Q_ASSERT(result);
|
||||||
|
|
||||||
|
std::call_once(_reportOnce, []{
|
||||||
|
qDebug() << "GL Version: " << QString((const char*) glGetString(GL_VERSION));
|
||||||
|
qDebug() << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
|
qDebug() << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR));
|
||||||
|
qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
|
||||||
|
});
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (result && !_logger) {
|
if (result && !_logger) {
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#ifndef hifi_OffscreenGlCanvas_h
|
#ifndef hifi_OffscreenGlCanvas_h
|
||||||
#define hifi_OffscreenGlCanvas_h
|
#define hifi_OffscreenGlCanvas_h
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOffscreenSurface>
|
#include <QOffscreenSurface>
|
||||||
|
|
||||||
|
@ -29,6 +31,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
std::once_flag _reportOnce;
|
||||||
QOpenGLContext _context;
|
QOpenGLContext _context;
|
||||||
QOffscreenSurface _offscreenSurface;
|
QOffscreenSurface _offscreenSurface;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Created by Bradley Austin Davis on 2015/05/29
|
// Created by Bradley Austin Davis on 2015/05/29
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
@ -12,37 +10,31 @@
|
||||||
using namespace oglplus;
|
using namespace oglplus;
|
||||||
using namespace oglplus::shapes;
|
using namespace oglplus::shapes;
|
||||||
|
|
||||||
static const char * SIMPLE_TEXTURED_VS = R"VS(#version 410 core
|
static const char * SIMPLE_TEXTURED_VS = R"VS(#version 120
|
||||||
#pragma line __LINE__
|
#pragma line __LINE__
|
||||||
|
|
||||||
uniform mat4 Projection = mat4(1);
|
attribute vec3 Position;
|
||||||
uniform mat4 ModelView = mat4(1);
|
attribute vec2 TexCoord;
|
||||||
|
|
||||||
layout(location = 0) in vec3 Position;
|
varying vec2 vTexCoord;
|
||||||
layout(location = 1) in vec2 TexCoord;
|
|
||||||
|
|
||||||
out vec2 vTexCoord;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = Projection * ModelView * vec4(Position, 1);
|
gl_Position = vec4(Position, 1);
|
||||||
vTexCoord = TexCoord;
|
vTexCoord = TexCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
)VS";
|
)VS";
|
||||||
|
|
||||||
static const char * SIMPLE_TEXTURED_FS = R"FS(#version 410 core
|
static const char * SIMPLE_TEXTURED_FS = R"FS(#version 120
|
||||||
#pragma line __LINE__
|
#pragma line __LINE__
|
||||||
|
|
||||||
uniform sampler2D sampler;
|
uniform sampler2D sampler;
|
||||||
uniform float Alpha = 1.0;
|
|
||||||
|
|
||||||
in vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
out vec4 vFragColor;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 c = texture(sampler, vTexCoord);
|
|
||||||
c.a = min(Alpha, c.a);
|
gl_FragColor = texture2D(sampler, vTexCoord);
|
||||||
vFragColor = c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
)FS";
|
)FS";
|
||||||
|
@ -72,6 +64,7 @@ void compileProgram(ProgramPtr & result, const std::string& vs, const std::strin
|
||||||
result->Link();
|
result->Link();
|
||||||
} catch (ProgramBuildError & err) {
|
} catch (ProgramBuildError & err) {
|
||||||
Q_UNUSED(err);
|
Q_UNUSED(err);
|
||||||
|
qWarning() << err.Log().c_str();
|
||||||
Q_ASSERT_X(false, "compileProgram", "Failed to build shader program");
|
Q_ASSERT_X(false, "compileProgram", "Failed to build shader program");
|
||||||
qFatal((const char*)err.Message);
|
qFatal((const char*)err.Message);
|
||||||
result.reset();
|
result.reset();
|
||||||
|
@ -322,4 +315,3 @@ ShapeWrapperPtr loadSphereSection(ProgramPtr program, float fov, float aspect, i
|
||||||
new shapes::ShapeWrapper({ "Position", "TexCoord" }, SphereSection(fov, aspect, slices, stacks), *program)
|
new shapes::ShapeWrapper({ "Position", "TexCoord" }, SphereSection(fov, aspect, slices, stacks), *program)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
|
|
@ -12,17 +12,15 @@
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
#include "GLMHelpers.h"
|
#include "GLMHelpers.h"
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
|
||||||
#define OGLPLUS_USE_GLCOREARB_H 0
|
#define OGLPLUS_USE_GLCOREARB_H 0
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
#define OGLPLUS_USE_GL3_H 1
|
#define OGLPLUS_USE_GL3_H 1
|
||||||
|
|
||||||
#elif defined(WIN32)
|
#elif defined(Q_OS_WIN32)
|
||||||
|
|
||||||
|
#define OGLPLUS_USE_GLCOREARB_H 0
|
||||||
#define OGLPLUS_USE_GLEW 1
|
#define OGLPLUS_USE_GLEW 1
|
||||||
#pragma warning(disable : 4068)
|
#pragma warning(disable : 4068)
|
||||||
|
|
||||||
|
@ -170,4 +168,3 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
using BasicFramebufferWrapperPtr = std::shared_ptr<BasicFramebufferWrapper>;
|
using BasicFramebufferWrapperPtr = std::shared_ptr<BasicFramebufferWrapper>;
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue