shm: ensure we use right gl unpack alignment (#12975)
gl defaults to 4 and not all formats is divisible with 4 meaning its going to pad out ouf bounds and cause issues. check if the stride is divisible with 4 otherwise set it to 1, aka disable it. GL_UNPACK_ALIGNMENT only takes 1,2,4,8 but formats like RGB888 has bytesPerBlock 3.
This commit is contained in:
parent
8d03fcc8d7
commit
e43f949f8a
1 changed files with 23 additions and 2 deletions
|
|
@ -76,9 +76,19 @@ void CTexture::createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t strid
|
||||||
if (format->swizzle.has_value())
|
if (format->swizzle.has_value())
|
||||||
swizzle(format->swizzle.value());
|
swizzle(format->swizzle.value());
|
||||||
|
|
||||||
|
bool alignmentChanged = false;
|
||||||
|
if (format->bytesPerBlock != 4) {
|
||||||
|
const GLint alignment = (stride % 4 == 0) ? 4 : 1;
|
||||||
|
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, alignment));
|
||||||
|
alignmentChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock));
|
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock));
|
||||||
GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, size_.x, size_.y, 0, format->glFormat, format->glType, pixels));
|
GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, size_.x, size_.y, 0, format->glFormat, format->glType, pixels));
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
|
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
|
||||||
|
if (alignmentChanged)
|
||||||
|
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 4));
|
||||||
|
|
||||||
unbind();
|
unbind();
|
||||||
|
|
||||||
if (m_keepDataCopy) {
|
if (m_keepDataCopy) {
|
||||||
|
|
@ -130,8 +140,16 @@ void CTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, cons
|
||||||
if (format->swizzle.has_value())
|
if (format->swizzle.has_value())
|
||||||
swizzle(format->swizzle.value());
|
swizzle(format->swizzle.value());
|
||||||
|
|
||||||
damage.copy().intersect(CBox{{}, m_size}).forEachRect([&format, &stride, &pixels](const auto& rect) {
|
bool alignmentChanged = false;
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock));
|
if (format->bytesPerBlock != 4) {
|
||||||
|
const GLint alignment = (stride % 4 == 0) ? 4 : 1;
|
||||||
|
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, alignment));
|
||||||
|
alignmentChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / format->bytesPerBlock));
|
||||||
|
|
||||||
|
damage.copy().intersect(CBox{{}, m_size}).forEachRect([&format, &pixels](const auto& rect) {
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rect.x1));
|
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rect.x1));
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rect.y1));
|
GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rect.y1));
|
||||||
|
|
||||||
|
|
@ -140,6 +158,9 @@ void CTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, cons
|
||||||
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x1, rect.y1, width, height, format->glFormat, format->glType, pixels));
|
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x1, rect.y1, width, height, format->glFormat, format->glType, pixels));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (alignmentChanged)
|
||||||
|
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 4));
|
||||||
|
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
|
GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0));
|
GLCALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0));
|
||||||
GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0));
|
GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue