streamlined text rendering

This commit is contained in:
devZoGok
2026-07-11 11:02:57 +03:00
parent 72b9007693
commit e29dad91d3
7 changed files with 41 additions and 166 deletions
+15 -7
View File
@@ -140,7 +140,7 @@ namespace vb01{
}
//TODO check loading of textures with different dimensions
void Root::initTextureDataOnGpu(u8 *data, int width, int height, int &bufferId, int &layerId, bool scene, int w, int h){
void Root::initTextureDataOnGpu(u8 *data, int width, int height, int &bufferId, int &layerId, bool scene, bool singleChannel, int w, int h){
int textureUnitId = -1;
vector<TextureUnitGpuData> &textureData = (scene ? meshTextureData : guiTextureData);
@@ -156,6 +156,8 @@ namespace vb01{
glGenTextures(1, &textureData[textureUnitId].buffer);
}
GLint texelFormat = (singleChannel ? GL_RED : GL_RGB);
for(int i = 0; i < textureData.size(); i++){
TextureUnitGpuData &texData = textureData[i];
@@ -163,7 +165,7 @@ namespace vb01{
u8 background[numPixels]{0};
glBindTexture(GL_TEXTURE_2D_ARRAY, texData.buffer);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RED, texData.width, texData.height, texData.imageData.size() + 1, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, texelFormat, texData.width, texData.height, texData.imageData.size() + 1, 0, texelFormat, GL_UNSIGNED_BYTE, NULL);
int dims[]{texData.width, texData.height};
@@ -171,10 +173,10 @@ namespace vb01{
if(!(texData.subDims[j].first == 0 && texData.subDims[j].second == 0)){
dims[0] = texData.subDims[j].first;
dims[1] = texData.subDims[j].second;
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, texData.width, texData.height, 1, texelFormat, GL_UNSIGNED_BYTE, background);
}
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, texData.width, texData.height, 1, GL_RED, GL_UNSIGNED_BYTE, background);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, dims[0], dims[1], 1, GL_RED, GL_UNSIGNED_BYTE, texData.imageData[j]);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, dims[0], dims[1], 1, texelFormat, GL_UNSIGNED_BYTE, texData.imageData[j]);
}
if(textureUnitId == i){
@@ -187,10 +189,12 @@ namespace vb01{
texData.imageData.push_back(data);
texData.subDims.push_back(make_pair(w, h));
if(!(w == 0 && h == 0)) dims[0] = w, dims[1] = h;
if(!(w == 0 && h == 0)){
dims[0] = w, dims[1] = h;
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerId, texData.width, texData.height, 1, texelFormat, GL_UNSIGNED_BYTE, background);
}
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerId, texData.width, texData.height, 1, GL_RED, GL_UNSIGNED_BYTE, background);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerId, dims[0], dims[1], 1, GL_RED, GL_UNSIGNED_BYTE, data);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerId, dims[0], dims[1], 1, texelFormat, GL_UNSIGNED_BYTE, data);
}
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, scene ? GL_REPEAT : GL_CLAMP_TO_EDGE);
@@ -288,6 +292,8 @@ namespace vb01{
gui.scale[0] = scale.x;
gui.scale[1] = scale.y;
gui.scale[2] = scale.z;
gui.size[0] = glyph.size.x / size.x;
gui.size[1] = glyph.size.y / size.y;
const Texture::Frame &frame = ((Material::TextureUniform*)charac.material->getUniform("glyphTexture"))->value->getFrame(0);
gui.glyphTexture[0] = frame.bufferId;
@@ -395,6 +401,8 @@ namespace vb01{
gui.pos[0] = pos.x;
gui.pos[1] = pos.y;
gui.pos[2] = pos.z;
gui.size[0] = 1;
gui.size[1] = 1;
gui.glyphTexture[0] = -1;
gui.glyphTexture[1] = -1;
gui.texturingEnabled = texturingEnabled;