diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index 03a31a2e1..6d53fd57d 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -296,7 +296,10 @@ void FHardwareTexture::AllocateBuffer(int w, int h, int texelsize) { glGenBuffers(1, &glBufferID); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glBufferID); - glBufferData(GL_PIXEL_UNPACK_BUFFER, w*h*texelsize, nullptr, GL_STREAM_DRAW); + if (screen->hwcaps & RFL_BUFFER_STORAGE) + glBufferStorage(GL_PIXEL_UNPACK_BUFFER, w*h*texelsize, nullptr, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_CLIENT_STORAGE_BIT); + else + glBufferData(GL_PIXEL_UNPACK_BUFFER, w*h*texelsize, nullptr, GL_STREAM_DRAW); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } } @@ -305,7 +308,16 @@ void FHardwareTexture::AllocateBuffer(int w, int h, int texelsize) uint8_t *FHardwareTexture::MapBuffer() { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glBufferID); - return (uint8_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); + if (screen->hwcaps & RFL_BUFFER_STORAGE) + { + GLint size = -1; + glGetBufferParameteriv(GL_PIXEL_UNPACK_BUFFER, GL_BUFFER_SIZE, &size); + return (uint8_t*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, size, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT); + } + else + { + return (uint8_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); + } } //=========================================================================== diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index 56c5448e6..3773bf89f 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -111,17 +111,12 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) fbtex->SystemTexture[0]->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); mat->AddTextureLayer(PaletteTexture.get()); - - FBBuffer.Resize(screen->GetWidth() * screen->GetHeight()); } - auto buf = (uint8_t*)&FBBuffer[0]; + auto buf = fbtex->SystemTexture[0]->MapBuffer(); + if (!buf) I_FatalError("Unable to map buffer for software rendering"); buffer.SetBuffer(screen->GetWidth(), screen->GetHeight(), screen->GetWidth(), buf); SWRenderer->RenderView(player, &buffer); - - auto pbobuf = fbtex->SystemTexture[0]->MapBuffer(); - if (!pbobuf) I_FatalError("Unable to map buffer for software rendering"); - memcpy(pbobuf, buf, FBBuffer.Size() * (V_IsTrueColor() ? 4 : 1)); fbtex->SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer"); auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); diff --git a/src/swrenderer/r_swscene.h b/src/swrenderer/r_swscene.h index c145a6a16..9c6921ee4 100644 --- a/src/swrenderer/r_swscene.h +++ b/src/swrenderer/r_swscene.h @@ -14,7 +14,6 @@ class SWSceneDrawer { std::unique_ptr PaletteTexture; std::unique_ptr FBTexture[2]; - TArray FBBuffer; int FBTextureIndex = 0; bool FBIsTruecolor = false;