Commit 49a608f4 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

minor gl convenience stuff

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19800 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 297099e8
......@@ -21,7 +21,7 @@ namespace ACG
FBO::FBO()
: fbo_(0), depthbuffer_(0), stencilbuffer_(0), width_(0), height_(0), samples_(0), fixedsamplelocation_(GL_TRUE), prevFbo_(0)
: fbo_(0), depthbuffer_(0), stencilbuffer_(0), width_(0), height_(0), samples_(0), fixedsamplelocation_(GL_TRUE), prevFbo_(0), prevDrawBuffer_(GL_NONE)
{
}
......@@ -276,6 +276,7 @@ bind()
{
// save previous fbo id
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint*)&prevFbo_);
glGetIntegerv(GL_DRAW_BUFFER, (GLint*)&prevDrawBuffer_);
if ( !fbo_ )
init();
......@@ -298,6 +299,7 @@ unbind()
{
//set to normal rendering
ACG::GLState::bindFramebuffer( GL_FRAMEBUFFER_EXT, prevFbo_ );
ACG::GLState::drawBuffer( prevDrawBuffer_ );
}
//-----------------------------------------------------------------------------
......
......@@ -145,6 +145,7 @@ private:
/// handle of previously bound fbo
GLuint prevFbo_;
GLuint prevDrawBuffer_;
};
......
......@@ -48,6 +48,7 @@
#include <cstring>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <QFile>
......@@ -59,6 +60,7 @@
#include <ACG/GL/GLError.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
namespace ACG
{
......@@ -462,7 +464,7 @@ GLSL::Program* ACG::ShaderCache::getComputeProgram(const char* _computeShaderFil
// If the shaders are equal, we return the cached entry
if (!compareShaderGenDescs(&it->first, &newEntry))
{
if ( timeCheck_ && !compareTimeStamp(&it->first, &newEntry))
if ( ( timeCheck_ && !compareTimeStamp(&it->first, &newEntry)) || !it->second)
oldCache = it;
else
return it->second;
......@@ -481,7 +483,7 @@ GLSL::Program* ACG::ShaderCache::getComputeProgram(const char* _computeShaderFil
}
GLSL::Program* prog = GLSL::loadComputeProgram(_computeShaderFile, &glslMacros, _verbose);
GLSL::Program* prog = GLSL::loadComputeProgram(newEntry.strVertexTemplate.toUtf8(), &glslMacros, _verbose);
glCheckErrors();
if (oldCache != cacheComputeShaders_.end())
......@@ -489,6 +491,41 @@ GLSL::Program* ACG::ShaderCache::getComputeProgram(const char* _computeShaderFil
if (!prog || !prog->isLinked())
{
delete prog;
// dump shader source including macros to debug output
if (!glslMacros.empty() && !dbgOutputDir_.isEmpty())
{
GLSL::StringList shaderSrc = GLSL::loadShader(newEntry.strVertexTemplate.toUtf8(), &glslMacros);
// compute FNV hash of macros
unsigned int fnv_prime = 16777619;
unsigned int fnv_hash = 2166136261;
for (GLSL::StringList::iterator it = shaderSrc.begin(); it != shaderSrc.end(); ++it)
{
for (size_t i = 0; i < it->length(); ++i)
{
fnv_hash *= fnv_prime;
fnv_hash ^= static_cast<unsigned char>((*it)[i]);
}
}
QString fnv_string;
fnv_string.sprintf("%X", fnv_hash);
QString dumpFilename = dbgOutputDir_ + QDir::separator() + fileInfo.fileName() + fnv_string;
std::ofstream dumpStream(dumpFilename.toStdString());
if (dumpStream.is_open())
{
for (GLSL::StringList::iterator it = shaderSrc.begin(); it != shaderSrc.end(); ++it)
dumpStream << *it;
dumpStream.close();
}
}
return oldCache->second;
}
else
......
......@@ -153,20 +153,23 @@ namespace GLSL {
return false;
}
glCompileShader(this->m_shaderId);
glCompileShader(m_shaderId);
GLint compileStatus;
glGetShaderiv(this->m_shaderId, GL_COMPILE_STATUS, &compileStatus);
glGetShaderiv(m_shaderId, GL_COMPILE_STATUS, &compileStatus);
if (compileStatus == GL_FALSE) {
if (verbose) {
GLchar *errorLog = new GLchar[GLSL_MAX_LOGSIZE];
GLsizei errorLength;
char shaderSource[32768];
glGetShaderSource(this->m_shaderId, 32768, &errorLength, shaderSource);
GLsizei errorLength, srcLength;
glGetShaderiv(m_shaderId, GL_SHADER_SOURCE_LENGTH, &srcLength);
GLchar* shaderSource = new GLchar[srcLength];
glGetShaderSource(m_shaderId, srcLength, &errorLength, shaderSource);
std::cout << "shader source: " << std::endl << shaderSource << std::endl;
glGetShaderInfoLog(this->m_shaderId, GLSL_MAX_LOGSIZE, &errorLength, errorLog);
glGetShaderInfoLog(m_shaderId, GLSL_MAX_LOGSIZE, &errorLength, errorLog);
std::cout << "GLSL compile error:" << std::endl << errorLog << std::endl;
delete[] shaderSource;
delete[] errorLog;
}
......@@ -218,6 +221,10 @@ namespace GLSL {
// Compute shader
//--------------------------------------------------------------------------
ComputeShader::Caps ComputeShader::caps_;
bool ComputeShader::capsInitialized_ = false;
ComputeShader::ComputeShader() : Shader(
#ifdef GL_ARB_compute_shader
GL_COMPUTE_SHADER
......@@ -227,6 +234,32 @@ namespace GLSL {
) {}
ComputeShader::~ComputeShader() {}
const ComputeShader::Caps& ComputeShader::caps() {
if (!capsInitialized_) {
capsInitialized_ = true;
#ifdef GL_ARB_compute_shader
glGetIntegerv(GL_MAX_COMPUTE_UNIFORM_BLOCKS, &caps_.maxUniformBlocks_);
glGetIntegerv(GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS, &caps_.maxTextureImageUnits_);
glGetIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &caps_.maxImageUniforms_);
glGetIntegerv(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE, &caps_.maxSharedMemorySize_);
glGetIntegerv(GL_MAX_COMPUTE_UNIFORM_COMPONENTS, &caps_.maxUniformComponents_);
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS, &caps_.maxAtomicCounterBufs_);
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTERS, &caps_.maxAtomicCounters_);
glGetIntegerv(GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS, &caps_.maxCombinedUniformComponents_);
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &caps_.maxWorkGroupInvocations_);
for (int i = 0; i < 3; ++i) {
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, caps_.maxWorkGroupCount_ + i);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, caps_.maxWorkGroupSize_ + i);
}
#else
memset(&caps_, 0, sizeof(caps_));
#endif
}
return caps_;
}
//--------------------------------------------------------------------------
// Shader program object
//--------------------------------------------------------------------------
......
......@@ -171,6 +171,30 @@ namespace GLSL {
public:
ComputeShader();
virtual ~ComputeShader();
// get hw caps
struct Caps
{
int maxUniformBlocks_;
int maxTextureImageUnits_;
int maxImageUniforms_;
int maxSharedMemorySize_;
int maxUniformComponents_;
int maxAtomicCounterBufs_;
int maxAtomicCounters_;
int maxCombinedUniformComponents_;
int maxWorkGroupInvocations_;
int maxWorkGroupCount_[3];
int maxWorkGroupSize_[3];
};
static const Caps& caps();
private:
static Caps caps_;
static bool capsInitialized_;
};
typedef ComputeShader* PtrComputeShader;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment