Fix rendering of Final render for Storm delegate #61

Merged
Bogdan Nagirniak merged 11 commits from BLEN-437 into hydra-render 2023-07-12 23:18:03 +02:00
2 changed files with 59 additions and 31 deletions
Showing only changes of commit 6ee0f4793d - Show all commits

View File

@ -114,7 +114,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
}
void FinalEngineGL::render0(Depsgraph *depsgraph)
void FinalEngineGL::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
@ -124,14 +124,15 @@ void FinalEngineGL::render0(Depsgraph *depsgraph)
resolution_[1],
1,
GPU_RGBA32F,
GPU_TEXTURE_USAGE_GENERAL,
GPU_TEXTURE_USAGE_ATTACHMENT,
nullptr);
GPU_texture_filter_mode(texture, true);
GPU_texture_mipmap_mode(texture, true, true);
GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0);
GPU_framebuffer_bind(framebuffer);
float clear_color[4] = {0.0, 0.0, 0.0, 0.0};
GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0);
float clear_color[4] = {0.1f, 0.1f, 0.1f, 1.0f};
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0);
engine_->Execute(render_index_.get(), &tasks_);
@ -175,16 +176,16 @@ void FinalEngineGL::render0(Depsgraph *depsgraph)
GPU_texture_free(texture);
}
void FinalEngineGL::render(Depsgraph *depsgraph)
void FinalEngineGL::render0(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
GLuint framebuffer = 0, tex_color = 0, tex_depth = 0;
glGenFramebuffers(1, &framebuffer);
GLuint fbo = 0, tex_color = 0, tex_depth = 0;
glGenFramebuffers(1, &fbo);
glGenTextures(1, &tex_color);
glGenTextures(1, &tex_depth);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
// Set tex_color as GL_COLOR_ATTACHMENT0
glBindTexture(GL_TEXTURE_2D, tex_color);
@ -194,30 +195,53 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex_color, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_color, 0);
// Set tex_depth as GL_DEPTH_ATTACHMENT
glBindTexture(GL_TEXTURE_2D, tex_depth);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT32,
resolution_[0],
resolution_[1],
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, tex_depth, 0);
GLuint rbo = 0;
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, resolution_[0], resolution_[1]);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
printf("ERROR::FRAMEBUFFER:: Framebuffer is not complete!\n");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//// Set tex_depth as GL_DEPTH_ATTACHMENT
//glBindTexture(GL_TEXTURE_2D, tex_depth);
//glTexImage2D(GL_TEXTURE_2D,
// 0,
// GL_DEPTH_COMPONENT32,
// resolution_[0],
// resolution_[1],
// 0,
// GL_DEPTH_COMPONENT,
// GL_FLOAT,
// 0);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
////glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex_depth, 0);
// Generate vertex array
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glEnable(GL_DEPTH_TEST);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
//glClearDepthf(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glDepthFunc(GL_LESS);
engine_->Execute(render_index_.get(), &tasks_);
std::vector<float> &pixels = render_images_["Combined"];

View File

@ -117,9 +117,9 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
engine->sync(depsgraph, context);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE;
}
@ -135,9 +135,9 @@ static PyObject *engine_sync_usd_func(PyObject * /*self*/, PyObject *args)
boost::python::extract<pxr::UsdStageRefPtr> extract(pystage);
pxr::UsdStagePtr stage = extract();
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
engine->sync_usd(stage);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE;
}
@ -152,12 +152,13 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
/* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS;
engine->render(depsgraph);
Py_END_ALLOW_THREADS;
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine);
Py_RETURN_NONE;
}
@ -172,12 +173,13 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine);
/* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS;
engine->render(depsgraph, context);
Py_END_ALLOW_THREADS;
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine);
Py_RETURN_NONE;
}
@ -208,9 +210,10 @@ static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *arg
}
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
engine->set_sync_setting(key, get_setting_val(pyval));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key);
engine->set_sync_setting(key, get_setting_val(pyval));
Py_RETURN_NONE;
}
@ -223,9 +226,10 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
}
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
engine->set_render_setting(key, get_setting_val(pyval));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key);
engine->set_render_setting(key, get_setting_val(pyval));
Py_RETURN_NONE;
}