[virglrenderer-devel] [PATCH] renderer: support allocation of compressed 2D textures
ramin.azarmehr at gmail.com
ramin.azarmehr at gmail.com
Fri Jun 15 22:03:09 UTC 2018
From: Ramin Azarmehr <ramin.azarmehr at gmail.com>
The resource_allocate_texture() shall allow allocation of 2D compressed textures.
Example of use-case: the Google Earth app on Android allocates texture tiles with "dxt1_rgb" format to save memory (if S3TC is available).
---
src/vrend_renderer.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 85b68c1..a561f6e 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4810,6 +4810,7 @@ static int vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
{
uint level;
GLenum internalformat, glformat, gltype;
+ bool compressed;
struct vrend_texture *gt = (struct vrend_texture *)gr;
struct pipe_resource *pr = &gr->base;
assert(pr->width0 > 0);
@@ -4841,6 +4842,7 @@ static int vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
internalformat = tex_conv_table[pr->format].internalformat;
glformat = tex_conv_table[pr->format].glformat;
gltype = tex_conv_table[pr->format].gltype;
+ compressed = util_format_is_compressed(pr->format);
if (internalformat == 0) {
fprintf(stderr,"unknown format is %d\n", pr->format);
@@ -4931,9 +4933,17 @@ static int vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
for (level = 0; level <= pr->last_level; level++) {
unsigned mwidth = u_minify(pr->width0, level);
unsigned mheight = u_minify(pr->height0, level);
- glTexImage2D(gr->target, level, internalformat, mwidth,
- gr->target == GL_TEXTURE_1D_ARRAY ? pr->array_size : mheight,
- 0, glformat, gltype, NULL);
+ unsigned comp_size;
+
+ if (compressed) {
+ comp_size = util_format_get_nblocks(pr->format, mwidth, mheight) *
+ util_format_get_blocksize(pr->format);
+ glCompressedTexImage2D(gr->target, level, internalformat, mwidth, mheight,
+ 0, comp_size, NULL);
+ } else {
+ glTexImage2D(gr->target, level, internalformat, mwidth,
+ gr->target == GL_TEXTURE_1D_ARRAY ? pr->array_size : mheight,
+ 0, glformat, gltype, NULL);
}
}
}
--
2.17.1
More information about the virglrenderer-devel
mailing list