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