mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-22 23:24:56 +02:00
Testing the gpu::Shader compilation and building steps, ready to be used for real
This commit is contained in:
parent
660d9237e6
commit
cb737d64d3
5 changed files with 78 additions and 75 deletions
|
@ -1015,11 +1015,11 @@ GLBackend::GLBuffer::~GLBuffer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::syncGPUObject(const Buffer& buffer) {
|
GLBackend::GLBuffer* GLBackend::syncGPUObject(const Buffer& buffer) {
|
||||||
GLBuffer* object = Backend::getGPUObject<GLBackend::GLBuffer>(buffer);
|
GLBuffer* object = Backend::getGPUObject<GLBackend::GLBuffer>(buffer);
|
||||||
|
|
||||||
if (object && (object->_stamp == buffer.getSysmem().getStamp())) {
|
if (object && (object->_stamp == buffer.getSysmem().getStamp())) {
|
||||||
return;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to have a gpu object?
|
// need to have a gpu object?
|
||||||
|
@ -1040,12 +1040,18 @@ void GLBackend::syncGPUObject(const Buffer& buffer) {
|
||||||
object->_size = buffer.getSysmem().getSize();
|
object->_size = buffer.getSysmem().getSize();
|
||||||
//}
|
//}
|
||||||
CHECK_GL_ERROR();
|
CHECK_GL_ERROR();
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLuint GLBackend::getBufferID(const Buffer& buffer) {
|
GLuint GLBackend::getBufferID(const Buffer& buffer) {
|
||||||
GLBackend::syncGPUObject(buffer);
|
GLBuffer* bo = GLBackend::syncGPUObject(buffer);
|
||||||
return Backend::getGPUObject<GLBackend::GLBuffer>(buffer)->_buffer;
|
if (bo) {
|
||||||
|
return bo->_buffer;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
GLBuffer();
|
GLBuffer();
|
||||||
~GLBuffer();
|
~GLBuffer();
|
||||||
};
|
};
|
||||||
static void syncGPUObject(const Buffer& buffer);
|
static GLBuffer* syncGPUObject(const Buffer& buffer);
|
||||||
static GLuint getBufferID(const Buffer& buffer);
|
static GLuint getBufferID(const Buffer& buffer);
|
||||||
|
|
||||||
class GLTexture : public GPUObject {
|
class GLTexture : public GPUObject {
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
GLTexture();
|
GLTexture();
|
||||||
~GLTexture();
|
~GLTexture();
|
||||||
};
|
};
|
||||||
static void syncGPUObject(const Texture& texture);
|
static GLTexture* syncGPUObject(const Texture& texture);
|
||||||
static GLuint getTextureID(const TexturePointer& texture);
|
static GLuint getTextureID(const TexturePointer& texture);
|
||||||
|
|
||||||
class GLShader : public GPUObject {
|
class GLShader : public GPUObject {
|
||||||
|
|
|
@ -25,12 +25,12 @@ GLBackend::GLShader::~GLShader() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compileShader(const Shader& shader, GLBackend::GLShader& object) {
|
GLBackend::GLShader* compileShader(const Shader& shader) {
|
||||||
// Any GLSLprogram ? normally yes...
|
// Any GLSLprogram ? normally yes...
|
||||||
const std::string& shaderSource = shader.getSource().getCode();
|
const std::string& shaderSource = shader.getSource().getCode();
|
||||||
if (shaderSource.empty()) {
|
if (shaderSource.empty()) {
|
||||||
qDebug() << "GLShader::compileShader - no GLSL shader source code ? so failed to create";
|
qDebug() << "GLShader::compileShader - no GLSL shader source code ? so failed to create";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shader domain
|
// Shader domain
|
||||||
|
@ -40,8 +40,8 @@ bool compileShader(const Shader& shader, GLBackend::GLShader& object) {
|
||||||
// Create the shader object
|
// Create the shader object
|
||||||
GLuint glshader = glCreateShader(shaderDomain);
|
GLuint glshader = glCreateShader(shaderDomain);
|
||||||
if (!glshader) {
|
if (!glshader) {
|
||||||
qDebug() << "GLShader::compileShader - failed to create the gl shader & gl program object";
|
qDebug() << "GLShader::compileShader - failed to create the gl shader object";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the source
|
// Assign the source
|
||||||
|
@ -56,13 +56,11 @@ bool compileShader(const Shader& shader, GLBackend::GLShader& object) {
|
||||||
glGetShaderiv(glshader, GL_COMPILE_STATUS, &compiled);
|
glGetShaderiv(glshader, GL_COMPILE_STATUS, &compiled);
|
||||||
|
|
||||||
// if compilation fails
|
// if compilation fails
|
||||||
if (!compiled)
|
if (!compiled) {
|
||||||
{
|
|
||||||
// save the source code to a temp file so we can debug easily
|
// save the source code to a temp file so we can debug easily
|
||||||
/* std::ofstream filestream;
|
/* std::ofstream filestream;
|
||||||
filestream.open( "debugshader.glsl" );
|
filestream.open("debugshader.glsl");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
|
||||||
filestream << shaderSource->source;
|
filestream << shaderSource->source;
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
|
@ -72,30 +70,31 @@ bool compileShader(const Shader& shader, GLBackend::GLShader& object) {
|
||||||
glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength);
|
glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength);
|
||||||
|
|
||||||
char* temp = new char[infoLength] ;
|
char* temp = new char[infoLength] ;
|
||||||
glGetShaderInfoLog( glshader, infoLength, NULL, temp);
|
glGetShaderInfoLog(glshader, infoLength, NULL, temp);
|
||||||
|
|
||||||
qDebug() << "GLShader::compileShader - failed to compile the gl shader object:";
|
qDebug() << "GLShader::compileShader - failed to compile the gl shader object:";
|
||||||
qDebug() << temp;
|
qDebug() << temp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
filestream.open( "debugshader.glsl.info.txt" );
|
filestream.open("debugshader.glsl.info.txt");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
filestream << std::string(temp);
|
||||||
filestream << String( temp );
|
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
|
|
||||||
glDeleteShader( glshader);
|
glDeleteShader(glshader);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint glprogram = 0;
|
||||||
|
#ifdef SEPARATE_PROGRAM
|
||||||
// so far so good, program is almost done, need to link:
|
// so far so good, program is almost done, need to link:
|
||||||
GLuint glprogram = glCreateProgram();
|
GLuint glprogram = glCreateProgram();
|
||||||
if (!glprogram) {
|
if (!glprogram) {
|
||||||
qDebug() << "GLShader::compileShader - failed to create the gl shader & gl program object";
|
qDebug() << "GLShader::compileShader - failed to create the gl shader & gl program object";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
glProgramParameteri(glprogram, GL_PROGRAM_SEPARABLE, GL_TRUE);
|
glProgramParameteri(glprogram, GL_PROGRAM_SEPARABLE, GL_TRUE);
|
||||||
|
@ -105,53 +104,52 @@ bool compileShader(const Shader& shader, GLBackend::GLShader& object) {
|
||||||
GLint linked = 0;
|
GLint linked = 0;
|
||||||
glGetProgramiv(glprogram, GL_LINK_STATUS, &linked);
|
glGetProgramiv(glprogram, GL_LINK_STATUS, &linked);
|
||||||
|
|
||||||
if (!linked)
|
if (!linked) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
// save the source code to a temp file so we can debug easily
|
// save the source code to a temp file so we can debug easily
|
||||||
std::ofstream filestream;
|
std::ofstream filestream;
|
||||||
filestream.open( "debugshader.glsl" );
|
filestream.open("debugshader.glsl");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
|
||||||
filestream << shaderSource->source;
|
filestream << shaderSource->source;
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLint infoLength = 0;
|
GLint infoLength = 0;
|
||||||
glGetProgramiv( glprogram, GL_INFO_LOG_LENGTH, &infoLength );
|
glGetProgramiv(glprogram, GL_INFO_LOG_LENGTH, &infoLength);
|
||||||
|
|
||||||
char* temp = new char[infoLength] ;
|
char* temp = new char[infoLength] ;
|
||||||
glGetProgramInfoLog( glprogram, infoLength, NULL, temp);
|
glGetProgramInfoLog(glprogram, infoLength, NULL, temp);
|
||||||
|
|
||||||
qDebug() << "GLShader::compileShader - failed to LINK the gl program object :";
|
qDebug() << "GLShader::compileShader - failed to LINK the gl program object :";
|
||||||
qDebug() << temp;
|
qDebug() << temp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
filestream.open( "debugshader.glsl.info.txt" );
|
filestream.open("debugshader.glsl.info.txt");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
filestream << String(temp);
|
||||||
filestream << String( temp );
|
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
|
|
||||||
glDeleteShader( glshader);
|
glDeleteShader(glshader);
|
||||||
glDeleteProgram( glprogram);
|
glDeleteProgram(glprogram);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// So far so good, the shader is created successfully
|
// So far so good, the shader is created successfully
|
||||||
object._shader = glshader;
|
GLBackend::GLShader* object = new GLBackend::GLShader();
|
||||||
object._program = glprogram;
|
object->_shader = glshader;
|
||||||
|
object->_program = glprogram;
|
||||||
|
|
||||||
return true;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compileProgram(const Shader& program, GLBackend::GLShader& object) {
|
GLBackend::GLShader* compileProgram(const Shader& program) {
|
||||||
if(!program.isProgram()) {
|
if(!program.isProgram()) {
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's go through every shaders and make sure they are ready to go
|
// Let's go through every shaders and make sure they are ready to go
|
||||||
|
@ -160,7 +158,7 @@ bool compileProgram(const Shader& program, GLBackend::GLShader& object) {
|
||||||
GLuint so = GLBackend::getShaderID(subShader);
|
GLuint so = GLBackend::getShaderID(subShader);
|
||||||
if (!so) {
|
if (!so) {
|
||||||
qDebug() << "GLShader::compileProgram - One of the shaders of the program is not compiled?";
|
qDebug() << "GLShader::compileProgram - One of the shaders of the program is not compiled?";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
shaderObjects.push_back(so);
|
shaderObjects.push_back(so);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +167,7 @@ bool compileProgram(const Shader& program, GLBackend::GLShader& object) {
|
||||||
GLuint glprogram = glCreateProgram();
|
GLuint glprogram = glCreateProgram();
|
||||||
if (!glprogram) {
|
if (!glprogram) {
|
||||||
qDebug() << "GLShader::compileProgram - failed to create the gl program object";
|
qDebug() << "GLShader::compileProgram - failed to create the gl program object";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// glProgramParameteri(glprogram, GL_PROGRAM_, GL_TRUE);
|
// glProgramParameteri(glprogram, GL_PROGRAM_, GL_TRUE);
|
||||||
|
@ -184,47 +182,45 @@ bool compileProgram(const Shader& program, GLBackend::GLShader& object) {
|
||||||
GLint linked = 0;
|
GLint linked = 0;
|
||||||
glGetProgramiv(glprogram, GL_LINK_STATUS, &linked);
|
glGetProgramiv(glprogram, GL_LINK_STATUS, &linked);
|
||||||
|
|
||||||
if (!linked)
|
if (!linked) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
// save the source code to a temp file so we can debug easily
|
// save the source code to a temp file so we can debug easily
|
||||||
std::ofstream filestream;
|
std::ofstream filestream;
|
||||||
filestream.open( "debugshader.glsl" );
|
filestream.open("debugshader.glsl");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
|
||||||
filestream << shaderSource->source;
|
filestream << shaderSource->source;
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLint infoLength = 0;
|
GLint infoLength = 0;
|
||||||
glGetProgramiv( glprogram, GL_INFO_LOG_LENGTH, &infoLength );
|
glGetProgramiv(glprogram, GL_INFO_LOG_LENGTH, &infoLength);
|
||||||
|
|
||||||
char* temp = new char[infoLength] ;
|
char* temp = new char[infoLength] ;
|
||||||
glGetProgramInfoLog( glprogram, infoLength, NULL, temp);
|
glGetProgramInfoLog(glprogram, infoLength, NULL, temp);
|
||||||
|
|
||||||
qDebug() << "GLShader::compileProgram - failed to LINK the gl program object :";
|
qDebug() << "GLShader::compileProgram - failed to LINK the gl program object :";
|
||||||
qDebug() << temp;
|
qDebug() << temp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
filestream.open( "debugshader.glsl.info.txt" );
|
filestream.open("debugshader.glsl.info.txt");
|
||||||
if ( filestream.is_open() )
|
if (filestream.is_open()) {
|
||||||
{
|
filestream << std::string(temp);
|
||||||
filestream << String( temp );
|
|
||||||
filestream.close();
|
filestream.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
|
|
||||||
glDeleteProgram( glprogram);
|
glDeleteProgram(glprogram);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// So far so good, the program is created successfully
|
// So far so good, the program is created successfully
|
||||||
object._shader = 0;
|
GLBackend::GLShader* object = new GLBackend::GLShader();
|
||||||
object._program = glprogram;
|
object->_shader = 0;
|
||||||
|
object->_program = glprogram;
|
||||||
|
|
||||||
return true;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLBackend::GLShader* GLBackend::syncGPUObject(const Shader& shader) {
|
GLBackend::GLShader* GLBackend::syncGPUObject(const Shader& shader) {
|
||||||
|
@ -234,20 +230,17 @@ GLBackend::GLShader* GLBackend::syncGPUObject(const Shader& shader) {
|
||||||
if (object) {
|
if (object) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to have a gpu object?
|
// need to have a gpu object?
|
||||||
|
|
||||||
// GO through the process of allocating the correct storage and/or update the content
|
|
||||||
if (shader.isProgram()) {
|
if (shader.isProgram()) {
|
||||||
GLShader tempObject;
|
GLShader* tempObject = compileProgram(shader);
|
||||||
if (compileProgram(shader, tempObject)) {
|
if (tempObject) {
|
||||||
object = new GLShader(tempObject);
|
object = tempObject;
|
||||||
Backend::setGPUObject(shader, object);
|
Backend::setGPUObject(shader, object);
|
||||||
}
|
}
|
||||||
} else if (shader.isDomain()) {
|
} else if (shader.isDomain()) {
|
||||||
GLShader tempObject;
|
GLShader* tempObject = compileShader(shader);
|
||||||
if (compileShader(shader, tempObject)) {
|
if (tempObject) {
|
||||||
object = new GLShader(tempObject);
|
object = tempObject;
|
||||||
Backend::setGPUObject(shader, object);
|
Backend::setGPUObject(shader, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +249,6 @@ GLBackend::GLShader* GLBackend::syncGPUObject(const Shader& shader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLuint GLBackend::getShaderID(const ShaderPointer& shader) {
|
GLuint GLBackend::getShaderID(const ShaderPointer& shader) {
|
||||||
if (!shader) {
|
if (!shader) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -223,7 +223,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void GLBackend::syncGPUObject(const Texture& texture) {
|
GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
GLTexture* object = Backend::getGPUObject<GLBackend::GLTexture>(texture);
|
GLTexture* object = Backend::getGPUObject<GLBackend::GLTexture>(texture);
|
||||||
|
|
||||||
// If GPU object already created and in sync
|
// If GPU object already created and in sync
|
||||||
|
@ -232,14 +232,14 @@ void GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
// If gpu object info is in sync with sysmem version
|
// If gpu object info is in sync with sysmem version
|
||||||
if (object->_contentStamp >= texture.getDataStamp()) {
|
if (object->_contentStamp >= texture.getDataStamp()) {
|
||||||
// Then all good, GPU object is ready to be used
|
// Then all good, GPU object is ready to be used
|
||||||
return;
|
return object;
|
||||||
} else {
|
} else {
|
||||||
// Need to update the content of the GPU object from the source sysmem of the texture
|
// Need to update the content of the GPU object from the source sysmem of the texture
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
} else if (!texture.isDefined()) {
|
} else if (!texture.isDefined()) {
|
||||||
// NO texture definition yet so let's avoid thinking
|
// NO texture definition yet so let's avoid thinking
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to have a gpu object?
|
// need to have a gpu object?
|
||||||
|
@ -320,6 +320,8 @@ void GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
qDebug() << "GLBackend::syncGPUObject(const Texture&) case for Texture Type " << texture.getType() << " not supported";
|
qDebug() << "GLBackend::syncGPUObject(const Texture&) case for Texture Type " << texture.getType() << " not supported";
|
||||||
}
|
}
|
||||||
CHECK_GL_ERROR();
|
CHECK_GL_ERROR();
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,8 +330,7 @@ GLuint GLBackend::getTextureID(const TexturePointer& texture) {
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
GLBackend::syncGPUObject(*texture);
|
GLTexture* object = GLBackend::syncGPUObject(*texture);
|
||||||
GLTexture* object = Backend::getGPUObject<GLBackend::GLTexture>(*texture);
|
|
||||||
if (object) {
|
if (object) {
|
||||||
return object->_texture;
|
return object->_texture;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "SkyFromAtmosphere_vert.h"
|
#include "SkyFromAtmosphere_vert.h"
|
||||||
#include "SkyFromAtmosphere_frag.h"
|
#include "SkyFromAtmosphere_frag.h"
|
||||||
|
#include "gpu/GLBackend.h"
|
||||||
|
|
||||||
using namespace model;
|
using namespace model;
|
||||||
|
|
||||||
|
@ -215,5 +216,8 @@ void SunSkyStage::updateGraphicsObject() const {
|
||||||
double originAlt = _earthSunModel.getAltitude();
|
double originAlt = _earthSunModel.getAltitude();
|
||||||
_sunLight->setPosition(Vec3(0.0f, originAlt, 0.0f));
|
_sunLight->setPosition(Vec3(0.0f, originAlt, 0.0f));
|
||||||
|
|
||||||
|
GLuint program = gpu::GLBackend::getShaderID(_skyShader);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue