mirror of https://github.com/OpenTTD/OpenTTD
pull/8879/head
parent
c92358527b
commit
f0f96e3103
|
@ -877,6 +877,22 @@ bool OpenGLBackend::InitShaders()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the bound pixel buffer to a specific value.
|
||||||
|
* @param len Length of the buffer.
|
||||||
|
* @param data Value to set.
|
||||||
|
* @tparam T Pixel type.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static void ClearPixelBuffer(size_t len, T data)
|
||||||
|
{
|
||||||
|
T *buf = reinterpret_cast<T *>(_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE));
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
*buf++ = data;
|
||||||
|
}
|
||||||
|
_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the size of the drawing window and allocate matching resources.
|
* Change the size of the drawing window and allocate matching resources.
|
||||||
* @param w New width of the window.
|
* @param w New width of the window.
|
||||||
|
@ -911,14 +927,16 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
|
||||||
if (_glClearBufferSubData != nullptr) {
|
if (_glClearBufferSubData != nullptr) {
|
||||||
_glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_RGBA8, 0, pitch * h * bpp / 8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &black.data);
|
_glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_RGBA8, 0, pitch * h * bpp / 8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &black.data);
|
||||||
} else {
|
} else {
|
||||||
uint32 *buf = (uint32 *)_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
|
ClearPixelBuffer<uint32>(pitch * h, black.data);
|
||||||
for (int i = 0; i < pitch * h; i++) {
|
}
|
||||||
*buf++ = black.data;
|
} else if (bpp == 8) {
|
||||||
}
|
if (_glClearBufferSubData != nullptr) {
|
||||||
_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
byte b = 0;
|
||||||
|
_glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_R8, 0, pitch * h, GL_RED, GL_UNSIGNED_BYTE, &b);
|
||||||
|
} else {
|
||||||
|
ClearPixelBuffer<byte>(pitch * h, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
||||||
|
|
||||||
_glActiveTexture(GL_TEXTURE0);
|
_glActiveTexture(GL_TEXTURE0);
|
||||||
_glBindTexture(GL_TEXTURE_2D, this->vid_texture);
|
_glBindTexture(GL_TEXTURE_2D, this->vid_texture);
|
||||||
|
@ -931,6 +949,7 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
|
||||||
_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
|
_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
|
||||||
/* Does this blitter need a separate animation buffer? */
|
/* Does this blitter need a separate animation buffer? */
|
||||||
if (BlitterFactory::GetCurrentBlitter()->NeedsAnimationBuffer()) {
|
if (BlitterFactory::GetCurrentBlitter()->NeedsAnimationBuffer()) {
|
||||||
|
@ -944,10 +963,18 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
|
||||||
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo);
|
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo);
|
||||||
_glBufferData(GL_PIXEL_UNPACK_BUFFER, pitch * h, nullptr, GL_DYNAMIC_DRAW);
|
_glBufferData(GL_PIXEL_UNPACK_BUFFER, pitch * h, nullptr, GL_DYNAMIC_DRAW);
|
||||||
}
|
}
|
||||||
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
||||||
|
/* Initialize buffer as 0 == no remap. */
|
||||||
|
if (_glClearBufferSubData != nullptr) {
|
||||||
|
byte b = 0;
|
||||||
|
_glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_R8, 0, pitch * h, GL_RED, GL_UNSIGNED_BYTE, &b);
|
||||||
|
} else {
|
||||||
|
ClearPixelBuffer<byte>(pitch * h, 0);
|
||||||
|
}
|
||||||
|
|
||||||
_glBindTexture(GL_TEXTURE_2D, this->anim_texture);
|
_glBindTexture(GL_TEXTURE_2D, this->anim_texture);
|
||||||
_glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, nullptr);
|
_glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, nullptr);
|
||||||
|
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
} else {
|
} else {
|
||||||
if (this->anim_buffer != nullptr) {
|
if (this->anim_buffer != nullptr) {
|
||||||
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo);
|
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo);
|
||||||
|
@ -975,6 +1002,8 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
|
||||||
_glUseProgram(this->remap_program);
|
_glUseProgram(this->remap_program);
|
||||||
_glUniform2f(this->remap_screen_loc, (float)_screen.width, (float)_screen.height);
|
_glUniform2f(this->remap_screen_loc, (float)_screen.width, (float)_screen.height);
|
||||||
|
|
||||||
|
_glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ bool VideoDriver_SDL_OpenGL::AllocateBackingStore(int w, int h, bool force)
|
||||||
MemSetT(&this->dirty_rect, 0);
|
MemSetT(&this->dirty_rect, 0);
|
||||||
|
|
||||||
bool res = OpenGLBackend::Get()->Resize(w, h, force);
|
bool res = OpenGLBackend::Get()->Resize(w, h, force);
|
||||||
|
SDL_GL_SwapWindow(this->sdl_window);
|
||||||
_screen.dst_ptr = this->GetVideoPointer();
|
_screen.dst_ptr = this->GetVideoPointer();
|
||||||
|
|
||||||
_cur_palette.first_dirty = 0;
|
_cur_palette.first_dirty = 0;
|
||||||
|
|
|
@ -1417,6 +1417,7 @@ bool VideoDriver_Win32OpenGL::AllocateBackingStore(int w, int h, bool force)
|
||||||
|
|
||||||
this->dirty_rect = {};
|
this->dirty_rect = {};
|
||||||
bool res = OpenGLBackend::Get()->Resize(w, h, force);
|
bool res = OpenGLBackend::Get()->Resize(w, h, force);
|
||||||
|
SwapBuffers(this->dc);
|
||||||
_screen.dst_ptr = this->GetVideoPointer();
|
_screen.dst_ptr = this->GetVideoPointer();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue