mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 12:04:16 +01:00
gl_rasterizer: Use the shared texture buffer for the lighting lut.
This commit is contained in:
parent
5a9cde138d
commit
4679487640
@ -78,9 +78,6 @@ RasterizerOpenGL::RasterizerOpenGL()
|
||||
uniform_block_data.proctex_lut_dirty = true;
|
||||
uniform_block_data.proctex_diff_lut_dirty = true;
|
||||
|
||||
for (int i = 0; i < 24; i++)
|
||||
uniform_block_data.data.lighting_lut_offset[i / 4][i % 4] = 256 * i;
|
||||
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniform_buffer_alignment);
|
||||
uniform_size_aligned_vs =
|
||||
Common::AlignUp<size_t>(sizeof(VSUniformData), uniform_buffer_alignment);
|
||||
@ -138,18 +135,6 @@ RasterizerOpenGL::RasterizerOpenGL()
|
||||
glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum());
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle());
|
||||
|
||||
// Allocate and bind lighting lut textures
|
||||
lighting_lut.Create();
|
||||
state.lighting_lut.texture_buffer = lighting_lut.handle;
|
||||
state.Apply();
|
||||
lighting_lut_buffer.Create();
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, lighting_lut_buffer.handle);
|
||||
glBufferData(GL_TEXTURE_BUFFER,
|
||||
sizeof(GLfloat) * 2 * 256 * Pica::LightingRegs::NumLightingSampler, nullptr,
|
||||
GL_DYNAMIC_DRAW);
|
||||
glActiveTexture(TextureUnits::LightingLUT.Enum());
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, lighting_lut_buffer.handle);
|
||||
|
||||
// Setup the LUT for the fog
|
||||
fog_lut.Create();
|
||||
state.fog_lut.texture_buffer = fog_lut.handle;
|
||||
@ -1951,10 +1936,25 @@ void RasterizerOpenGL::SyncAndUploadLUTs() {
|
||||
sizeof(GLvec4) * 256 + // proctex
|
||||
sizeof(GLvec4) * 256; // proctex diff
|
||||
|
||||
if (!uniform_block_data.lighting_lut_dirty_any && !uniform_block_data.fog_lut_dirty &&
|
||||
!uniform_block_data.proctex_noise_lut_dirty &&
|
||||
!uniform_block_data.proctex_color_map_dirty &&
|
||||
!uniform_block_data.proctex_alpha_map_dirty && !uniform_block_data.proctex_lut_dirty &&
|
||||
!uniform_block_data.proctex_diff_lut_dirty) {
|
||||
return;
|
||||
}
|
||||
|
||||
u8* buffer;
|
||||
GLintptr offset;
|
||||
bool invalidate;
|
||||
size_t bytes_used = 0;
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, texture_buffer.GetHandle());
|
||||
std::tie(buffer, offset, invalidate) = texture_buffer.Map(max_size, sizeof(GLvec4));
|
||||
|
||||
// Sync the lighting luts
|
||||
if (uniform_block_data.lighting_lut_dirty_any) {
|
||||
if (uniform_block_data.lighting_lut_dirty_any || invalidate) {
|
||||
for (unsigned index = 0; index < uniform_block_data.lighting_lut_dirty.size(); index++) {
|
||||
if (uniform_block_data.lighting_lut_dirty[index]) {
|
||||
if (uniform_block_data.lighting_lut_dirty[index] || invalidate) {
|
||||
std::array<GLvec2, 256> new_data;
|
||||
const auto& source_lut = Pica::g_state.lighting.luts[index];
|
||||
std::transform(source_lut.begin(), source_lut.end(), new_data.begin(),
|
||||
@ -1962,11 +1962,14 @@ void RasterizerOpenGL::SyncAndUploadLUTs() {
|
||||
return GLvec2{entry.ToFloat(), entry.DiffToFloat()};
|
||||
});
|
||||
|
||||
if (new_data != lighting_lut_data[index]) {
|
||||
if (new_data != lighting_lut_data[index] || invalidate) {
|
||||
lighting_lut_data[index] = new_data;
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, lighting_lut_buffer.handle);
|
||||
glBufferSubData(GL_TEXTURE_BUFFER, index * new_data.size() * sizeof(GLvec2),
|
||||
new_data.size() * sizeof(GLvec2), new_data.data());
|
||||
std::memcpy(buffer + bytes_used, new_data.data(),
|
||||
new_data.size() * sizeof(GLvec2));
|
||||
uniform_block_data.data.lighting_lut_offset[index / 4][index % 4] =
|
||||
(offset + bytes_used) / sizeof(GLvec2);
|
||||
uniform_block_data.dirty = true;
|
||||
bytes_used += new_data.size() * sizeof(GLvec2);
|
||||
}
|
||||
uniform_block_data.lighting_lut_dirty[index] = false;
|
||||
}
|
||||
@ -2068,6 +2071,8 @@ void RasterizerOpenGL::SyncAndUploadLUTs() {
|
||||
}
|
||||
uniform_block_data.proctex_diff_lut_dirty = false;
|
||||
}
|
||||
|
||||
texture_buffer.Unmap(bytes_used);
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::UploadUniforms(bool accelerate_draw, bool use_gs) {
|
||||
|
@ -289,8 +289,6 @@ private:
|
||||
OGLTexture texture_buffer_lut_rg;
|
||||
OGLTexture texture_buffer_lut_rgba;
|
||||
|
||||
OGLBuffer lighting_lut_buffer;
|
||||
OGLTexture lighting_lut;
|
||||
std::array<std::array<GLvec2, 256>, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{};
|
||||
|
||||
OGLBuffer fog_lut_buffer;
|
||||
|
@ -1224,7 +1224,6 @@ uniform sampler2D tex2;
|
||||
uniform samplerCube tex_cube;
|
||||
uniform samplerBuffer texture_buffer_lut_rg;
|
||||
uniform samplerBuffer texture_buffer_lut_rgba;
|
||||
uniform samplerBuffer lighting_lut;
|
||||
uniform samplerBuffer fog_lut;
|
||||
uniform samplerBuffer proctex_noise_lut;
|
||||
uniform samplerBuffer proctex_color_map;
|
||||
@ -1252,7 +1251,7 @@ vec3 quaternion_rotate(vec4 q, vec3 v) {
|
||||
}
|
||||
|
||||
float LookupLightingLUT(int lut_index, int index, float delta) {
|
||||
vec2 entry = texelFetch(lighting_lut, lighting_lut_offset[lut_index >> 2][lut_index & 3] + index).rg;
|
||||
vec2 entry = texelFetch(texture_buffer_lut_rg, lighting_lut_offset[lut_index >> 2][lut_index & 3] + index).rg;
|
||||
return entry.r + entry.g * delta;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,6 @@ static void SetShaderSamplerBindings(GLuint shader) {
|
||||
// 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_rgba", TextureUnits::TextureBufferLUT_RGBA);
|
||||
SetShaderSamplerBinding(shader, "lighting_lut", TextureUnits::LightingLUT);
|
||||
SetShaderSamplerBinding(shader, "fog_lut", TextureUnits::FogLUT);
|
||||
SetShaderSamplerBinding(shader, "proctex_noise_lut", TextureUnits::ProcTexNoiseLUT);
|
||||
SetShaderSamplerBinding(shader, "proctex_color_map", TextureUnits::ProcTexColorMap);
|
||||
|
@ -58,8 +58,6 @@ OpenGLState::OpenGLState() {
|
||||
texture_buffer_lut_rg.texture_buffer = 0;
|
||||
texture_buffer_lut_rgba.texture_buffer = 0;
|
||||
|
||||
lighting_lut.texture_buffer = 0;
|
||||
|
||||
fog_lut.texture_buffer = 0;
|
||||
|
||||
proctex_lut.texture_buffer = 0;
|
||||
@ -237,12 +235,6 @@ void OpenGLState::Apply() const {
|
||||
glBindTexture(GL_TEXTURE_BUFFER, texture_buffer_lut_rgba.texture_buffer);
|
||||
}
|
||||
|
||||
// Lighting LUTs
|
||||
if (lighting_lut.texture_buffer != cur_state.lighting_lut.texture_buffer) {
|
||||
glActiveTexture(TextureUnits::LightingLUT.Enum());
|
||||
glBindTexture(GL_TEXTURE_BUFFER, lighting_lut.texture_buffer);
|
||||
}
|
||||
|
||||
// Fog LUT
|
||||
if (fog_lut.texture_buffer != cur_state.fog_lut.texture_buffer) {
|
||||
glActiveTexture(TextureUnits::FogLUT.Enum());
|
||||
@ -394,8 +386,6 @@ OpenGLState& OpenGLState::ResetTexture(GLuint handle) {
|
||||
texture_buffer_lut_rg.texture_buffer = 0;
|
||||
if (texture_buffer_lut_rgba.texture_buffer == handle)
|
||||
texture_buffer_lut_rgba.texture_buffer = 0;
|
||||
if (lighting_lut.texture_buffer == handle)
|
||||
lighting_lut.texture_buffer = 0;
|
||||
if (fog_lut.texture_buffer == handle)
|
||||
fog_lut.texture_buffer = 0;
|
||||
if (proctex_noise_lut.texture_buffer == handle)
|
||||
|
@ -20,7 +20,6 @@ constexpr TextureUnit PicaTexture(int unit) {
|
||||
return TextureUnit{unit};
|
||||
}
|
||||
|
||||
constexpr TextureUnit LightingLUT{3};
|
||||
constexpr TextureUnit FogLUT{4};
|
||||
constexpr TextureUnit ProcTexNoiseLUT{5};
|
||||
constexpr TextureUnit ProcTexColorMap{6};
|
||||
@ -113,10 +112,6 @@ public:
|
||||
GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
|
||||
} texture_buffer_lut_rgba;
|
||||
|
||||
struct {
|
||||
GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
|
||||
} lighting_lut;
|
||||
|
||||
struct {
|
||||
GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
|
||||
} fog_lut;
|
||||
|
Loading…
Reference in New Issue
Block a user