42 #include <ACG/GL/acg_glew.hh> 43 #include <ACG/GL/globjects.hh> 44 #include <ACG/GL/GLFormatInfo.hh> 45 #include <ACG/ShaderUtils/GLSLShader.hh> 46 #include <ACG/Utils/ImageConversion.hh> 56 Texture::Texture( GLenum tgt, GLenum _unit )
57 : target(tgt), unit(_unit), valid(false), texture(0u), internalFormat_(0)
61 void Texture::bindAsImage(GLuint _index, GLenum _access)
63 #if defined(GL_ARB_shader_image_load_store) 65 glBindImageTexture(_index,
id(), 0, GL_FALSE, 0, _access, getInternalFormat());
67 std::cerr <<
"Texture::bindAsImage - error: texture not initialized!" << std::endl;
69 std::cerr <<
"Texture::bindAsImage - glBindImageTexture symbol not loaded!" << std::endl;
74 GLint Texture::getInternalFormat()
79 glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat_);
82 return internalFormat_;
121 bool Texture::clear(
const ACG::Vec4f& _color )
123 #ifdef GL_ARB_clear_texture 124 if (supportsClearTexture() && texture)
126 glClearTexImage(texture, 0, GL_RGBA, GL_FLOAT, _color.
data());
135 #ifdef GL_ARB_clear_texture 136 if (supportsClearTexture() && texture)
138 glClearTexImage(texture, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, _color.data());
145 bool Texture::clear(
const ACG::Vec4i& _color )
147 #ifdef GL_ARB_clear_texture 148 if (supportsClearTexture() && texture)
150 glClearTexImage(texture, 0, GL_RGBA_INTEGER, GL_INT, _color.data());
157 bool Texture::supportsImageLoadStore()
159 static int status = -1;
163 #if defined(GL_ARB_shader_image_load_store) 176 bool Texture::supportsTextureBuffer()
178 static int status = -1;
190 bool Texture::supportsClearTexture()
192 static int status = -1;
196 #if defined(GL_ARB_clear_texture) 207 bool Texture::supportsGenerateMipmap()
209 static int status = -1;
213 #if defined(GL_SGIS_generate_mipmap) 227 Texture1D::Texture1D( GLenum unit ) :
Texture(GL_TEXTURE_1D, unit),
232 void Texture1D::setData(GLint _level,
233 GLint _internalFormat,
237 const GLvoid* _data) {
241 glTexImage1D(GL_TEXTURE_1D, _level, _internalFormat, _width, 0, _format, _type, _data);
244 internalFormat_ = _internalFormat;
250 void Texture1D::setStorage( GLsizei _levels, GLenum _internalFormat, GLsizei _width ) {
251 #ifdef GL_ARB_texture_storage 253 glTexStorage1D(GL_TEXTURE_1D, _levels, _internalFormat, _width);
256 internalFormat_ = _internalFormat;
258 GLFormatInfo finfo(_internalFormat);
259 format_ = finfo.format();
260 type_ = finfo.type();
261 #endif // GL_ARB_texture_storage 265 bool Texture1D::getData( GLint _level,
void* _dst ) {
268 glGetIntegerv(GL_TEXTURE_BINDING_1D, &curTex);
271 glGetTexImage(GL_TEXTURE_1D, _level, format_, type_, _dst);
273 glBindTexture(GL_TEXTURE_1D, curTex);
280 bool Texture1D::getData( GLint _level, std::vector<char>& _dst ) {
283 GLFormatInfo finfo(internalFormat_);
285 if (finfo.isValid()) {
286 size_t bufSize = finfo.elemSize() * width_;
288 if (_dst.size() < bufSize)
289 _dst.resize(bufSize);
292 return getData(_level, &_dst[0]);
304 Texture2D::Texture2D(GLenum unit)
305 :
Texture(GL_TEXTURE_2D, unit),
306 width_(0), height_(0),
307 format_(0), type_(0),
313 bool Texture2D::autogenerateMipMaps()
322 #ifdef GL_SGIS_generate_mipmap 323 if (supportsGenerateMipmap())
325 parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
330 buildMipsCPU_ =
true;
336 void Texture2D::disableAutogenerateMipMaps()
338 #ifdef GL_SGIS_generate_mipmap 339 if (supportsGenerateMipmap())
340 parameter(GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
342 buildMipsCPU_ =
false;
347 void Texture2D::setData(GLint _level,
348 GLint _internalFormat,
356 if (getUnit() == GL_NONE)
357 setUnit(GL_TEXTURE0);
361 if (buildMipsCPU_ && _level == 0)
362 buildMipMaps(_internalFormat, _width, _height, _format, _type, _data);
364 glTexImage2D(GL_TEXTURE_2D, _level, _internalFormat, _width, _height, 0, _format, _type, _data);
368 glGenerateMipmap(GL_TEXTURE_2D);
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 = ACG::Util::convertToGLFormat(qtex);
645 setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits(), mipmaps);
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_VERSION_1_5) 742 void VertexBufferObject::del() {
744 glDeleteBuffers(1, &vbo);
748 void VertexBufferObject::upload(
749 GLsizeiptr size,
const GLvoid* data, GLenum usage) {
756 glBufferData(target, size, data, usage);
759 void VertexBufferObject::uploadSubData(
760 GLuint _offset, GLuint _size,
const GLvoid* _data ) {
762 glBufferSubData(target, _offset, _size, _data);
765 void VertexBufferObject::gen() {
766 glGenBuffers(1, &vbo);
771 int VertexBufferObject::size() {
774 glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufsize);
783 TextureBuffer::TextureBuffer(GLenum u)
786 bufferSize_(0), buffer_(0), usage_(0), fmt_(0) {
790 TextureBuffer::~TextureBuffer() {
792 glDeleteBuffers(1, &buffer_);
795 void TextureBuffer::setBufferData(
796 size_t _size,
const void* _data, GLenum _internalFormat, GLenum _usage) {
797 if (supportsTextureBuffer()) {
800 glGenBuffers(1, &buffer_);
802 glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
803 glBufferData(GL_TEXTURE_BUFFER, static_cast<GLsizei>(_size), _data, _usage);
806 fmt_ = _internalFormat;
809 if (getUnit() == GL_NONE)
810 setUnit(GL_TEXTURE0);
814 glTexBuffer(GL_TEXTURE_BUFFER, _internalFormat, buffer_);
819 std::cerr <<
"TextureBuffer::setData - gpu does not support buffer textures!" << std::endl;
822 bool TextureBuffer::getBufferData(
void* _dst) {
826 glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
827 glGetBufferSubData(GL_TEXTURE_BUFFER, 0, bufferSize_, _dst);
831 std::cerr <<
"TextureBuffer::getBufferData - gpu does not support buffer textures!" << std::endl;
833 std::cerr <<
"TextureBuffer::getBufferData - currently only in core profile available!" << std::endl;
838 bool TextureBuffer::getBufferData(std::vector<char>& _dst) {
839 if (_dst.size() < size_t(bufferSize_))
840 _dst.resize(bufferSize_);
843 return getBufferData(&_dst[0]);
853 #if defined(GL_NV_vertex_program) || defined(GL_NV_fragment_program) 858 glBindProgramARB(target, program);
861 void ProgramBaseNV::unbind() {
862 glBindProgramARB(target, 0);
865 bool ProgramBaseNV::load(
const char* prog_text) {
866 int size = int(strlen(prog_text));
869 glLoadProgramNV(target, program, size, (
const GLubyte *) prog_text);
871 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errpos);
873 fprintf(stderr,
"\nprogram error:\n");
874 int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
875 for (
int i = bgn; i < end; ++i)
876 fputc(prog_text[i], stderr);
884 void ProgramBaseNV::gen() {
885 glGenProgramsARB(1, &program);
889 void ProgramBaseNV::del() {
891 glDeleteProgramsARB(1, &program);
897 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) 902 glBindProgramARB(target, program);
904 void ProgramBaseARB::unbind() {
905 glBindProgramARB(target, 0);
908 bool ProgramBaseARB::load(
const char* prog_text) {
909 int size = int(strlen(prog_text));
913 glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, size, prog_text);
915 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos);
917 fprintf(stderr,
"\nprogram error:\n");
918 int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
919 for (
int i = bgn; i < end; ++i)
920 fputc(prog_text[i], stderr);
927 void ProgramBaseARB::gen() {
928 glGenProgramsARB(1, &program);
931 void ProgramBaseARB::del() {
933 glDeleteProgramsARB(1, &program);
937 #endif // GL_ARB_vertex_program 943 int VertexArrayObject::supportStatus_ = -1;
945 VertexArrayObject::VertexArrayObject()
950 VertexArrayObject::~VertexArrayObject()
952 #ifdef GL_ARB_vertex_array_object 954 glDeleteVertexArrays(1, &id_);
959 void VertexArrayObject::bind()
961 #ifdef GL_ARB_vertex_array_object 966 glBindVertexArray(id_);
970 void VertexArrayObject::unbind()
972 #ifdef GL_ARB_vertex_array_object 973 glBindVertexArray(0);
977 void VertexArrayObject::init()
979 #ifdef GL_ARB_vertex_array_object 981 glDeleteVertexArrays(1, &id_);
983 glGenVertexArrays(1, &id_);
987 bool VertexArrayObject::isSupported()
989 #ifndef GL_ARB_vertex_array_object 994 if (supportStatus_ < 0)
1000 return supportStatus_ > 0;
1010 int AtomicCounter::supportStatus_ = -1;
1012 AtomicCounter::AtomicCounter(
int _numCounters)
1013 : numCounters_(_numCounters), buffer_(0)
1017 AtomicCounter::~AtomicCounter()
1020 glDeleteBuffers(1, &buffer_);
1023 void AtomicCounter::init()
1026 #ifdef GL_ARB_shader_atomic_counters 1027 if (isSupported() && numCounters_ > 0)
1029 glGenBuffers(1, &buffer_);
1031 glBufferData(GL_ATOMIC_COUNTER_BUFFER, numCounters_ *
sizeof(
unsigned int), 0, GL_DYNAMIC_COPY);
1037 std::cerr <<
"atomic counter failed to initialize!" << std::endl;
1040 void AtomicCounter::bind()
1042 #ifdef GL_ARB_shader_atomic_counters 1048 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, buffer_);
1052 void AtomicCounter::bind(GLuint _index)
1054 #ifdef GL_ARB_shader_atomic_counters 1060 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, _index, buffer_);
1064 void AtomicCounter::unbind()
1066 #ifdef GL_ARB_shader_atomic_counters 1067 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
1071 void AtomicCounter::set(
unsigned int _value)
1073 #ifdef GL_ARB_shader_atomic_counters 1079 const size_t bufSize = numCounters_ *
sizeof(
unsigned int);
1086 void* bufPtr = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, bufSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
1087 memset(bufPtr,
int(_value), bufSize);
1088 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
1095 void AtomicCounter::get(
unsigned int* _out)
1097 #ifdef GL_ARB_shader_atomic_counters 1102 const size_t bufSize = numCounters_ *
sizeof(
unsigned int);
1107 void* bufPtr = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, bufSize, GL_MAP_READ_BIT);
1108 memcpy(_out, bufPtr, bufSize);
1109 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
1116 bool AtomicCounter::isSupported()
1118 #ifndef GL_ARB_shader_atomic_counters 1123 if (supportStatus_ < 0)
1127 return supportStatus_ > 0;
1130 bool AtomicCounter::isValid()
const 1132 return buffer_ && numCounters_ > 0;
1137 QueryObject::QueryObject(GLenum _type)
1138 : id_(0), state_(-1), type_(_type)
1143 QueryObject::~QueryObject()
1146 glDeleteQueries(1, &id_);
1152 glGenQueries(1, &id_);
1154 glBeginQuery(type_, id_);
1171 glGetQueryObjectiv(id_, GL_QUERY_RESULT_AVAILABLE, &r);
1172 return r != GL_FALSE;
1177 GLuint r = 0xffffffff;
1179 glGetQueryObjectuiv(id_, GL_QUERY_RESULT, &r);
1186 int QueryCounter::supportStatus_ = -1;
1188 QueryCounter::QueryCounter()
1191 queryObjects_[0] = queryObjects_[1] = 0;
1194 QueryCounter::~QueryCounter()
1196 if (queryObjects_[0])
1197 glDeleteQueries(2, queryObjects_);
1201 void QueryCounter::restart()
1203 #ifdef GL_ARB_timer_query 1208 if (!queryObjects_[0])
1209 glGenQueries(2, queryObjects_);
1211 glQueryCounter(queryObjects_[0], GL_TIMESTAMP);
1216 void QueryCounter::stop()
1218 #ifdef GL_ARB_timer_query 1221 glQueryCounter(queryObjects_[1], GL_TIMESTAMP);
1229 GLuint64 timing = 0;
1230 #ifdef GL_ARB_timer_query 1235 GLint available = 0;
1237 glGetQueryObjectiv(queryObjects_[1], GL_QUERY_RESULT_AVAILABLE, &available);
1240 glGetQueryObjectui64v(queryObjects_[0], GL_QUERY_RESULT, &timeStart);
1241 glGetQueryObjectui64v(queryObjects_[1], GL_QUERY_RESULT, &timing);
1242 timing -= timeStart;
1250 return elapsedNs() / 1000;
1255 GLuint64 ms = elapsedMs();
1257 return float(ms) / 1000.0f;
1262 #ifndef GL_ARB_timer_query 1267 if (supportStatus_ < 0)
1271 return supportStatus_ > 0;
1279 int UniformBufferObject::supportStatus_ = -1;
1280 int UniformBufferObject::maxBlockSize_ = -1;
1281 int UniformBufferObject::maxBindings_ = -1;
1282 int UniformBufferObject::maxCombinedShaderBlocks_ = -1;
1283 int UniformBufferObject::offsetAlignment_ = -1;
1285 UniformBufferObject::UniformBufferObject()
1286 : VertexBufferObject(
1287 #ifndef GL_ARB_uniform_buffer_object
1297 UniformBufferObject::~UniformBufferObject()
1301 void UniformBufferObject::bind( GLuint _index )
1303 #ifdef GL_ARB_uniform_buffer_object 1304 glBindBufferBase(GL_UNIFORM_BUFFER, _index,
id());
1309 bool UniformBufferObject::isSupported()
1311 #ifndef GL_ARB_uniform_buffer_object 1316 if (supportStatus_ < 0)
1320 return supportStatus_ > 0;
1323 void UniformBufferObject::queryCaps()
1325 #ifdef GL_ARB_uniform_buffer_object 1328 glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxBindings_);
1329 glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxBlockSize_);
1330 glGetIntegerv(GL_MAX_COMBINED_UNIFORM_BLOCKS, &maxCombinedShaderBlocks_);
1331 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &offsetAlignment_);
1336 int UniformBufferObject::getMaxBindings()
1338 if (maxBindings_ < 0)
1341 return maxBindings_;
1344 int UniformBufferObject::getMaxBlocksize()
1346 if (maxBlockSize_ < 0)
1349 return maxBlockSize_;
1352 int UniformBufferObject::getMaxCombinedShaderBlocks()
1354 if (maxCombinedShaderBlocks_ < 0)
1357 return maxCombinedShaderBlocks_;
1360 int UniformBufferObject::getOffsetAlignment()
1362 if (offsetAlignment_ < 0)
1365 return offsetAlignment_;
1368 void UniformBufferObject::setUniformData(
GLSL::Program* _prog,
const char* _bufferName,
const char* _uniformName,
const void* _data,
int _datasize,
bool _delay )
1370 if (_prog && _bufferName && _uniformName && _data)
1374 if (idx != GL_INVALID_INDEX)
1378 if (data_.size() != bufsize)
1379 data_.resize(bufsize, 0);
1386 memcpy(&data_[offset], _data, _datasize);
1392 if (size() !=
int(bufsize))
1393 VertexBufferObject::upload(bufsize, &data_[0], GL_DYNAMIC_DRAW);
1395 uploadSubData(offset, _datasize, _data);
1402 void UniformBufferObject::upload()
1408 VertexBufferObject::upload(data_.size(), &data_[0], GL_DYNAMIC_DRAW);
1418 int ShaderStorageBufferObject::supportStatus_ = -1;
1419 int ShaderStorageBufferObject::maxBlockSize_ = -1;
1420 int ShaderStorageBufferObject::maxBindings_ = -1;
1421 int ShaderStorageBufferObject::maxCombinedShaderBlocks_ = -1;
1423 ShaderStorageBufferObject::ShaderStorageBufferObject()
1424 : VertexBufferObject(
1425 #ifndef GL_ARB_shader_storage_buffer_object
1428 GL_SHADER_STORAGE_BUFFER
1434 ShaderStorageBufferObject::~ShaderStorageBufferObject()
1438 void ShaderStorageBufferObject::bind( GLuint _index )
1440 #ifdef GL_ARB_shader_storage_buffer_object 1441 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, _index,
id());
1445 bool ShaderStorageBufferObject::isSupported()
1447 #ifndef GL_ARB_shader_storage_buffer_object 1452 if (supportStatus_ < 0)
1456 return supportStatus_ > 0;
1459 void ShaderStorageBufferObject::queryCaps()
1461 #ifdef GL_ARB_shader_storage_buffer_object 1464 glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &maxBindings_);
1465 glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &maxBlockSize_);
1466 glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &maxCombinedShaderBlocks_);
1471 int ShaderStorageBufferObject::getMaxBindings()
1473 if (maxBindings_ < 0)
1476 return maxBindings_;
1479 int ShaderStorageBufferObject::getMaxBlocksize()
1481 if (maxBlockSize_ < 0)
1484 return maxBlockSize_;
1487 int ShaderStorageBufferObject::getMaxCombinedShaderBlocks()
1489 if (maxCombinedShaderBlocks_ < 0)
1492 return maxCombinedShaderBlocks_;
void begin()
begin measuring the query
GLuint64 elapsedNs()
elapsed gpu time since restart() in nanosecs
VectorT< signed int, 2 > Vec2i
static bool isSupported()
check hw support
Namespace providing different geometric functions concerning angles.
VectorT< float, 4 > Vec4f
Scalar * data()
access to Scalar array
GLuint getUniformBlockIndex(const char *_name)
Get location of the specified uniform buffer.
void getUniformBlockOffsets(int _numUniforms, const char **_names, int *_outOffsets)
Get offsets of uniforms in a uniform buffer.
bool openGLVersion(const int _major, const int _minor, bool _verbose)
GLuint result() const
get the measurement of the query between the begin() end() calls (waits for the gpu) ...
GLuint64 elapsedMs()
elapsed gpu time in millisecs
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
int getUniformBlockSize(GLuint _index)
Get size in bytes of a uniform buffer.
void end()
stop measuring the query
bool checkExtensionSupported(const std::string &_extension)
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
float elapsedSecs()
elapsed gpu time in seconds
bool available() const
check if the result is available (does not wait for gpu to finish)