void Texture2D::present(Shader *shader) { // One shared mesh for all texture presentation static GLuint vao, vbo; if (!glIsBuffer(vao)) { GLfloat vertices[] = { -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, 1.0, 0.0, }; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, 48, vertices, GL_STATIC_DRAW); GLint loc = shader->getAttribLocation("vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); } glBindFramebuffer(GL_FRAMEBUFFER, 0); glBlendFunc(GL_ONE, GL_ZERO); glBindVertexArray(vao); shader->use(); GLint texLoc = shader->getUniformLocation("texture0"); glUniform1i(texLoc, 0); bindToUnit(GL_TEXTURE0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); unbind(); }
void allocate(size_t new_width, size_t new_height) { width = new_width; height = new_height; size = height * width * bytes_per_pixel; data = new unsigned char[size]; glGenTextures(1, &texture); bindToUnit(GL_TEXTURE0); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_RECTANGLE, 0, FormatT::InternalFormat, width, height, 0, FormatT::Format, FormatT::Type, 0); }
void Texture2D::present(Shader *shader) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glBlendFunc(GL_ONE, GL_ZERO); GLfloat vertices[] = { -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, 1.0, 0.0, }; glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); shader->use(); bindToUnit(GL_TEXTURE0); GLint loc = shader->getAttribLocation("vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 0, vertices); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); unbind(); }
void upload() { bindToUnit(GL_TEXTURE0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexSubImage2D(GL_TEXTURE_RECTANGLE, /*level*/0, /*xoffset*/0, /*yoffset*/0, width, height, FormatT::Format, FormatT::Type, data); }