void NLGLWidget::initializeTexture() { if (_texture >= 0) { cleanupTexture(); } // Create the texture for displaying the result: GLuint gltex; glGenTextures(1, &gltex); _texture = gltex; reportGLError("setupGLRendering() genTexture"); // Bind texture: glBindTexture(GL_TEXTURE_2D, _texture); reportGLError("setupGLRendering() bindTexture"); // Allocate texture: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, _img_width, _img_height, 0, GL_RGBA, GL_FLOAT, NULL); reportGLError("setupGLRendering() texImage2D"); // Set texture parameters: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); reportGLError("setupGLRendering() glTexParameteri"); // Unbind texture: glBindTexture(GL_TEXTURE_2D, 0); reportGLError("setupGLRendering() bindTexture(0)"); // Register the buffer object: checkCUDAError("Pre gl register"); cudaGraphicsGLRegisterImage(&_graphicsResource, _texture, GL_TEXTURE_2D, cudaGraphicsMapFlagsWriteDiscard); checkCUDAError("Post gl register"); }
void loadTextures(tgaInfo *info, GLuint *texture) { GLsizei w, h; int mode; if (info->status != TGA_OK) { fprintf(stderr, "error loading texture image: %d\n", info->status); return; } mode = info->pixelDepth / 8; // will be 3 for rgb, 4 for rgba glGenTextures(1, texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); // Upload the texture bitmap. w = info->width; h = info->height; reportGLError("before uploading texture"); GLint format = (mode == 4) ? GL_RGBA : GL_RGB; glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, format, GL_UNSIGNED_BYTE, info->imageData); reportGLError("after uploading texture"); tgaDestroy(info); }
void VertexBufferObject::bufferSubData(GLintptr offset, GLsizeiptr size, const GLvoid *data) { try { if(glIsBuffer(_buffer) == GL_FALSE) throw std::runtime_error("Invalid buffer object"); glBufferSubData(_bufferTarget, offset, size, data); reportGLError(__FILE__, __LINE__); } catch(std::runtime_error &err) { std::cerr << "Error: Failed to create buffer object data store " << std::endl; std::cerr << "Reason: " << err.what () << std::endl; } }
void NLGLWidget::cleanupTexture() { if (_texture < 0) return; // Unregister the graphics resource: cudaError_t error = cudaGraphicsUnregisterResource(_graphicsResource); if (error != cudaSuccess) { qCritical() << "ERROR! (cleanupGLRendering()) GraphicsUnregisterResource" << cudaGetErrorString(error); } // Delete texture: GLuint gltex = _texture; glDeleteTextures(1, &gltex); _texture = -1; if(_checkboardTexture < 0) return; gltex = _checkboardTexture; glDeleteTextures(1, &gltex); _checkboardTexture = -1; reportGLError("OutputTexture cleanup"); }