Merge remote-tracking branch 'tmj/master' into sim

This commit is contained in:
milek7
2020-10-18 23:35:14 +02:00
244 changed files with 54164 additions and 11636 deletions

View File

@@ -39,6 +39,8 @@ void gl::buffer::bind_base(targets target, GLuint index)
void gl::buffer::unbind(targets target)
{
if( binding_points[ target ] == 0 ) { return; }
glBindBuffer(glenum_target(target), 0);
binding_points[target] = 0;
}

View File

@@ -1,6 +1,9 @@
#include "stdafx.h"
#include "framebuffer.h"
#include "Logs.h"
#include "utilities.h"
gl::framebuffer::framebuffer()
{
glGenFramebuffers(1, *this);
@@ -22,6 +25,12 @@ void gl::framebuffer::attach(const opengl_texture &tex, GLenum location)
glFramebufferTexture2D(GL_FRAMEBUFFER, location, tex.target, tex.id, 0);
}
void gl::framebuffer::attach(const opengl_texture &tex, GLenum location, GLint layer)
{
bind();
glFramebufferTextureLayer(GL_FRAMEBUFFER, location, tex.id, 0, layer);
}
void gl::framebuffer::attach(const cubemap &tex, int face, GLenum location)
{
bind();
@@ -43,8 +52,14 @@ void gl::framebuffer::detach(GLenum location)
bool gl::framebuffer::is_complete()
{
bind();
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
return status == GL_FRAMEBUFFER_COMPLETE;
GLenum const status { glCheckFramebufferStatus( GL_FRAMEBUFFER ) };
auto const iscomplete { status == GL_FRAMEBUFFER_COMPLETE };
if( false == iscomplete ) {
ErrorLog( "framebuffer status: error " + to_hex_str( status ) );
}
return iscomplete;
}
void gl::framebuffer::clear(GLbitfield mask)

View File

@@ -15,6 +15,7 @@ namespace gl
~framebuffer();
void attach(const opengl_texture &tex, GLenum location);
void attach( const opengl_texture &tex, GLenum location, GLint layer );
void attach(const cubemap &tex, int face, GLenum location);
void attach(const renderbuffer &rb, GLenum location);
void setup_drawing(int attachments);

View File

@@ -12,12 +12,14 @@ void gl::glsl_common_setup()
"#define POSTFX_ENABLED " + std::to_string((int)!Global.gfx_skippipeline) + "\n" +
"#define EXTRAEFFECTS_ENABLED " + std::to_string((int)Global.gfx_extraeffects) + "\n" +
"#define USE_GLES " + std::to_string((int)Global.gfx_usegles) + "\n" +
"const uint MAX_LIGHTS = " + std::to_string(MAX_LIGHTS) + "U;\n" +
"const uint MAX_PARAMS = " + std::to_string(MAX_PARAMS) + "U;\n" +
"#define MAX_LIGHTS " + std::to_string(MAX_LIGHTS) + "U\n" +
"#define MAX_CASCADES " + std::to_string(MAX_CASCADES) + "U\n" +
"#define MAX_PARAMS " + std::to_string(MAX_PARAMS) + "U\n" +
R"STRING(
const uint LIGHT_SPOT = 0U;
const uint LIGHT_POINT = 1U;
const uint LIGHT_DIR = 2U;
const uint LIGHT_HEADLIGHTS = 3U;
struct light_s
{
@@ -35,6 +37,9 @@ void gl::glsl_common_setup()
float intensity;
float ambient;
mat4 headlight_projection;
vec4 headlight_weights;
};
layout(std140) uniform light_ubo
@@ -58,13 +63,15 @@ void gl::glsl_common_setup()
float emission;
float fog_density;
float alpha_mult;
float shadow_tone;
};
layout (std140) uniform scene_ubo
{
mat4 projection;
mat4 lightview;
vec3 scene_extra;
mat4 inv_view;
mat4 lightview[MAX_CASCADES];
vec4 cascade_end;
float time;
};

View File

@@ -34,7 +34,8 @@ void gl::query::end()
std::optional<int64_t> gl::query::result()
{
GLuint ready;
end(); // intercept potential error if the result check is called for still active object
GLuint ready;
glGetQueryObjectuiv(*this, GL_QUERY_RESULT_AVAILABLE, &ready);
int64_t value = 0;
if (ready) {

View File

@@ -69,7 +69,8 @@ std::unordered_map<std::string, gl::shader::defaultparam_e> gl::shader::defaultp
{ "one", defaultparam_e::one },
{ "ambient", defaultparam_e::ambient },
{ "diffuse", defaultparam_e::diffuse },
{ "specular", defaultparam_e::specular }
{ "specular", defaultparam_e::specular },
{ "glossiness", defaultparam_e::glossiness }
};
void gl::shader::process_source(std::string &str)
@@ -251,6 +252,7 @@ gl::shader::shader(const std::string &filename)
GLchar info[512];
glGetShaderInfoLog(*this, 512, 0, info);
std::cerr << std::string(info) << std::endl;
throw shader_exception("failed to compile " + filename + ": " + std::string(info));
}
}
@@ -271,8 +273,9 @@ void gl::program::init()
glUniform1i(loc, e.id);
}
glUniform1i(glGetUniformLocation(*this, "shadowmap"), MAX_TEXTURES + 0);
glUniform1i(glGetUniformLocation(*this, "envmap"), MAX_TEXTURES + 1);
glUniform1i(glGetUniformLocation(*this, "shadowmap"), gl::SHADOW_TEX);
glUniform1i(glGetUniformLocation(*this, "envmap"), gl::ENV_TEX);
glUniform1i(glGetUniformLocation(*this, "headlightmap"), gl::HEADLIGHT_TEX);
GLuint index;

View File

@@ -44,7 +44,8 @@ namespace gl
one,
ambient,
diffuse,
specular
specular,
glossiness
};
struct param_entry

View File

@@ -32,16 +32,22 @@ namespace gl
const size_t MAX_TEXTURES = 8;
const size_t ENVMAP_SIZE = 1024;
const size_t MAX_CASCADES = 3;
const size_t HELPER_TEXTURES = 4;
const size_t SHADOW_TEX = MAX_TEXTURES + 0;
const size_t ENV_TEX = MAX_TEXTURES + 1;
const size_t HEADLIGHT_TEX = MAX_TEXTURES + 2;
struct scene_ubs
{
glm::mat4 projection;
glm::mat4 lightview;
glm::vec3 scene_extra;
glm::mat4 inv_view;
glm::mat4 lightview[MAX_CASCADES];
glm::vec4 cascade_end;
float time;
};
static_assert(sizeof(scene_ubs) == 144, "bad size of ubs");
static_assert(sizeof(scene_ubs) == 340, "bad size of ubs");
const size_t MAX_PARAMS = 3;
@@ -56,6 +62,7 @@ namespace gl
float emission;
float fog_density;
float alpha_mult;
float shadow_tone;
UBS_PAD(4);
void set_modelview(const glm::mat4 &mv)
@@ -65,7 +72,7 @@ namespace gl
}
};
static_assert(sizeof(model_ubs) == 196 + 16 * MAX_PARAMS, "bad size of ubs");
static_assert(sizeof(model_ubs) == 200 + 16 * MAX_PARAMS, "bad size of ubs");
struct light_element_ubs
{
@@ -73,7 +80,8 @@ namespace gl
{
SPOT = 0,
POINT,
DIR
DIR,
HEADLIGHTS
};
glm::vec3 pos;
@@ -90,9 +98,12 @@ namespace gl
float intensity;
float ambient;
glm::mat4 headlight_projection;
glm::vec4 headlight_weights;
};
static_assert(sizeof(light_element_ubs) == 64, "bad size of ubs");
static_assert(sizeof(light_element_ubs) == 144, "bad size of ubs");
const size_t MAX_LIGHTS = 8;