mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	gl_rasterizer: Use the shared texture buffer for the noise, color and alpha map.
This commit is contained in:
		
							parent
							
								
									63fb7dcc1b
								
							
						
					
					
						commit
						1ca6d2ea8d
					
				
					 6 changed files with 19 additions and 104 deletions
				
			
		|  | @ -135,36 +135,6 @@ RasterizerOpenGL::RasterizerOpenGL() | ||||||
|     glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum()); |     glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum()); | ||||||
|     glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle()); |     glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle()); | ||||||
| 
 | 
 | ||||||
|     // Setup the noise LUT for proctex
 |  | ||||||
|     proctex_noise_lut.Create(); |  | ||||||
|     state.proctex_noise_lut.texture_buffer = proctex_noise_lut.handle; |  | ||||||
|     state.Apply(); |  | ||||||
|     proctex_noise_lut_buffer.Create(); |  | ||||||
|     glBindBuffer(GL_TEXTURE_BUFFER, proctex_noise_lut_buffer.handle); |  | ||||||
|     glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 2 * 128, nullptr, GL_DYNAMIC_DRAW); |  | ||||||
|     glActiveTexture(TextureUnits::ProcTexNoiseLUT.Enum()); |  | ||||||
|     glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, proctex_noise_lut_buffer.handle); |  | ||||||
| 
 |  | ||||||
|     // Setup the color map for proctex
 |  | ||||||
|     proctex_color_map.Create(); |  | ||||||
|     state.proctex_color_map.texture_buffer = proctex_color_map.handle; |  | ||||||
|     state.Apply(); |  | ||||||
|     proctex_color_map_buffer.Create(); |  | ||||||
|     glBindBuffer(GL_TEXTURE_BUFFER, proctex_color_map_buffer.handle); |  | ||||||
|     glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 2 * 128, nullptr, GL_DYNAMIC_DRAW); |  | ||||||
|     glActiveTexture(TextureUnits::ProcTexColorMap.Enum()); |  | ||||||
|     glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, proctex_color_map_buffer.handle); |  | ||||||
| 
 |  | ||||||
|     // Setup the alpha map for proctex
 |  | ||||||
|     proctex_alpha_map.Create(); |  | ||||||
|     state.proctex_alpha_map.texture_buffer = proctex_alpha_map.handle; |  | ||||||
|     state.Apply(); |  | ||||||
|     proctex_alpha_map_buffer.Create(); |  | ||||||
|     glBindBuffer(GL_TEXTURE_BUFFER, proctex_alpha_map_buffer.handle); |  | ||||||
|     glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 2 * 128, nullptr, GL_DYNAMIC_DRAW); |  | ||||||
|     glActiveTexture(TextureUnits::ProcTexAlphaMap.Enum()); |  | ||||||
|     glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, proctex_alpha_map_buffer.handle); |  | ||||||
| 
 |  | ||||||
|     // Setup the LUT for proctex
 |     // Setup the LUT for proctex
 | ||||||
|     proctex_lut.Create(); |     proctex_lut.Create(); | ||||||
|     state.proctex_lut.texture_buffer = proctex_lut.handle; |     state.proctex_lut.texture_buffer = proctex_lut.handle; | ||||||
|  | @ -1987,39 +1957,41 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // helper function for SyncProcTexNoiseLUT/ColorMap/AlphaMap
 |     // helper function for SyncProcTexNoiseLUT/ColorMap/AlphaMap
 | ||||||
|     auto SyncProcTexValueLUT = [](const std::array<Pica::State::ProcTex::ValueEntry, 128>& lut, |     auto SyncProcTexValueLUT = [this, buffer, offset, invalidate, &bytes_used]( | ||||||
|                                   std::array<GLvec2, 128>& lut_data, GLuint buffer) { |                                    const std::array<Pica::State::ProcTex::ValueEntry, 128>& lut, | ||||||
|  |                                    std::array<GLvec2, 128>& lut_data, GLint& lut_offset) { | ||||||
|         std::array<GLvec2, 128> new_data; |         std::array<GLvec2, 128> new_data; | ||||||
|         std::transform(lut.begin(), lut.end(), new_data.begin(), [](const auto& entry) { |         std::transform(lut.begin(), lut.end(), new_data.begin(), [](const auto& entry) { | ||||||
|             return GLvec2{entry.ToFloat(), entry.DiffToFloat()}; |             return GLvec2{entry.ToFloat(), entry.DiffToFloat()}; | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         if (new_data != lut_data) { |         if (new_data != lut_data || invalidate) { | ||||||
|             lut_data = new_data; |             lut_data = new_data; | ||||||
|             glBindBuffer(GL_TEXTURE_BUFFER, buffer); |             std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2)); | ||||||
|             glBufferSubData(GL_TEXTURE_BUFFER, 0, new_data.size() * sizeof(GLvec2), |             lut_offset = (offset + bytes_used) / sizeof(GLvec2); | ||||||
|                             new_data.data()); |             uniform_block_data.dirty = true; | ||||||
|  |             bytes_used += new_data.size() * sizeof(GLvec2); | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     // Sync the proctex noise lut
 |     // Sync the proctex noise lut
 | ||||||
|     if (uniform_block_data.proctex_noise_lut_dirty) { |     if (uniform_block_data.proctex_noise_lut_dirty || invalidate) { | ||||||
|         SyncProcTexValueLUT(Pica::g_state.proctex.noise_table, proctex_noise_lut_data, |         SyncProcTexValueLUT(Pica::g_state.proctex.noise_table, proctex_noise_lut_data, | ||||||
|                             proctex_noise_lut_buffer.handle); |                             uniform_block_data.data.proctex_noise_lut_offset); | ||||||
|         uniform_block_data.proctex_noise_lut_dirty = false; |         uniform_block_data.proctex_noise_lut_dirty = false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Sync the proctex color map
 |     // Sync the proctex color map
 | ||||||
|     if (uniform_block_data.proctex_color_map_dirty) { |     if (uniform_block_data.proctex_color_map_dirty || invalidate) { | ||||||
|         SyncProcTexValueLUT(Pica::g_state.proctex.color_map_table, proctex_color_map_data, |         SyncProcTexValueLUT(Pica::g_state.proctex.color_map_table, proctex_color_map_data, | ||||||
|                             proctex_color_map_buffer.handle); |                             uniform_block_data.data.proctex_color_map_offset); | ||||||
|         uniform_block_data.proctex_color_map_dirty = false; |         uniform_block_data.proctex_color_map_dirty = false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Sync the proctex alpha map
 |     // Sync the proctex alpha map
 | ||||||
|     if (uniform_block_data.proctex_alpha_map_dirty) { |     if (uniform_block_data.proctex_alpha_map_dirty || invalidate) { | ||||||
|         SyncProcTexValueLUT(Pica::g_state.proctex.alpha_map_table, proctex_alpha_map_data, |         SyncProcTexValueLUT(Pica::g_state.proctex.alpha_map_table, proctex_alpha_map_data, | ||||||
|                             proctex_alpha_map_buffer.handle); |                             uniform_block_data.data.proctex_alpha_map_offset); | ||||||
|         uniform_block_data.proctex_alpha_map_dirty = false; |         uniform_block_data.proctex_alpha_map_dirty = false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -291,17 +291,8 @@ private: | ||||||
| 
 | 
 | ||||||
|     std::array<std::array<GLvec2, 256>, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{}; |     std::array<std::array<GLvec2, 256>, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{}; | ||||||
|     std::array<GLvec2, 128> fog_lut_data{}; |     std::array<GLvec2, 128> fog_lut_data{}; | ||||||
| 
 |  | ||||||
|     OGLBuffer proctex_noise_lut_buffer; |  | ||||||
|     OGLTexture proctex_noise_lut; |  | ||||||
|     std::array<GLvec2, 128> proctex_noise_lut_data{}; |     std::array<GLvec2, 128> proctex_noise_lut_data{}; | ||||||
| 
 |  | ||||||
|     OGLBuffer proctex_color_map_buffer; |  | ||||||
|     OGLTexture proctex_color_map; |  | ||||||
|     std::array<GLvec2, 128> proctex_color_map_data{}; |     std::array<GLvec2, 128> proctex_color_map_data{}; | ||||||
| 
 |  | ||||||
|     OGLBuffer proctex_alpha_map_buffer; |  | ||||||
|     OGLTexture proctex_alpha_map; |  | ||||||
|     std::array<GLvec2, 128> proctex_alpha_map_data{}; |     std::array<GLvec2, 128> proctex_alpha_map_data{}; | ||||||
| 
 | 
 | ||||||
|     OGLBuffer proctex_lut_buffer; |     OGLBuffer proctex_lut_buffer; | ||||||
|  |  | ||||||
|  | @ -1113,8 +1113,8 @@ float ProcTexNoiseCoef(vec2 x) { | ||||||
|     float g2 = ProcTexNoiseRand2D(point + vec2(0.0, 1.0)) * (frac.x + frac.y - 1.0); |     float g2 = ProcTexNoiseRand2D(point + vec2(0.0, 1.0)) * (frac.x + frac.y - 1.0); | ||||||
|     float g3 = ProcTexNoiseRand2D(point + vec2(1.0, 1.0)) * (frac.x + frac.y - 2.0); |     float g3 = ProcTexNoiseRand2D(point + vec2(1.0, 1.0)) * (frac.x + frac.y - 2.0); | ||||||
| 
 | 
 | ||||||
|     float x_noise = ProcTexLookupLUT(proctex_noise_lut, proctex_noise_lut_offset, frac.x); |     float x_noise = ProcTexLookupLUT(texture_buffer_lut_rg, proctex_noise_lut_offset, frac.x); | ||||||
|     float y_noise = ProcTexLookupLUT(proctex_noise_lut, proctex_noise_lut_offset, frac.y); |     float y_noise = ProcTexLookupLUT(texture_buffer_lut_rg, proctex_noise_lut_offset, frac.y); | ||||||
|     float x0 = mix(g0, g1, x_noise); |     float x0 = mix(g0, g1, x_noise); | ||||||
|     float x1 = mix(g2, g3, x_noise); |     float x1 = mix(g2, g3, x_noise); | ||||||
|     return mix(x0, x1, y_noise); |     return mix(x0, x1, y_noise); | ||||||
|  | @ -1156,7 +1156,7 @@ float ProcTexNoiseCoef(vec2 x) { | ||||||
| 
 | 
 | ||||||
|     // Combine and map
 |     // Combine and map
 | ||||||
|     out += "float lut_coord = "; |     out += "float lut_coord = "; | ||||||
|     AppendProcTexCombineAndMap(out, config.state.proctex.color_combiner, "proctex_color_map", |     AppendProcTexCombineAndMap(out, config.state.proctex.color_combiner, "texture_buffer_lut_rg", | ||||||
|                                "proctex_color_map_offset"); |                                "proctex_color_map_offset"); | ||||||
|     out += ";\n"; |     out += ";\n"; | ||||||
| 
 | 
 | ||||||
|  | @ -1188,8 +1188,8 @@ float ProcTexNoiseCoef(vec2 x) { | ||||||
|         // Note: in separate alpha mode, the alpha channel skips the color LUT look up stage. It
 |         // Note: in separate alpha mode, the alpha channel skips the color LUT look up stage. It
 | ||||||
|         // uses the output of CombineAndMap directly instead.
 |         // uses the output of CombineAndMap directly instead.
 | ||||||
|         out += "float final_alpha = "; |         out += "float final_alpha = "; | ||||||
|         AppendProcTexCombineAndMap(out, config.state.proctex.alpha_combiner, "proctex_alpha_map", |         AppendProcTexCombineAndMap(out, config.state.proctex.alpha_combiner, | ||||||
|                                    "proctex_alpha_map_offset"); |                                    "texture_buffer_lut_rg", "proctex_alpha_map_offset"); | ||||||
|         out += ";\n"; |         out += ";\n"; | ||||||
|         out += "return vec4(final_color.xyz, final_alpha);\n}\n"; |         out += "return vec4(final_color.xyz, final_alpha);\n}\n"; | ||||||
|     } else { |     } else { | ||||||
|  | @ -1224,9 +1224,6 @@ uniform sampler2D tex2; | ||||||
| uniform samplerCube tex_cube; | uniform samplerCube tex_cube; | ||||||
| uniform samplerBuffer texture_buffer_lut_rg; | uniform samplerBuffer texture_buffer_lut_rg; | ||||||
| uniform samplerBuffer texture_buffer_lut_rgba; | uniform samplerBuffer texture_buffer_lut_rgba; | ||||||
| uniform samplerBuffer proctex_noise_lut; |  | ||||||
| uniform samplerBuffer proctex_color_map; |  | ||||||
| uniform samplerBuffer proctex_alpha_map; |  | ||||||
| uniform samplerBuffer proctex_lut; | uniform samplerBuffer proctex_lut; | ||||||
| uniform samplerBuffer proctex_diff_lut; | uniform samplerBuffer proctex_diff_lut; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -57,9 +57,6 @@ static void SetShaderSamplerBindings(GLuint shader) { | ||||||
|     // Set the texture samplers to correspond to different lookup table texture units
 |     // Set the texture samplers to correspond to different lookup table texture units
 | ||||||
|     SetShaderSamplerBinding(shader, "texture_buffer_lut_rg", TextureUnits::TextureBufferLUT_RG); |     SetShaderSamplerBinding(shader, "texture_buffer_lut_rg", TextureUnits::TextureBufferLUT_RG); | ||||||
|     SetShaderSamplerBinding(shader, "texture_buffer_lut_rgba", TextureUnits::TextureBufferLUT_RGBA); |     SetShaderSamplerBinding(shader, "texture_buffer_lut_rgba", TextureUnits::TextureBufferLUT_RGBA); | ||||||
|     SetShaderSamplerBinding(shader, "proctex_noise_lut", TextureUnits::ProcTexNoiseLUT); |  | ||||||
|     SetShaderSamplerBinding(shader, "proctex_color_map", TextureUnits::ProcTexColorMap); |  | ||||||
|     SetShaderSamplerBinding(shader, "proctex_alpha_map", TextureUnits::ProcTexAlphaMap); |  | ||||||
|     SetShaderSamplerBinding(shader, "proctex_lut", TextureUnits::ProcTexLUT); |     SetShaderSamplerBinding(shader, "proctex_lut", TextureUnits::ProcTexLUT); | ||||||
|     SetShaderSamplerBinding(shader, "proctex_diff_lut", TextureUnits::ProcTexDiffLUT); |     SetShaderSamplerBinding(shader, "proctex_diff_lut", TextureUnits::ProcTexDiffLUT); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -60,9 +60,6 @@ OpenGLState::OpenGLState() { | ||||||
| 
 | 
 | ||||||
|     proctex_lut.texture_buffer = 0; |     proctex_lut.texture_buffer = 0; | ||||||
|     proctex_diff_lut.texture_buffer = 0; |     proctex_diff_lut.texture_buffer = 0; | ||||||
|     proctex_color_map.texture_buffer = 0; |  | ||||||
|     proctex_alpha_map.texture_buffer = 0; |  | ||||||
|     proctex_noise_lut.texture_buffer = 0; |  | ||||||
| 
 | 
 | ||||||
|     image_shadow_buffer = 0; |     image_shadow_buffer = 0; | ||||||
|     image_shadow_texture_px = 0; |     image_shadow_texture_px = 0; | ||||||
|  | @ -233,24 +230,6 @@ void OpenGLState::Apply() const { | ||||||
|         glBindTexture(GL_TEXTURE_BUFFER, texture_buffer_lut_rgba.texture_buffer); |         glBindTexture(GL_TEXTURE_BUFFER, texture_buffer_lut_rgba.texture_buffer); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // ProcTex Noise LUT
 |  | ||||||
|     if (proctex_noise_lut.texture_buffer != cur_state.proctex_noise_lut.texture_buffer) { |  | ||||||
|         glActiveTexture(TextureUnits::ProcTexNoiseLUT.Enum()); |  | ||||||
|         glBindTexture(GL_TEXTURE_BUFFER, proctex_noise_lut.texture_buffer); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // ProcTex Color Map
 |  | ||||||
|     if (proctex_color_map.texture_buffer != cur_state.proctex_color_map.texture_buffer) { |  | ||||||
|         glActiveTexture(TextureUnits::ProcTexColorMap.Enum()); |  | ||||||
|         glBindTexture(GL_TEXTURE_BUFFER, proctex_color_map.texture_buffer); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // ProcTex Alpha Map
 |  | ||||||
|     if (proctex_alpha_map.texture_buffer != cur_state.proctex_alpha_map.texture_buffer) { |  | ||||||
|         glActiveTexture(TextureUnits::ProcTexAlphaMap.Enum()); |  | ||||||
|         glBindTexture(GL_TEXTURE_BUFFER, proctex_alpha_map.texture_buffer); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // ProcTex LUT
 |     // ProcTex LUT
 | ||||||
|     if (proctex_lut.texture_buffer != cur_state.proctex_lut.texture_buffer) { |     if (proctex_lut.texture_buffer != cur_state.proctex_lut.texture_buffer) { | ||||||
|         glActiveTexture(TextureUnits::ProcTexLUT.Enum()); |         glActiveTexture(TextureUnits::ProcTexLUT.Enum()); | ||||||
|  | @ -378,12 +357,6 @@ OpenGLState& OpenGLState::ResetTexture(GLuint handle) { | ||||||
|         texture_buffer_lut_rg.texture_buffer = 0; |         texture_buffer_lut_rg.texture_buffer = 0; | ||||||
|     if (texture_buffer_lut_rgba.texture_buffer == handle) |     if (texture_buffer_lut_rgba.texture_buffer == handle) | ||||||
|         texture_buffer_lut_rgba.texture_buffer = 0; |         texture_buffer_lut_rgba.texture_buffer = 0; | ||||||
|     if (proctex_noise_lut.texture_buffer == handle) |  | ||||||
|         proctex_noise_lut.texture_buffer = 0; |  | ||||||
|     if (proctex_color_map.texture_buffer == handle) |  | ||||||
|         proctex_color_map.texture_buffer = 0; |  | ||||||
|     if (proctex_alpha_map.texture_buffer == handle) |  | ||||||
|         proctex_alpha_map.texture_buffer = 0; |  | ||||||
|     if (proctex_lut.texture_buffer == handle) |     if (proctex_lut.texture_buffer == handle) | ||||||
|         proctex_lut.texture_buffer = 0; |         proctex_lut.texture_buffer = 0; | ||||||
|     if (proctex_diff_lut.texture_buffer == handle) |     if (proctex_diff_lut.texture_buffer == handle) | ||||||
|  |  | ||||||
|  | @ -20,9 +20,6 @@ constexpr TextureUnit PicaTexture(int unit) { | ||||||
|     return TextureUnit{unit}; |     return TextureUnit{unit}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| constexpr TextureUnit ProcTexNoiseLUT{5}; |  | ||||||
| constexpr TextureUnit ProcTexColorMap{6}; |  | ||||||
| constexpr TextureUnit ProcTexAlphaMap{7}; |  | ||||||
| constexpr TextureUnit ProcTexLUT{8}; | constexpr TextureUnit ProcTexLUT{8}; | ||||||
| constexpr TextureUnit ProcTexDiffLUT{9}; | constexpr TextureUnit ProcTexDiffLUT{9}; | ||||||
| constexpr TextureUnit TextureCube{10}; | constexpr TextureUnit TextureCube{10}; | ||||||
|  | @ -111,18 +108,6 @@ public: | ||||||
|         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 |         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 | ||||||
|     } texture_buffer_lut_rgba; |     } texture_buffer_lut_rgba; | ||||||
| 
 | 
 | ||||||
|     struct { |  | ||||||
|         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 |  | ||||||
|     } proctex_noise_lut; |  | ||||||
| 
 |  | ||||||
|     struct { |  | ||||||
|         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 |  | ||||||
|     } proctex_color_map; |  | ||||||
| 
 |  | ||||||
|     struct { |  | ||||||
|         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 |  | ||||||
|     } proctex_alpha_map; |  | ||||||
| 
 |  | ||||||
|     struct { |     struct { | ||||||
|         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 |         GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
 | ||||||
|     } proctex_lut; |     } proctex_lut; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue