Răsfoiți Sursa

device: blit into SDR color buffer

Daniele Bartolini 1 săptămână în urmă
părinte
comite
afffdc43ce
2 a modificat fișierele cu 34 adăugiri și 10 ștergeri
  1. 29 9
      src/device/pipeline.cpp
  2. 5 1
      src/device/pipeline.h

+ 29 - 9
src/device/pipeline.cpp

@@ -156,6 +156,7 @@ static void lookup_default_shaders(Pipeline &pl)
 
 
 Pipeline::Pipeline(ShaderManager &sm)
 Pipeline::Pipeline(ShaderManager &sm)
 	: _shader_manager(&sm)
 	: _shader_manager(&sm)
+	, _color_sdr(BGFX_INVALID_HANDLE)
 	, _depth_texture(BGFX_INVALID_HANDLE)
 	, _depth_texture(BGFX_INVALID_HANDLE)
 	, _color_map(BGFX_INVALID_HANDLE)
 	, _color_map(BGFX_INVALID_HANDLE)
 	, _depth_map(BGFX_INVALID_HANDLE)
 	, _depth_map(BGFX_INVALID_HANDLE)
@@ -381,6 +382,9 @@ void Pipeline::destroy()
 		_colors[i] = BGFX_INVALID_HANDLE;
 		_colors[i] = BGFX_INVALID_HANDLE;
 	}
 	}
 
 
+	bgfx::destroy(_color_sdr);
+	_color_sdr = BGFX_INVALID_HANDLE;
+
 	bgfx::destroy(_depth_texture);
 	bgfx::destroy(_depth_texture);
 	_depth_texture = BGFX_INVALID_HANDLE;
 	_depth_texture = BGFX_INVALID_HANDLE;
 
 
@@ -434,6 +438,22 @@ void Pipeline::reset(u16 width, u16 height)
 		_colors[i] = bgfx::createFrameBuffer(countof(_main_frame_buffer_attachments), _main_frame_buffer_attachments);
 		_colors[i] = bgfx::createFrameBuffer(countof(_main_frame_buffer_attachments), _main_frame_buffer_attachments);
 	}
 	}
 
 
+	// Create SDR frame buffer.
+	const bgfx::TextureHandle sdr_attach[] =
+	{
+		bgfx::createTexture2D(width
+			, height
+			, false
+			, 1
+			, bgfx::TextureFormat::RGBA8
+			, color_texture_flags
+			),
+		_depth_texture
+	};
+	if (bgfx::isValid(_color_sdr))
+		bgfx::destroy(_color_sdr);
+	_color_sdr = bgfx::createFrameBuffer(countof(sdr_attach), sdr_attach, true);
+
 	// Create selection frame buffer.
 	// Create selection frame buffer.
 	if (bgfx::isValid(_selection_texture))
 	if (bgfx::isValid(_selection_texture))
 		bgfx::destroy(_selection_texture);
 		bgfx::destroy(_selection_texture);
@@ -527,7 +547,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthAscending);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthAscending);
-			bgfx::setViewFrameBuffer(id, _colors[0]);
+			bgfx::setViewFrameBuffer(id, _color_sdr);
 			bgfx::touch(id);
 			bgfx::touch(id);
 		} else if (id == View::CASCADE_CLEAR) {
 		} else if (id == View::CASCADE_CLEAR) {
 			view_name = "sm_cascade_clear";
 			view_name = "sm_cascade_clear";
@@ -647,7 +667,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthDescending);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthDescending);
-			bgfx::setViewFrameBuffer(id, _colors[0]);
+			bgfx::setViewFrameBuffer(id, _color_sdr);
 			bgfx::touch(id);
 			bgfx::touch(id);
 		} else if (id == View::SELECTION) {
 		} else if (id == View::SELECTION) {
 			view_name = "selection";
 			view_name = "selection";
@@ -676,7 +696,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 			view_name = "debug";
 			view_name = "debug";
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewTransform(id, to_float_ptr(view), to_float_ptr(proj));
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewRect(id, 0, 0, width, height);
-			bgfx::setViewFrameBuffer(id, _colors[0]);
+			bgfx::setViewFrameBuffer(id, _color_sdr);
 			bgfx::touch(id);
 			bgfx::touch(id);
 		} else if (id == View::SCREEN_GUI) {
 		} else if (id == View::SCREEN_GUI) {
 			view_name = "screen_gui";
 			view_name = "screen_gui";
@@ -696,7 +716,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 			bgfx::setViewTransform(id, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(ortho_proj));
 			bgfx::setViewTransform(id, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(ortho_proj));
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthDescending);
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthDescending);
-			bgfx::setViewFrameBuffer(id, _colors[0]);
+			bgfx::setViewFrameBuffer(id, _color_sdr);
 			bgfx::touch(id);
 			bgfx::touch(id);
 		} else if (id == View::GRAPH) {
 		} else if (id == View::GRAPH) {
 			view_name = "graph";
 			view_name = "graph";
@@ -714,7 +734,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 				);
 				);
 			bgfx::setViewTransform(id, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(from_array(graph_ortho)));
 			bgfx::setViewTransform(id, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(from_array(graph_ortho)));
 			bgfx::setViewRect(id, 0, 0, width, height);
 			bgfx::setViewRect(id, 0, 0, width, height);
-			bgfx::setViewFrameBuffer(id, _colors[0]);
+			bgfx::setViewFrameBuffer(id, _color_sdr);
 			bgfx::touch(id);
 			bgfx::touch(id);
 		} else if (id == View::BLIT) {
 		} else if (id == View::BLIT) {
 			view_name = "blit";
 			view_name = "blit";
@@ -815,10 +835,10 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 	}
 	}
 
 
 	// Tonemapping.
 	// Tonemapping.
-	bgfx::setViewFrameBuffer(View::TONEMAP, _colors[0]);
+	bgfx::setViewFrameBuffer(View::TONEMAP, _color_sdr);
 	bgfx::setViewTransform(View::TONEMAP, NULL, ortho);
 	bgfx::setViewTransform(View::TONEMAP, NULL, ortho);
 	bgfx::setViewRect(View::TONEMAP, 0, 0, width, height);
 	bgfx::setViewRect(View::TONEMAP, 0, 0, width, height);
-	bgfx::setTexture(0, _color_map, bgfx::getTexture(_colors[1]), samplerFlags);
+	bgfx::setTexture(0, _color_map, bgfx::getTexture(_colors[0]), samplerFlags);
 	bgfx::setUniform(_tonemap_type, &_tonemap, sizeof(_tonemap)/sizeof(Vector4));
 	bgfx::setUniform(_tonemap_type, &_tonemap, sizeof(_tonemap)/sizeof(Vector4));
 	screenSpaceQuad(width, height, 0.0f, caps->originBottomLeft);
 	screenSpaceQuad(width, height, 0.0f, caps->originBottomLeft);
 	bgfx::setState(_tonemap_shader.state);
 	bgfx::setState(_tonemap_shader.state);
@@ -836,7 +856,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 	bgfx::setState(_outline_shader.state);
 	bgfx::setState(_outline_shader.state);
 	bgfx::submit(View::OUTLINE, _outline_shader.program);
 	bgfx::submit(View::OUTLINE, _outline_shader.program);
 
 
-	bgfx::setViewFrameBuffer(View::OUTLINE_BLIT, _colors[0]);
+	bgfx::setViewFrameBuffer(View::OUTLINE_BLIT, _color_sdr);
 	bgfx::setTexture(0, _outline_color_map, _outline_color_texture, samplerFlags);
 	bgfx::setTexture(0, _outline_color_map, _outline_color_texture, samplerFlags);
 	bgfx::setViewRect(View::OUTLINE_BLIT, 0, 0, width, height);
 	bgfx::setViewRect(View::OUTLINE_BLIT, 0, 0, width, height);
 	bgfx::setViewTransform(View::OUTLINE_BLIT, NULL, ortho);
 	bgfx::setViewTransform(View::OUTLINE_BLIT, NULL, ortho);
@@ -849,7 +869,7 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 	bgfx::setViewFrameBuffer(View::BLIT, BGFX_INVALID_HANDLE);
 	bgfx::setViewFrameBuffer(View::BLIT, BGFX_INVALID_HANDLE);
 	bgfx::setViewRect(View::BLIT, 0, 0, width, height);
 	bgfx::setViewRect(View::BLIT, 0, 0, width, height);
 	bgfx::setViewTransform(View::BLIT, NULL, ortho);
 	bgfx::setViewTransform(View::BLIT, NULL, ortho);
-	bgfx::setTexture(0, _color_map, bgfx::getTexture(_colors[0]), samplerFlags);
+	bgfx::setTexture(0, _color_map, bgfx::getTexture(_color_sdr), samplerFlags);
 	screenSpaceQuad(width, height, 0.0f, caps->originBottomLeft);
 	screenSpaceQuad(width, height, 0.0f, caps->originBottomLeft);
 	bgfx::setState(_blit_shader.state);
 	bgfx::setState(_blit_shader.state);
 	bgfx::submit(View::BLIT, _blit_shader.program);
 	bgfx::submit(View::BLIT, _blit_shader.program);

+ 5 - 1
src/device/pipeline.h

@@ -44,7 +44,10 @@ struct View
 		BLOOM_COMBINE,
 		BLOOM_COMBINE,
 		DUMMY_BLIT,
 		DUMMY_BLIT,
 		TONEMAP,
 		TONEMAP,
-		SPRITE_0,
+
+		SDR, // SDR rendering below.
+
+		SPRITE_0              = SDR,
 		SPRITE_LAST           = SPRITE_0 + MAX_NUM_SPRITE_LAYERS,
 		SPRITE_LAST           = SPRITE_0 + MAX_NUM_SPRITE_LAYERS,
 		WORLD_GUI             = SPRITE_LAST,
 		WORLD_GUI             = SPRITE_LAST,
 		SELECTION,
 		SELECTION,
@@ -71,6 +74,7 @@ struct Pipeline
 	RenderSettings _render_settings;
 	RenderSettings _render_settings;
 
 
 	// Main output color/depth handles.
 	// Main output color/depth handles.
+	bgfx::FrameBufferHandle _color_sdr;
 	bgfx::TextureHandle _color_textures[2];
 	bgfx::TextureHandle _color_textures[2];
 	bgfx::TextureHandle _depth_texture;
 	bgfx::TextureHandle _depth_texture;
 	bgfx::FrameBufferHandle _colors[2];
 	bgfx::FrameBufferHandle _colors[2];