Split glTexImage2D and update via glTexSubImage2D.
From the doc, it might allow for better performance. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
1905590b27
commit
b204dc5362
3 changed files with 17 additions and 4 deletions
|
@ -24,7 +24,17 @@ GL_BGRA_EXT: it uses a shader to swap the color bytes
|
|||
For simplicity (and because it just works) here we are using these 2 extensions.
|
||||
*/
|
||||
|
||||
void LoadTextureFromData(GLuint texture, const uint8_t * data, size_t width, size_t height, size_t pitch)
|
||||
void allocateTexture(GLuint texture, size_t width, size_t height)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h
|
||||
const GLenum type = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, nullptr);
|
||||
|
||||
}
|
||||
|
||||
void loadTextureFromData(GLuint texture, const uint8_t * data, size_t width, size_t height, size_t pitch)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glPixelStorei(UGL_UNPACK_LENGTH, pitch); // in pixels
|
||||
|
@ -37,7 +47,7 @@ void LoadTextureFromData(GLuint texture, const uint8_t * data, size_t width, siz
|
|||
|
||||
const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h
|
||||
const GLenum type = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
|
||||
// reset to default state
|
||||
glPixelStorei(UGL_UNPACK_LENGTH, 0);
|
||||
}
|
||||
|
|
|
@ -3,4 +3,5 @@
|
|||
#include <cstddef>
|
||||
#include "frontends/sdl/imgui/gles.h"
|
||||
|
||||
void LoadTextureFromData(GLuint texture, const uint8_t * data, size_t width, size_t height, size_t pitch);
|
||||
void allocateTexture(GLuint texture, size_t width, size_t height);
|
||||
void loadTextureFromData(GLuint texture, const uint8_t * data, size_t width, size_t height, size_t pitch);
|
||||
|
|
|
@ -109,6 +109,8 @@ SDLImGuiFrame::SDLImGuiFrame()
|
|||
|
||||
myPitch = width;
|
||||
myOffset = (width * borderHeight + borderWidth) * sizeof(bgra_t);
|
||||
|
||||
allocateTexture(myTexture, myBorderlessWidth, myBorderlessHeight);
|
||||
}
|
||||
|
||||
SDLImGuiFrame::~SDLImGuiFrame()
|
||||
|
@ -122,7 +124,7 @@ SDLImGuiFrame::~SDLImGuiFrame()
|
|||
|
||||
void SDLImGuiFrame::UpdateTexture()
|
||||
{
|
||||
LoadTextureFromData(myTexture, myFramebuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch);
|
||||
loadTextureFromData(myTexture, myFramebuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch);
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::DrawAppleVideo()
|
||||
|
|
Loading…
Add table
Reference in a new issue