50 #include <ACG/GL/acg_glew.hh>
51 #include <ACG/GL/globjects.hh>
52 #include <ACG/GL/GLFormatInfo.hh>
53 #include <ACG/ShaderUtils/GLSLShader.hh>
63 Texture::Texture( GLenum tgt, GLenum _unit )
64 : target(tgt), unit(_unit), valid(false), texture(0u), internalFormat_(0)
68 void Texture::bindAsImage(GLuint _index, GLenum _access)
70 #if defined(GL_ARB_shader_image_load_store)
72 glBindImageTexture(_index,
id(), 0, GL_FALSE, 0, _access, getInternalFormat());
74 std::cerr <<
"Texture::bindAsImage - error: texture not initialized!" << std::endl;
76 std::cerr <<
"Texture::bindAsImage - glBindImageTexture symbol not loaded!" << std::endl;
81 GLint Texture::getInternalFormat()
86 glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat_);
89 return internalFormat_;
128 bool Texture::clear(
const ACG::Vec4f& _color )
130 #ifdef GL_ARB_clear_texture
131 if (supportsClearTexture() && texture)
133 glClearTexImage(texture, 0, GL_RGBA, GL_FLOAT, _color.data());
142 #ifdef GL_ARB_clear_texture
143 if (supportsClearTexture() && texture)
145 glClearTexImage(texture, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, _color.data());
152 bool Texture::clear(
const ACG::Vec4i& _color )
154 #ifdef GL_ARB_clear_texture
155 if (supportsClearTexture() && texture)
157 glClearTexImage(texture, 0, GL_RGBA_INTEGER, GL_INT, _color.data());
164 bool Texture::supportsImageLoadStore()
166 static int status = -1;
170 #if defined(GL_ARB_shader_image_load_store)
183 bool Texture::supportsTextureBuffer()
185 static int status = -1;
189 #if defined(GL_ARB_texture_buffer_object)
202 bool Texture::supportsClearTexture()
204 static int status = -1;
208 #if defined(GL_ARB_clear_texture)
219 bool Texture::supportsGenerateMipmap()
221 static int status = -1;
225 #if defined(GL_SGIS_generate_mipmap)
239 Texture1D::Texture1D( GLenum unit ) :
Texture(GL_TEXTURE_1D, unit),
244 void Texture1D::setData(GLint _level,
245 GLint _internalFormat,
249 const GLvoid* _data) {
253 glTexImage1D(GL_TEXTURE_1D, _level, _internalFormat, _width, 0, _format, _type, _data);
256 internalFormat_ = _internalFormat;
262 void Texture1D::setStorage( GLsizei _levels, GLenum _internalFormat, GLsizei _width ) {
263 #ifdef GL_ARB_texture_storage
265 glTexStorage1D(GL_TEXTURE_1D, _levels, _internalFormat, _width);
268 internalFormat_ = _internalFormat;
270 GLFormatInfo finfo(_internalFormat);
271 format_ = finfo.format();
272 type_ = finfo.type();
273 #endif // GL_ARB_texture_storage
277 bool Texture1D::getData( GLint _level,
void* _dst ) {
280 glGetIntegerv(GL_TEXTURE_BINDING_1D, &curTex);
283 glGetTexImage(GL_TEXTURE_1D, _level, format_, type_, _dst);
285 glBindTexture(GL_TEXTURE_1D, curTex);
292 bool Texture1D::getData( GLint _level, std::vector<char>& _dst ) {
295 GLFormatInfo finfo(internalFormat_);
297 if (finfo.isValid()) {
298 size_t bufSize = finfo.elemSize() * width_;
300 if (_dst.size() < bufSize)
301 _dst.resize(bufSize);
304 return getData(_level, &_dst[0]);
316 Texture2D::Texture2D(GLenum unit)
317 :
Texture(GL_TEXTURE_2D, unit),
318 width_(0), height_(0),
319 format_(0), type_(0),
325 bool Texture2D::autogenerateMipMaps()
327 #ifdef GL_SGIS_generate_mipmap
328 if (supportsGenerateMipmap())
330 parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
335 buildMipsCPU_ =
true;
341 void Texture2D::disableAutogenerateMipMaps()
343 #ifdef GL_SGIS_generate_mipmap
344 if (supportsGenerateMipmap())
345 parameter(GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
347 buildMipsCPU_ =
false;
352 void Texture2D::setData(GLint _level,
353 GLint _internalFormat,
358 const GLvoid* _data) {
360 if (getUnit() == GL_NONE)
361 setUnit(GL_TEXTURE0);
365 if (buildMipsCPU_ && _level == 0)
366 buildMipMaps(_internalFormat, _width, _height, _format, _type, _data);
368 glTexImage2D(GL_TEXTURE_2D, _level, _internalFormat, _width, _height, 0, _format, _type, _data);
372 internalFormat_ = _internalFormat;
378 void Texture2D::setStorage( GLsizei _levels, GLenum _internalFormat, GLsizei _width, GLsizei _height ) {
379 #ifdef GL_ARB_texture_storage
381 glTexStorage2D(GL_TEXTURE_2D, _levels, _internalFormat, _width, _height);
385 internalFormat_ = _internalFormat;
387 GLFormatInfo finfo(_internalFormat);
388 format_ = finfo.format();
389 type_ = finfo.type();
390 #endif // GL_ARB_texture_storage
394 bool Texture2D::getData( GLint _level,
void* _dst ) {
397 glGetIntegerv(GL_TEXTURE_BINDING_2D, &curTex);
400 glGetTexImage(GL_TEXTURE_2D, _level, format_, type_, _dst);
402 glBindTexture(GL_TEXTURE_2D, curTex);
409 bool Texture2D::getData( GLint _level, std::vector<char>& _dst ) {
412 GLFormatInfo finfo(internalFormat_);
414 if (finfo.isValid()) {
415 size_t bufSize = finfo.elemSize() * width_ * height_;
417 if (_dst.size() < bufSize)
418 _dst.resize(bufSize);
421 return getData(_level, &_dst[0]);
428 void Texture2D_buildMipMaps_DataInterpreter(
Vec4f* _dst,
int _numChannels,
int _srcOffset,
const void* _src)
430 const T* dataT =
static_cast<const T*
>(_src);
432 for (
int i = 0; i < _numChannels; ++i)
433 (*_dst)[i] = float(dataT[_srcOffset + i]);
436 void Texture2D::buildMipMaps( GLenum _internalfmt,
448 GLFormatInfo finfo(_internalfmt);
450 if (finfo.isValid() && (finfo.isFloat() || finfo.isNormalized()))
452 int numChannels = finfo.channelCount();
463 std::vector<int> mipMemsize(1, 0);
464 std::vector<Vec2i> mipSize(1, curSize);
466 mipMemsize.reserve(16);
472 while (curSize[0] > 1 || curSize[1] > 1)
474 for (
int k = 0; k < 2; ++k)
475 curSize[k] = std::max(1, curSize[k] >> 1);
478 mipSize.push_back(curSize);
481 int numPixels = curSize[0] * curSize[1];
482 mipMemsize.push_back(numPixels * numChannels * 4);
488 std::vector<int> mipOffset;
489 mipOffset.reserve(16);
490 int totalMemSize = 0;
491 for (
int mipID = 0; mipID < numMips; ++mipID)
493 mipOffset.push_back(totalMemSize);
494 totalMemSize += mipMemsize[mipID];
499 std::vector<float> mipData(totalMemSize / 4);
502 for (
int mipID = 1; mipID < numMips; ++mipID)
504 Vec2i srcSize = mipSize[mipID-1];
505 Vec2i dstSize = mipSize[mipID];
507 int srcOffset = mipOffset[mipID-1];
508 int dstOffset = mipOffset[mipID];
510 int dstNumPixels = dstSize[0] * dstSize[1];
516 for (
int dstPixel = 0; dstPixel < dstNumPixels; ++dstPixel)
518 int x = dstPixel % dstSize[0];
519 int y = dstPixel / dstSize[0];
523 Vec2i srcPixelPos[4] =
526 Vec2i(x * 2, y * 2 + 1),
Vec2i(x * 2 + 1, y * 2 + 1)
529 Vec4f avgColor =
Vec4f(0.0f, 0.0f, 0.0f, 0.0f);
532 for (
int srcPixel = 0; srcPixel < 4; ++srcPixel)
535 pixelData[srcPixel] =
Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
538 srcPixelPos[srcPixel][0] = std::min(srcPixelPos[srcPixel][0], srcSize[0] - 1);
539 srcPixelPos[srcPixel][1] = std::min(srcPixelPos[srcPixel][1], srcSize[1] - 1);
542 int srcPixelPosLinear = srcSize[0] * srcPixelPos[srcPixel][1] + srcPixelPos[srcPixel][0];
549 case GL_DOUBLE: Texture2D_buildMipMaps_DataInterpreter<double>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
550 case GL_FLOAT: Texture2D_buildMipMaps_DataInterpreter<float>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
551 case GL_INT: Texture2D_buildMipMaps_DataInterpreter<int>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
552 case GL_UNSIGNED_INT: Texture2D_buildMipMaps_DataInterpreter<unsigned int>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
553 case GL_SHORT: Texture2D_buildMipMaps_DataInterpreter<short>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
554 case GL_UNSIGNED_SHORT: Texture2D_buildMipMaps_DataInterpreter<unsigned short>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
break;
557 Texture2D_buildMipMaps_DataInterpreter<char>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
559 if (finfo.isNormalized())
560 pixelData[srcPixel] /= 127.0f;
562 case GL_UNSIGNED_BYTE:
564 Texture2D_buildMipMaps_DataInterpreter<unsigned char>(pixelData + srcPixel, numChannels, srcPixelPosLinear * numChannels, _data);
566 if (finfo.isNormalized())
567 pixelData[srcPixel] /= 255.0f;
570 default: std::cerr <<
"MipMaps: unknown data type: " << _type << std::endl;
577 for (
int c = 0; c < numChannels; ++c)
578 pixelData[srcPixel][c] = mipData[srcOffset/4 + srcPixelPosLinear * numChannels + c];
581 avgColor += pixelData[srcPixel];
587 int dstPixelPosLinear = y * dstSize[0] + x;
588 for (
int c = 0; c < numChannels; ++c)
589 mipData[dstOffset / 4 + dstPixelPosLinear * numChannels + c] = avgColor[c];
597 for (
int mipID = 0; mipID < numMips; ++mipID)
600 const void* mipDataPtr = _data;
601 GLenum mipDataType = _type;
608 mipDataPtr = &mipData[mipOffset[mipID] / 4];
609 mipDataType = GL_FLOAT;
612 glTexImage2D(getTarget(), mipID, _internalfmt, mipSize[mipID][0], mipSize[mipID][1], 0, _format, mipDataType, mipDataPtr);
619 bool Texture2D::loadFromFile(
const std::string& _filename, GLenum _minFilter, GLenum _magFilter )
621 bool success =
false;
623 const int numMipmapEnums = 4;
624 GLenum mipmapEnums[numMipmapEnums] = {GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR};
625 bool mipmaps =
false;
627 for (
int i = 0; i < numMipmapEnums; ++i)
628 mipmaps = mipmaps || _minFilter == mipmapEnums[i];
630 if (!_filename.empty())
636 if (qtex.load(_filename.c_str()))
641 autogenerateMipMaps();
643 QImage gltex = QGLWidget::convertToGLFormat ( qtex );
645 setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits());
652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _minFilter);
653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _magFilter);
660 void Texture2D::loadRandom( GLint _internalFormat, GLsizei _width, GLsizei _height )
664 if (finfo.isValid() && _width && _height)
666 int n = _width * _height * finfo.channelCount();
670 std::vector<float> randF;
671 std::vector<int> randI;
675 if (finfo.isFloat() || finfo.isNormalized())
679 bool isSigned = finfo.isInt();
681 for (
int i = 0; i < n; ++i)
683 float r = float(rand()) / float(RAND_MAX);
698 for (
int i = 0; i < n; ++i)
706 setData(0, _internalFormat, _width, _height, finfo.format(), gltype, dataPtr);
710 bool Texture2D::checkTextureMem( GLenum _internalFormat, GLsizei _width, GLsizei _height, GLenum _format)
713 glGenTextures(1, &t);
720 glGetIntegerv(GL_TEXTURE_BINDING_2D, &savedTex);
723 glBindTexture(GL_TEXTURE_2D, t);
724 glTexImage2D(GL_PROXY_TEXTURE_2D, 0, _internalFormat, _width, _height, 0, _format, GL_FLOAT, 0);
727 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
731 glBindTexture(GL_TEXTURE_2D, savedTex);
732 glDeleteTextures(1, &t);
740 #if defined(GL_ARB_vertex_buffer_object)
742 void VertexBufferObject::del() {
744 glDeleteBuffersARB(1, &vbo);
748 void VertexBufferObject::upload(
749 GLsizeiptr size,
const GLvoid* data, GLenum usage) {
756 glBufferDataARB(target, size, data, usage);
759 void VertexBufferObject::uploadSubData(
760 GLuint _offset, GLuint _size,
const GLvoid* _data ) {
762 glBufferSubDataARB(target, _offset, _size, _data);
765 void VertexBufferObject::gen() {
766 glGenBuffersARB(1, &vbo);
771 int VertexBufferObject::size() {
774 glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufsize);
783 TextureBuffer::TextureBuffer(GLenum u)
785 #if defined(GL_ARB_texture_buffer_object)
790 bufferSize_(0), buffer_(0), usage_(0), fmt_(0) {
794 TextureBuffer::~TextureBuffer() {
796 glDeleteBuffers(1, &buffer_);
799 void TextureBuffer::setBufferData(
800 int _size,
const void* _data, GLenum _internalFormat, GLenum _usage) {
801 #if defined(GL_ARB_texture_buffer_object)
802 if (supportsTextureBuffer()) {
805 glGenBuffers(1, &buffer_);
807 glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
808 glBufferData(GL_TEXTURE_BUFFER, _size, _data, _usage);
811 fmt_ = _internalFormat;
814 if (getUnit() == GL_NONE)
815 setUnit(GL_TEXTURE0);
819 glTexBuffer(GL_TEXTURE_BUFFER, _internalFormat, buffer_);
824 std::cerr <<
"TextureBuffer::setData - gpu does not support buffer textures!" << std::endl;
826 std::cerr <<
"TextureBuffer::setData - glew version too old, rebuild with latest glew!" << std::endl;
830 bool TextureBuffer::getBufferData(
void* _dst) {
831 #if defined(GL_ARB_texture_buffer_object)
833 glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
834 glGetBufferSubData(GL_TEXTURE_BUFFER, 0, bufferSize_, _dst);
838 std::cerr <<
"TextureBuffer::getBufferData - gpu does not support buffer textures!" << std::endl;
840 std::cerr <<
"TextureBuffer::getBufferData - glew version too old, rebuild with latest glew!" << std::endl;
845 bool TextureBuffer::getBufferData(std::vector<char>& _dst) {
846 if (_dst.size() < size_t(bufferSize_))
847 _dst.resize(bufferSize_);
850 return getBufferData(&_dst[0]);
860 #if defined(GL_NV_vertex_program) || defined(GL_NV_fragment_program)
865 glBindProgramNV(target, program);
868 void ProgramBaseNV::unbind() {
869 glBindProgramNV(target, 0);
872 bool ProgramBaseNV::load(
const char* prog_text) {
873 int size = int(strlen(prog_text));
876 glLoadProgramNV(target, program, size, (
const GLubyte *) prog_text);
878 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errpos);
880 fprintf(stderr,
"\nprogram error:\n");
881 int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
882 for (
int i = bgn; i < end; ++i)
883 fputc(prog_text[i], stderr);
891 void ProgramBaseNV::gen() {
892 glGenProgramsNV(1, &program);
896 void ProgramBaseNV::del() {
898 glDeleteProgramsNV(1, &program);
904 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
909 glBindProgramARB(target, program);
911 void ProgramBaseARB::unbind() {
912 glBindProgramARB(target, 0);
915 bool ProgramBaseARB::load(
const char* prog_text) {
916 int size = int(strlen(prog_text));
920 glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, size, prog_text);
922 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos);
924 fprintf(stderr,
"\nprogram error:\n");
925 int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
926 for (
int i = bgn; i < end; ++i)
927 fputc(prog_text[i], stderr);
934 void ProgramBaseARB::gen() {
935 glGenProgramsARB(1, &program);
938 void ProgramBaseARB::del() {
940 glDeleteProgramsARB(1, &program);
944 #endif // GL_ARB_vertex_program
950 int VertexArrayObject::supportStatus_ = -1;
952 VertexArrayObject::VertexArrayObject()
957 VertexArrayObject::~VertexArrayObject()
959 #ifdef GL_ARB_vertex_array_object
961 glDeleteVertexArrays(1, &id_);
966 void VertexArrayObject::bind()
968 #ifdef GL_ARB_vertex_array_object
973 glBindVertexArray(id_);
977 void VertexArrayObject::unbind()
979 #ifdef GL_ARB_vertex_array_object
980 glBindVertexArray(0);
984 void VertexArrayObject::init()
986 #ifdef GL_ARB_vertex_array_object
988 glDeleteVertexArrays(1, &id_);
990 glGenVertexArrays(1, &id_);
994 bool VertexArrayObject::isSupported()
996 #ifndef GL_ARB_vertex_array_object
1001 if (supportStatus_ < 0)
1005 return supportStatus_ > 0;
1015 int AtomicCounter::supportStatus_ = -1;
1017 AtomicCounter::AtomicCounter(
int _numCounters)
1018 : numCounters_(_numCounters), buffer_(0)
1022 AtomicCounter::~AtomicCounter()
1025 glDeleteBuffers(1, &buffer_);
1028 void AtomicCounter::init()
1031 #ifdef GL_ARB_shader_atomic_counters
1032 if (isSupported() && numCounters_ > 0)
1034 glGenBuffers(1, &buffer_);
1036 glBufferData(GL_ATOMIC_COUNTER_BUFFER, numCounters_ *
sizeof(
unsigned int), 0, GL_DYNAMIC_COPY);
1042 std::cerr <<
"atomic counter failed to initialize!" << std::endl;
1045 void AtomicCounter::bind()
1047 #ifdef GL_ARB_shader_atomic_counters
1053 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, buffer_);
1057 void AtomicCounter::bind(GLuint _index)
1059 #ifdef GL_ARB_shader_atomic_counters
1065 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, _index, buffer_);
1069 void AtomicCounter::unbind()
1071 #ifdef GL_ARB_shader_atomic_counters
1072 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
1076 void AtomicCounter::set(
unsigned int _value)
1078 #ifdef GL_ARB_shader_atomic_counters
1084 const size_t bufSize = numCounters_ *
sizeof(
unsigned int);
1091 void* bufPtr = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, bufSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
1092 memset(bufPtr,
int(_value), bufSize);
1093 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
1100 void AtomicCounter::get(
unsigned int* _out)
1102 #ifdef GL_ARB_shader_atomic_counters
1107 const size_t bufSize = numCounters_ *
sizeof(
unsigned int);
1112 void* bufPtr = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, bufSize, GL_MAP_READ_BIT);
1113 memcpy(_out, bufPtr, bufSize);
1114 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
1121 bool AtomicCounter::isSupported()
1123 #ifndef GL_ARB_shader_atomic_counters
1128 if (supportStatus_ < 0)
1132 return supportStatus_ > 0;
1135 bool AtomicCounter::isValid()
const
1137 return buffer_ && numCounters_ > 0;
1142 QueryObject::QueryObject(GLenum _type)
1143 : id_(0), state_(-1), type_(_type)
1148 QueryObject::~QueryObject()
1151 glDeleteQueries(1, &id_);
1157 glGenQueries(1, &id_);
1159 glBeginQuery(type_, id_);
1176 glGetQueryObjectiv(id_, GL_QUERY_RESULT_AVAILABLE, &r);
1177 return r != GL_FALSE;
1182 GLuint r = 0xffffffff;
1184 glGetQueryObjectuiv(id_, GL_QUERY_RESULT, &r);
1191 int QueryCounter::supportStatus_ = -1;
1193 QueryCounter::QueryCounter()
1196 queryObjects_[0] = queryObjects_[1] = 0;
1199 QueryCounter::~QueryCounter()
1201 if (queryObjects_[0])
1202 glDeleteQueries(2, queryObjects_);
1206 void QueryCounter::restart()
1208 #ifdef GL_ARB_timer_query
1213 if (!queryObjects_[0])
1214 glGenQueries(2, queryObjects_);
1216 glQueryCounter(queryObjects_[0], GL_TIMESTAMP);
1221 void QueryCounter::stop()
1223 #ifdef GL_ARB_timer_query
1226 glQueryCounter(queryObjects_[1], GL_TIMESTAMP);
1234 GLuint64 timing = 0;
1235 #ifdef GL_ARB_timer_query
1240 GLint available = 0;
1242 glGetQueryObjectiv(queryObjects_[1], GL_QUERY_RESULT_AVAILABLE, &available);
1245 glGetQueryObjectui64v(queryObjects_[0], GL_QUERY_RESULT, &timeStart);
1246 glGetQueryObjectui64v(queryObjects_[1], GL_QUERY_RESULT, &timing);
1247 timing -= timeStart;
1262 return float(ms) / 1000.0f;
1267 #ifndef GL_ARB_timer_query
1272 if (supportStatus_ < 0)
1276 return supportStatus_ > 0;
1284 int UniformBufferObject::supportStatus_ = -1;
1285 int UniformBufferObject::maxBlockSize_ = -1;
1286 int UniformBufferObject::maxBindings_ = -1;
1287 int UniformBufferObject::maxCombinedShaderBlocks_ = -1;
1288 int UniformBufferObject::offsetAlignment_ = -1;
1290 UniformBufferObject::UniformBufferObject()
1291 : VertexBufferObject(
1292 #ifndef GL_ARB_uniform_buffer_object
1302 UniformBufferObject::~UniformBufferObject()
1306 void UniformBufferObject::bind( GLuint _index )
1308 #ifdef GL_ARB_uniform_buffer_object
1309 glBindBufferBase(GL_UNIFORM_BUFFER, _index,
id());
1314 bool UniformBufferObject::isSupported()
1316 #ifndef GL_ARB_uniform_buffer_object
1321 if (supportStatus_ < 0)
1325 return supportStatus_ > 0;
1328 void UniformBufferObject::queryCaps()
1330 #ifdef GL_ARB_uniform_buffer_object
1333 glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxBindings_);
1334 glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxBlockSize_);
1335 glGetIntegerv(GL_MAX_COMBINED_UNIFORM_BLOCKS, &maxCombinedShaderBlocks_);
1336 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &offsetAlignment_);
1341 int UniformBufferObject::getMaxBindings()
1343 if (maxBindings_ < 0)
1346 return maxBindings_;
1349 int UniformBufferObject::getMaxBlocksize()
1351 if (maxBlockSize_ < 0)
1354 return maxBlockSize_;
1357 int UniformBufferObject::getMaxCombinedShaderBlocks()
1359 if (maxCombinedShaderBlocks_ < 0)
1362 return maxCombinedShaderBlocks_;
1365 int UniformBufferObject::getOffsetAlignment()
1367 if (offsetAlignment_ < 0)
1370 return offsetAlignment_;
1373 void UniformBufferObject::setUniformData(
GLSL::Program* _prog,
const char* _bufferName,
const char* _uniformName,
const void* _data,
int _datasize,
bool _delay )
1375 if (_prog && _bufferName && _uniformName && _data)
1379 if (idx != GL_INVALID_INDEX)
1383 if (data_.size() != bufsize)
1384 data_.resize(bufsize, 0);
1391 memcpy(&data_[offset], _data, _datasize);
1397 if (size() !=
int(bufsize))
1398 VertexBufferObject::upload(bufsize, &data_[0], GL_DYNAMIC_DRAW);
1400 uploadSubData(offset, _datasize, _data);
1407 void UniformBufferObject::upload()
1413 VertexBufferObject::upload(data_.size(), &data_[0], GL_DYNAMIC_DRAW);
1423 int ShaderStorageBufferObject::supportStatus_ = -1;
1424 int ShaderStorageBufferObject::maxBlockSize_ = -1;
1425 int ShaderStorageBufferObject::maxBindings_ = -1;
1426 int ShaderStorageBufferObject::maxCombinedShaderBlocks_ = -1;
1428 ShaderStorageBufferObject::ShaderStorageBufferObject()
1429 : VertexBufferObject(
1430 #ifndef GL_ARB_shader_storage_buffer_object
1433 GL_SHADER_STORAGE_BUFFER
1439 ShaderStorageBufferObject::~ShaderStorageBufferObject()
1443 void ShaderStorageBufferObject::bind( GLuint _index )
1445 #ifdef GL_ARB_shader_storage_buffer_object
1446 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, _index,
id());
1450 bool ShaderStorageBufferObject::isSupported()
1452 #ifndef GL_ARB_shader_storage_buffer_object
1457 if (supportStatus_ < 0)
1461 return supportStatus_ > 0;
1464 void ShaderStorageBufferObject::queryCaps()
1466 #ifdef GL_ARB_shader_storage_buffer_object
1469 glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &maxBindings_);
1470 glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &maxBlockSize_);
1471 glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &maxCombinedShaderBlocks_);
1476 int ShaderStorageBufferObject::getMaxBindings()
1478 if (maxBindings_ < 0)
1481 return maxBindings_;
1484 int ShaderStorageBufferObject::getMaxBlocksize()
1486 if (maxBlockSize_ < 0)
1489 return maxBlockSize_;
1492 int ShaderStorageBufferObject::getMaxCombinedShaderBlocks()
1494 if (maxCombinedShaderBlocks_ < 0)
1497 return maxCombinedShaderBlocks_;
GLuint64 elapsedNs()
elapsed gpu time since restart() in nanosecs
Namespace providing different geometric functions concerning angles.
VectorT< signed int, 2 > Vec2i
GLuint64 elapsedMs()
elapsed gpu time in millisecs
VectorT< float, 4 > Vec4f
bool openGLVersion(const int _major, const int _minor)
int getUniformBlockSize(GLuint _index)
Get size in bytes of a uniform buffer.
bool checkExtensionSupported(const std::string &_extension)
GLuint getUniformBlockIndex(const char *_name)
Get location of the specified uniform buffer.
GLuint result() const
get the measurement of the query between the begin() end() calls (waits for the gpu) ...
float elapsedSecs()
elapsed gpu time in seconds
void getUniformBlockOffsets(int _numUniforms, const char **_names, int *_outOffsets)
Get offsets of uniforms in a uniform buffer.
void begin()
begin measuring the query
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
bool available() const
check if the result is available (does not wait for gpu to finish)
static bool isSupported()
check hw support
void end()
stop measuring the query