|
|
@@ -13,14 +13,13 @@ namespace render_texture_impl {
|
|
|
bool init_ok = false;
|
|
|
|
|
|
using pg_type = std::unique_ptr<smart_program>;
|
|
|
- pg_type pg_bw; // render black/white texture
|
|
|
- pg_type pg_rgb; // render rgb texture
|
|
|
- pg_type pg_rgba; // render rgba texture
|
|
|
+ pg_type pg_bw; // render black/white texture
|
|
|
+ pg_type pg_rgb; // render rgb texture
|
|
|
+ pg_type pg_rgba; // render rgba texture
|
|
|
pg_type pg_rgb_d; // render rgb and depth texture
|
|
|
- pg_type pg_nv12; // render nv12 textures
|
|
|
-// pg_type pg_depth_only;
|
|
|
-// pg_type pg_color_depth;
|
|
|
-// pg_type pg_depth_alpha;
|
|
|
+ pg_type pg_rgbd2; // render rgb and depth texture (use depth alpha)
|
|
|
+ pg_type pg_nv12; // render nv12 textures
|
|
|
+ pg_type pg_d; // render depth only
|
|
|
|
|
|
void init_buffers() {
|
|
|
assert(!init_ok);
|
|
|
@@ -75,6 +74,26 @@ namespace render_texture_impl {
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
|
|
}
|
|
|
|
|
|
+ void ren_d_only(const tex_render_info &info) {
|
|
|
+ auto &pg = pg_d;
|
|
|
+ if (pg == nullptr) {
|
|
|
+ pg = std::unique_ptr<smart_program>(
|
|
|
+ smart_program::create("tex_d",
|
|
|
+ {{GL_VERTEX_SHADER, "tex.vert"},
|
|
|
+ {GL_FRAGMENT_SHADER, "tex_d.frag"}}));
|
|
|
+ }
|
|
|
+ assert(pg != nullptr);
|
|
|
+ pg->use();
|
|
|
+
|
|
|
+ glActiveTexture(GL_TEXTURE0 + 0);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, info.depth.id);
|
|
|
+ pg->set_uniform_i("d_tex", 0);
|
|
|
+
|
|
|
+ glEnable(GL_DEPTH_TEST);
|
|
|
+ config_buffers(info);
|
|
|
+ draw();
|
|
|
+ }
|
|
|
+
|
|
|
// render bw texture
|
|
|
void ren_bw_only(const tex_render_info &info) {
|
|
|
auto &pg = pg_bw;
|
|
|
@@ -168,6 +187,35 @@ namespace render_texture_impl {
|
|
|
draw();
|
|
|
}
|
|
|
|
|
|
+ void ren_rgb_d_v2(const tex_render_info &info) {
|
|
|
+ auto &pg = pg_rgbd2;
|
|
|
+ if (pg == nullptr) {
|
|
|
+ pg = std::unique_ptr<smart_program>(
|
|
|
+ smart_program::create("tex_rgb_d_v2",
|
|
|
+ {{GL_VERTEX_SHADER, "tex.vert"},
|
|
|
+ {GL_FRAGMENT_SHADER, "tex_rgb_d_v2.frag"}}));
|
|
|
+ }
|
|
|
+ assert(pg != nullptr);
|
|
|
+ pg->use();
|
|
|
+
|
|
|
+ auto &extra = info.extra.color_depth;
|
|
|
+ pg->set_uniform_f("opacity", info.color.alpha);
|
|
|
+ pg->set_uniform_f("alpha_factor", extra.alpha_factor);
|
|
|
+ pg->set_uniform_mat4("proj_inv",
|
|
|
+ glm::inverse(extra.proj_mat));
|
|
|
+
|
|
|
+ glActiveTexture(GL_TEXTURE0 + 0);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, info.color.id);
|
|
|
+ pg->set_uniform_i("c_tex", 0);
|
|
|
+ glActiveTexture(GL_TEXTURE0 + 1);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, info.depth.id);
|
|
|
+ pg->set_uniform_i("d_tex", 1);
|
|
|
+
|
|
|
+ glDisable(GL_DEPTH_TEST);
|
|
|
+ config_buffers(info);
|
|
|
+ draw();
|
|
|
+ }
|
|
|
+
|
|
|
void ren_nv12_only(const tex_render_info &info) {
|
|
|
auto &pg = pg_nv12;
|
|
|
if (pg == nullptr) {
|
|
|
@@ -221,7 +269,11 @@ namespace render_texture_impl {
|
|
|
void ren_c_d(const tex_render_info &info) {
|
|
|
switch (info.color.fmt) {
|
|
|
case COLOR_RGB: {
|
|
|
- ren_rgb_d(info);
|
|
|
+ if (info.depth.enable_alpha_effect) {
|
|
|
+ ren_rgb_d_v2(info);
|
|
|
+ } else {
|
|
|
+ ren_rgb_d(info);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
@@ -240,6 +292,10 @@ void render_texture(const tex_render_info &info) {
|
|
|
ren_c_only(info);
|
|
|
break;
|
|
|
}
|
|
|
+ case TEX_DEPTH_ONLY: {
|
|
|
+ ren_d_only(info);
|
|
|
+ break;
|
|
|
+ }
|
|
|
case TEX_COLOR_DEPTH: {
|
|
|
ren_c_d(info);
|
|
|
break;
|