bool initFramebuffer() { glCreateFramebuffers(1, &FramebufferName); glNamedFramebufferTexture(FramebufferName, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0); return this->checkFramebuffer(FramebufferName); }
void Framebuffer::create() { if (m_id == 0) { glCreateFramebuffers(1, &m_id); } }
bool initFramebuffer() { glCreateFramebuffers(1, &FramebufferName); glNamedFramebufferTexture(FramebufferName, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0); glNamedFramebufferTexture(FramebufferName, GL_DEPTH_ATTACHMENT, TextureName[texture::RENDERBUFFER], 0); return glCheckNamedFramebufferStatus(FramebufferName, GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; }
kit::PixelBuffer::PixelBuffer() { this->m_glHandle = 0; this->m_resolution = glm::uvec2(0, 0); this->m_depthAttachment = nullptr; KIT_GL(glCreateFramebuffers(1, &this->m_glHandle)); }
GLuint CreateFramebuffer(GLsizei layers, GLsizei width, GLsizei height, GLsizei samples, GLboolean fixedsamplelocations) { GLuint framebuffer = 0; glCreateFramebuffers(1, &framebuffer); glNamedFramebufferParameteri(framebuffer, GL_FRAMEBUFFER_DEFAULT_LAYERS, layers); glNamedFramebufferParameteri(framebuffer, GL_FRAMEBUFFER_DEFAULT_WIDTH, width); glNamedFramebufferParameteri(framebuffer, GL_FRAMEBUFFER_DEFAULT_HEIGHT, height); glNamedFramebufferParameteri(framebuffer, GL_FRAMEBUFFER_DEFAULT_SAMPLES, samples); glNamedFramebufferParameteri(framebuffer, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, fixedsamplelocations); return framebuffer; }
bool initFramebuffer() { glCreateFramebuffers(framebuffer::MAX, &FramebufferName[0]); glNamedFramebufferTexture(FramebufferName[framebuffer::RENDER], GL_COLOR_ATTACHMENT0, TextureName[texture::MULTISAMPLE], 0); glNamedFramebufferTexture(FramebufferName[framebuffer::RESOLVE], GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0); if(glCheckNamedFramebufferStatus(FramebufferName[framebuffer::RENDER], GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; if(glCheckNamedFramebufferStatus(FramebufferName[framebuffer::RESOLVE], GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; return true; }
void __init_frame_buffer()try { isOK=true; if (width_<=0) { throw QString("width is null"); } if (height_<=0) {throw QString("height is null");} glCreateFramebuffers(1,&fbo_); glCreateTextures(GL_TEXTURE_2D,1,&depth_texture_); glCreateTextures(GL_TEXTURE_2D,1,&color1_texture_); glCreateTextures(GL_TEXTURE_2D,1,&color0_texture_); glTextureStorage2D(depth_texture_,1,GL_DEPTH_COMPONENT32,width_,height_); glTextureStorage2D(color1_texture_,1,GL_RGB16F,width_,height_); glTextureStorage2D(color0_texture_,1,GL_RGB16F,width_,height_); glNamedFramebufferTexture(fbo_,GL_DEPTH_ATTACHMENT,depth_texture_,0); glNamedFramebufferTexture(fbo_,GL_COLOR_ATTACHMENT0,color0_texture_, 0 ); glNamedFramebufferTexture(fbo_,GL_COLOR_ATTACHMENT1,color1_texture_, 0 ); #if defined(_DEBUG) /*check*/ GLenum fboStatus = glCheckNamedFramebufferStatus( fbo_,GL_DRAW_FRAMEBUFFER); if (fboStatus!=GL_FRAMEBUFFER_COMPLETE){ isOK=false; switch ( fboStatus ) { case GL_FRAMEBUFFER_UNDEFINED: qDebug() << "GL_FRAMEBUFFER_UNDEFINED"; break; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"; break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"; break; case GL_FRAMEBUFFER_UNSUPPORTED:qDebug() << "GL_FRAMEBUFFER_UNSUPPORTED"; break; case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"; break; case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break; default: break; } return ; } #endif }/*__init_frame_buffer*/ catch (const QString & error) { isOK=false; qDebug().noquote()<<error; }
bool initFramebuffer() { bool Validated(true); glm::ivec2 WindowSize(this->getWindowSize()); glCreateFramebuffers(1, &FramebufferName); glNamedFramebufferParameteri(FramebufferName, GL_FRAMEBUFFER_DEFAULT_WIDTH, WindowSize.x * this->Supersampling); glNamedFramebufferParameteri(FramebufferName, GL_FRAMEBUFFER_DEFAULT_HEIGHT, WindowSize.y * this->Supersampling); glNamedFramebufferParameteri(FramebufferName, GL_FRAMEBUFFER_DEFAULT_LAYERS, 1); glNamedFramebufferParameteri(FramebufferName, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 1); glNamedFramebufferParameteri(FramebufferName, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, GL_TRUE); return this->checkFramebuffer(FramebufferName); }
void piglit_init(int argc, char **argv) { bool pass = true; GLuint framebuffer; GLuint default_framebuffer = 0; GLenum bufs[2] = {GL_BACK_LEFT, GL_BACK}; GLenum one_buf; bool subtest_pass; int i; glCreateFramebuffers(1, &framebuffer); piglit_check_gl_error(GL_NO_ERROR); /* * "An INVALID_OPERATION error is generated by * NamedFramebufferDrawBuffers if framebuffer is not zero or * the name of an existing framebuffer" */ glNamedFramebufferDrawBuffers(5, 2, bufs); PIGLIT_SUBTEST_ERROR(GL_INVALID_OPERATION, pass, "INVALID_OPERATION if " "framebuffer is not zero or the name of an existing " "framebuffer"); /* * "An INVALID_VALUE error is generated if n is negative, or greater than the * value of MAX_DRAW_BUFFERS." */ int max_draw_buffers; glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers); subtest_pass = true; glNamedFramebufferDrawBuffers(0, -1, bufs); subtest_pass = subtest_pass & piglit_check_gl_error(GL_INVALID_VALUE); glNamedFramebufferDrawBuffers(0, max_draw_buffers + 1, bufs); subtest_pass = subtest_pass & piglit_check_gl_error(GL_INVALID_VALUE); PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "INVALID_VALUE error is " "generated if n is negative, or greater than " "the value of MAX_DRAW_BUFFERS."); /* * From OpenGL 4.5 spec * "An INVALID_ENUM error is generated if any value in bufs * is not one of the values in tables 17.5 or 17.6." */ subtest_pass = true; one_buf = GL_RED; glNamedFramebufferDrawBuffers(default_framebuffer, 1, &one_buf); subtest_pass = subtest_pass && piglit_check_gl_error(GL_INVALID_ENUM); glNamedFramebufferDrawBuffers(framebuffer, 1, &one_buf); subtest_pass = subtest_pass && piglit_check_gl_error(GL_INVALID_ENUM); PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "INVALID_ENUM error is " "generated if any value in bufs is not one of " "the values in tables 17.5 or 17.6."); /* * (cont on error out of 17.5 or 17.6) Specifically for the default * framebuffer: * From OpenGL 4.5 spec, page 492 (515 PDF) * "If the default framebuffer is affected, then each of the * constants must be one of the values listed in table 17.6 * or the special value BACK ."" * * And: *"An INVALID_OPERATION error is generated if the default * framebuffer is affected and any value in bufs is a * constant (other than NONE or BACK) that does not indicate * one of the color buffers allocated to the default * framebuffer." * * So for the default framebuffer, and that table, we expect * GL_NO_ERROR or GL_INVALID_OPERATION. */ subtest_pass = true; for (i = 0; i < ARRAY_SIZE(table_17_6_and_back); i++) { GLenum err = 0; glNamedFramebufferDrawBuffers(default_framebuffer, 1, &table_17_6_and_back[i]); /* We manually check glGetError instead of relying on * piglit_check_gl_error like in other subtests * because for subtests that checks several enums, we * are interested on getting which one failed. That * makes debugging easier. */ err = glGetError(); if (err != GL_NO_ERROR && err != GL_INVALID_OPERATION) { printf("Expected GL_NO_ERROR or GL_INVALID_OPERATION " "with %s but received: %s\n", piglit_get_gl_enum_name(table_17_6_and_back[i]), piglit_get_gl_error_name(err)); subtest_pass = false; } } /* For that spec paragraph, we also test enums from table * 17.5. They should return INVALID_OPERATION, as after all, * they are not allocated to the default framebuffer. */ one_buf = GL_COLOR_ATTACHMENT0; glNamedFramebufferDrawBuffers(default_framebuffer, 1, &one_buf); subtest_pass = subtest_pass && piglit_check_gl_error(GL_INVALID_OPERATION); PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "If the default framebuffer" " is affected, then each of the constants must " "be one of the values listed in table 17.6 or " "the special value BACK. INVALID_OPERATION error" " is generated if the default framebuffer is " "affected and any value in bufs is a constant " "(other than NONE or BACK ) that does not indicate " "one of the color buffers allocated to the default" " framebuffer."); /* (cont default framebuffer) * From OpenGL 4.5 spec: * "When BACK is used, n must be 1 and color values are * written into the left buffer for single-buffered * contexts, or into the back left buffer for * double-buffered contexts" * * From the error table: * "An INVALID_OPERATION error is generated if any value in * bufs is BACK , and n is not one." * */ glNamedFramebufferDrawBuffers(default_framebuffer, 2, bufs); PIGLIT_SUBTEST_ERROR(GL_INVALID_OPERATION, pass, "(default framebuffer)" " An INVALID_OPERATION error is generated if any " "value in bufs is BACK, and n is not one."); /* * Now, specifically for a framebuffer object: * "If a framebuffer object is affected, then each of the * constants must be one of the values listed in table 17.5." * * 17.5 is GL_NONE, and COLOR_ATTACHMENTi, where i < * MAX_COLOR_ATTACHMENTS - 1 */ int max_attachments; glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_attachments); subtest_pass = true; for (i = 0; i < max_attachments; i++) { one_buf = GL_COLOR_ATTACHMENT0 + i; glNamedFramebufferDrawBuffers(framebuffer, 1, &one_buf); subtest_pass = subtest_pass && piglit_check_gl_error(GL_NO_ERROR); } PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "If a framebuffer object is " "affected, then each of constants must be one of the " "values listed in table 17.5."); /* * "An INVALID_OPERATION error is generated if a framebuffer * object is affected and any value in bufs is a constant * from table 17.6, or COLOR_ATTACHMENTm where m is greater * than or equal to the value of MAX_COLOR_ATTACHMENTS." */ subtest_pass = true; /* Starting at 1, as GL_NONE is valid */ for (i = 1; i < ARRAY_SIZE(table_17_6); i++) { GLenum err = 0; glNamedFramebufferDrawBuffers(framebuffer, 1, &table_17_6[i]); err = glGetError(); if (err != GL_INVALID_OPERATION) { printf("Expected GL_INVALID_OPERATION with" " %s but received: %s\n", piglit_get_gl_enum_name(table_17_6[i]), piglit_get_gl_error_name(err)); subtest_pass = false; } } one_buf = GL_COLOR_ATTACHMENT0 + max_attachments; glNamedFramebufferDrawBuffers(framebuffer, 1, &one_buf); subtest_pass = subtest_pass && piglit_check_gl_error(GL_INVALID_OPERATION); PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "INVALID_OPERATION error is " "generated if a framebuffer object is affected and any " "value in bufs is a constant from table 17.6, or " "COLOR_ATTACHMENTm where m is greater than or equal " "to the value of MAX_COLOR_ATTACHMENTS."); /* * "An INVALID_OPERATION error is generated if a buffer other * than NONE is specified more than once in the array pointed * to by bufs" */ bufs[0] = bufs[1] = GL_FRONT_LEFT; glNamedFramebufferDrawBuffers(framebuffer, 2, bufs); PIGLIT_SUBTEST_ERROR(GL_INVALID_OPERATION, pass, "INVALID_OPERATION error " "is generated if a buffer other than NONE is specified " "more than once in the array pointed to by bufs."); /* * From OpenGL 4.5 spec: * "An INVALID_ENUM error is generated if any value in bufs is * FRONT, LEFT, RIGHT, or FRONT_AND_BACK . This restriction * applies to both the default framebuffer and framebuffer * objects, and exists because these constants may themselves * refer to multiple buffers, as shown in table 17.4." */ subtest_pass = true; for (i = 0; i < ARRAY_SIZE(multiple_buffers); i++) { GLenum err = 0; bool local_pass = true; glNamedFramebufferDrawBuffers(default_framebuffer, 1, &multiple_buffers[i]); err = glGetError(); local_pass = local_pass && (err == GL_INVALID_ENUM); glNamedFramebufferDrawBuffers(framebuffer, 1, &multiple_buffers[i]); err = glGetError(); local_pass = local_pass && (err == GL_INVALID_ENUM); if (!local_pass) printf("Expected GL_INVALID_ENUM with" " %s but received: %s\n", piglit_get_gl_enum_name(table_17_6_and_back[i]), piglit_get_gl_error_name(err)); subtest_pass = subtest_pass && local_pass; } PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "INVALID_ENUM error is " "generated if any value in bufs is FRONT, LEFT," " RIGHT, or FRONT_AND_BACK "); /* clean up */ glDeleteFramebuffers(1, &framebuffer); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
bool OGLCoreFramebuffer::setup(const GraphicsFramebufferDesc& framebufferDesc) noexcept { assert(GL_NONE == _fbo); assert(framebufferDesc.getGraphicsFramebufferLayout()); assert(framebufferDesc.getGraphicsFramebufferLayout()->isInstanceOf<OGLFramebufferLayout>()); assert(framebufferDesc.getWidth() > 0 && framebufferDesc.getHeight() > 0); glCreateFramebuffers(1, &_fbo); if (_fbo == GL_NONE) { this->getDevice()->downcast<OGLDevice>()->message("glCreateFramebuffers() fail"); return false; } GLenum drawCount = 0; GLenum drawBuffers[GL_COLOR_ATTACHMENT15 - GL_COLOR_ATTACHMENT0]; const auto& textureComponents = framebufferDesc.getGraphicsFramebufferLayout()->getGraphicsFramebufferLayoutDesc().getComponents(); const auto& colorAttachments = framebufferDesc.getColorAttachments(); if (colorAttachments.size() > (sizeof(drawBuffers) / sizeof(drawBuffers[0]))) { this->getDevice()->downcast<OGLDevice>()->message("The color attachment in framebuffer is out of range."); return false; } for (std::size_t i = 0; i < textureComponents.size(); i++) { auto type = textureComponents[i].getAttachType(); switch (type) { case GraphicsImageLayout::GraphicsImageLayoutGeneral: break; case GraphicsImageLayout::GraphicsImageLayoutColorAttachmentOptimal: { GLint slot = GL_COLOR_ATTACHMENT0 + textureComponents[i].getAttachSlot(); GLint mipLevel = colorAttachments[drawCount].getBindingLevel(); GLint layer = colorAttachments[drawCount].getBindingLayer(); if (!this->bindRenderTexture(colorAttachments[drawCount].getBindingTexture(), slot, mipLevel, layer)) return false; drawBuffers[drawCount++] = slot; } break; case GraphicsImageLayout::GraphicsImageLayoutDepthStencilAttachmentOptimal: case GraphicsImageLayout::GraphicsImageLayoutDepthStencilReadOnlyOptimal: { const auto& depthStencilAttachment = framebufferDesc.getDepthStencilAttachment(); if (!depthStencilAttachment.getBindingTexture()) { this->getDevice()->downcast<OGLDevice>()->message("Need depth or stencil texture."); return false; } auto texture = depthStencilAttachment.getBindingTexture(); auto format = texture->getGraphicsTextureDesc().getTexFormat(); auto level = depthStencilAttachment.getBindingLevel(); auto layer = depthStencilAttachment.getBindingLayer(); if (OGLTypes::isDepthStencilFormat(format)) { if (!this->bindRenderTexture(texture, GL_DEPTH_STENCIL_ATTACHMENT, level, layer)) return false; } else if (OGLTypes::isDepthFormat(format)) { if (!this->bindRenderTexture(texture, GL_DEPTH_ATTACHMENT, level, layer)) return false; } else if (OGLTypes::isStencilFormat(format)) { if (!this->bindRenderTexture(texture, GL_STENCIL_ATTACHMENT, level, layer)) return false; } else { this->getDevice()->downcast<OGLDevice>()->message("Invalid texture format"); return false; } } case GraphicsImageLayout::GraphicsImageLayoutShaderReadOnlyOptimal: break; case GraphicsImageLayout::GraphicsImageLayoutTransferSrcOptimal: break; case GraphicsImageLayout::GraphicsImageLayoutTransferDstOptimal: break; case GraphicsImageLayout::GraphicsImageLayoutPreinitialized: break; case GraphicsImageLayout::GraphicsImageLayoutPresentSrcKhr: break; default: break; } } glNamedFramebufferDrawBuffers(_fbo, drawCount, drawBuffers); _framebufferDesc = framebufferDesc; return OGLCheck::checkError(); }
void SuzanneGL::RenderShadowMaps() { GLuint FramebufferName = 0; glCreateFramebuffers(1, &FramebufferName); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glm::mat4 depthViewProjectionMatrices[NUMBER_OF_LIGHTS]; for (int i = 0; i < NUMBER_OF_LIGHTS; ++i) { glCreateTextures(GL_TEXTURE_2D, 1, &shadowMaps[i]); glTextureImage2DEXT(shadowMaps[i], GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, SHADOW_RESOLUTION, SHADOW_RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTextureParameteri(shadowMaps[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTextureParameteri(shadowMaps[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTextureParameteri(shadowMaps[i], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTextureParameteri(shadowMaps[i], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTextureParameteri(shadowMaps[i], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTextureParameteri(shadowMaps[i], GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMaps[i], 0); glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return; glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); glViewport(0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION); glm::vec3 lightDir = glm::normalize(glm::vec3(lighting.lights[i].position.x, lighting.lights[i].position.y, lighting.lights[i].position.z)); glm::mat4 depthProjectionMatrix = glm::ortho<float>(-10, 10, -10, 10, -10, 20); glm::mat4 depthViewMatrix = glm::lookAt(lightDir, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); depthViewProjectionMatrices[i] = depthProjectionMatrix * depthViewMatrix; shadowModelMatrixIndex = glGetUniformLocation(shadowShaderProgram, "modelMatrix"); shadowViewProjectionMatrixIndex = glGetUniformLocation(shadowShaderProgram, "viewProjectionMatrix"); glProgramUniformMatrix4fv(shadowShaderProgram, shadowViewProjectionMatrixIndex, 1, GL_FALSE, glm::value_ptr(depthViewProjectionMatrices[i])); for (ModelGL model : models) { glProgramUniformMatrix4fv(shadowShaderProgram, shadowModelMatrixIndex, 1, GL_FALSE, glm::value_ptr(model.modelMatrix)); glNamedBufferSubData(materialBuffer, 0, sizeof(Material), &model.material); glBindVertexArray(model.vertexArray); glUseProgram(shadowShaderProgram); glDrawArrays(GL_TRIANGLES, 0, model.vertexCount); } } glBindFramebuffer(GL_FRAMEBUFFER, 0); glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 ); shadowViewProjectionMatrixIndex = glGetUniformLocation(shaderProgram, "shadowViewProjectionMatrix"); shadowBiasMatrixIndex = glGetUniformLocation(shaderProgram, "shadowBiasMatrix"); glProgramUniformMatrix4fv(shaderProgram, shadowViewProjectionMatrixIndex, 2, GL_FALSE, glm::value_ptr(depthViewProjectionMatrices[0])); glProgramUniformMatrix4fv(shaderProgram, shadowBiasMatrixIndex, 1, GL_FALSE, glm::value_ptr(biasMatrix)); }
static void createObjects(GLsizei n, GLuint* objects) { glCreateFramebuffers(n, objects); }
static GLuint allocate() { GLuint result; glCreateFramebuffers(1, &result); return result; }
GLFramebufferObject::GLFramebufferObject() : m_isExternal( false ) { glCreateFramebuffers( 1, &m_id ); }
Framebuffer() {glCreateFramebuffers(1,&m_handle);}