void ScreenBasedRenderManager::destroyMsaaFrameBuffer()
{
    glVerify(glDeleteFramebuffers(1, &this->msaa_FBO_));
    glVerify(glDeleteRenderbuffers(1, &this->msaa_color_RBO_));
    glVerify(glDeleteRenderbuffers(1, &this->msaa_depth_RBO_));
    glVerify(glDeleteTextures(1, &this->msaa_color_TEX_));
}
예제 #2
0
void LineRenderUtil::initVAOAndVBO()
{
    glVerify(glGenVertexArrays(1, &line_VAO_));
    glVerify(glBindVertexArray(line_VAO_));

    glGenBuffers(1, &line_VBO_);
    glBindBuffer(GL_ARRAY_BUFFER, line_VBO_);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glVerify(glBindVertexArray(0));
}
예제 #3
0
void RenderTaskBase::renderTask()
{
    if (enable_bind_shader_ == true)
        shader_.bindAndConfigBasicUniforms();

    //config global uniforms
    GlobalUniformConfig & global_uniform_config = GlobalUniformConfig::getSingleton();
    global_uniform_config.configGlobalUniforms();

    //set model transform
    const Matrix4f & model_trans = transform_.transformMatrix();
    openGLSetCurBindShaderMat4("model_trans", model_trans);

    glVerify(glPushAttrib(GL_ALL_ATTRIB_BITS));

    renderTaskImpl();

    glVerify(glPopAttrib());

    if (enable_bind_shader_ == true)
        shader_.unBind();
}
void ScreenBasedRenderManager::renderToScreen()
{
    //switch back to the default frame buffer
    glVerify(glBindFramebuffer(GL_FRAMEBUFFER, 0));
    glVerify(glViewport(0, 0, this->screen_width_, this->screen_height_));

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    this->msaa_shader_program_.use();
    openGLSetCurBindShaderBool("use_gamma_correction", use_gamma_correction_);
    openGLSetCurBindShaderBool("use_hdr", use_hdr_);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, msaa_color_TEX_);

    glBindVertexArray(screen_VAO_);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glBindVertexArray(0);

    glBindTexture(GL_TEXTURE_2D, 0);

    this->msaa_shader_program_.unUse();
}
void ScreenBasedRenderManager::beginFrame()
{
    float window_clear_color[3];
    glGetFloatv(GL_COLOR_CLEAR_VALUE, window_clear_color);

    //switch to msaa_FBO & set view port
    glVerify(glBindFramebuffer(GL_FRAMEBUFFER, this->msaa_FBO_));
    glVerify(glViewport(0, 0, this->screen_width_, this->screen_height_));

    glVerify(glPushAttrib(GL_ALL_ATTRIB_BITS));

    glVerify(glEnable(GL_DEPTH_TEST));
    glVerify(glClearColor(window_clear_color[0], window_clear_color[1], window_clear_color[2], 1.0f));
    glVerify(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
}
void ScreenBasedRenderManager::endFrame()
{
    glVerify(glPopAttrib());

    //clear all global uniform configs
    GlobalUniformConfig & global_uniform_config = GlobalUniformConfig::getSingleton();
    global_uniform_config.clear();

    /*
     
    //render to default frame buffer

    //specify msaa_FBO to read and default FBO to draw
    glVerify(glBindFramebuffer(GL_READ_FRAMEBUFFER, this->msaa_FBO_));
    glVerify(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));

    //blit the msaa_FBO to the window(default FBO), i.e. render to the current window
    glVerify(glBlitFramebuffer(0, 0, this->screen_width_, this->screen_height_, 0, 0, this->screen_width_, this->screen_height_, GL_COLOR_BUFFER_BIT, GL_LINEAR));

    //render help to back buffer
    glVerify(glBindFramebuffer(GL_FRAMEBUFFER, 0));

    */
}
void ScreenBasedRenderManager::initMsaaFrameBuffer()
{
    //determine msaa_samples
    int samples;
    glGetIntegerv(GL_MAX_SAMPLES_EXT, &samples);
    samples = std::min({ samples, this->msaa_samples_, 4 }); // clamp samples to 4

                                                             //create msaa_FBO
    glVerify(glGenFramebuffers(1, &this->msaa_FBO_));
    glVerify(glBindFramebuffer(GL_FRAMEBUFFER, this->msaa_FBO_));

    //create msaa_color_RBO & bind it to msaa_FBO
    //glVerify(glGenRenderbuffers(1, &this->msaa_color_RBO_));
    //glVerify(glBindRenderbuffer(GL_RENDERBUFFER, this->msaa_color_RBO_));
    //glVerify(glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, this->screen_width_, this->screen_height_));
    //glVerify(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, this->msaa_color_RBO_));
    //glVerify(glBindRenderbuffer(GL_RENDERBUFFER, 0));

    glVerify(glGenTextures(1, &this->msaa_color_TEX_));
    glVerify(glBindTexture(GL_TEXTURE_2D, this->msaa_color_TEX_));
    glVerify(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
    glVerify(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
    glVerify(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
    glVerify(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
    glVerify(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, this->screen_width_, this->screen_height_, 0, GL_RGB, GL_FLOAT, nullptr));
    glVerify(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->msaa_color_TEX_, 0));
    glVerify(glBindTexture(GL_TEXTURE_2D, 0));

    //create msaa_depth_RBO & bind it to msaa_FBO
    glVerify(glGenRenderbuffers(1, &this->msaa_depth_RBO_));
    glVerify(glBindRenderbuffer(GL_RENDERBUFFER, this->msaa_depth_RBO_));
    glVerify(glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH_COMPONENT, this->screen_width_, this->screen_height_));
    glVerify(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, this->msaa_depth_RBO_));
    glVerify(glBindRenderbuffer(GL_RENDERBUFFER, 0));

    //check frame buffer status
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    {
        std::cerr << "error: msaa_FBO is incomplete !" << std::endl;
        std::exit(EXIT_FAILURE);
    }

    glEnable(GL_MULTISAMPLE);

    //switch to default framebuffer
    glVerify(glBindFramebuffer(GL_FRAMEBUFFER, 0));
}
GLuint LoadCubeTexture(const char* baseName)
{

	TgaImage img;
	std::string base(baseName);
	
	GLuint texture;
	glVerify(glActiveTexture(GL_TEXTURE0));
    glVerify(glEnable(GL_TEXTURE_CUBE_MAP));
    glVerify(glGenTextures(1, &texture));
    glVerify(glBindTexture(GL_TEXTURE_CUBE_MAP, texture));
	glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE));
    glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
    glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); 
    glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
    glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
    glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));

	if (TgaLoad((base + "_bk.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	if (TgaLoad((base + "_ft.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	if (TgaLoad((base + "_lf.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	if (TgaLoad((base + "_rt.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	if (TgaLoad((base + "_dn.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	if (TgaLoad((base + "_up.tga").c_str(), img))
		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data);

	//...
	glVerify(glDisable(GL_TEXTURE_CUBE_MAP));

	return texture;
}
예제 #9
0
void LineRenderUtil::unbindLineVAO()
{
    glVerify(glBindVertexArray(0));
}
예제 #10
0
void LineRenderUtil::bindLineVAO()
{
    glVerify(glBindVertexArray(line_VAO_));
}