void Texture::draw() { bind(); quad.draw(); unbind(); checkGLError("Texture::draw quad draw"); }
unsigned char *Texture::mapData() { if(!texture) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboTexture); texture = (unsigned char*)(glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE)); } checkGLError("Texture::mapData"); return texture; }
void Texture::createTexture() { glGenTextures(1, &idTexture); glBindTexture(GL_TEXTURE_2D, idTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GLint(GL_REPEAT)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GLint(GL_REPEAT)); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); checkGLError("Texture::createTexture glTexStorage2D"); glGenBuffers(1, &pboTexture); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboTexture); glBufferData(GL_PIXEL_UNPACK_BUFFER, getWidth() * getHeight() * getChannelCount(), nullptr, GL_DYNAMIC_DRAW); checkGLError("Texture::createTexture glBufferData"); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }
void Texture::uploadData() { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboTexture); bind(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0); unbind(); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); checkGLError("Texture::uploadData"); }
void Texture::unmapData() { glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); checkGLError("Texture::unmapData"); texture = nullptr; }