[virglrenderer-devel] [PATCH 2/4] vrend: refactor out sized buffer creation.

Dave Airlie airlied at gmail.com
Fri May 18 02:10:19 UTC 2018


From: Dave Airlie <airlied at redhat.com>

This just pulls out some common code
---
 src/vrend_renderer.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 930dede..b492c4d 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4642,6 +4642,14 @@ static int check_resource_valid(struct vrend_renderer_resource_create_args *args
    }
    return 0;
 }
+
+void vrend_create_buffer(struct vrend_resource *gr, uint32_t width)
+{
+   glGenBuffersARB(1, &gr->id);
+   glBindBufferARB(gr->target, gr->id);
+   glBufferData(gr->target, width, NULL, GL_STREAM_DRAW);
+}
+
 int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
 {
    struct vrend_resource *gr;
@@ -4682,29 +4690,19 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
       }
    } else if (args->bind == VREND_RES_BIND_INDEX_BUFFER) {
       gr->target = GL_ELEMENT_ARRAY_BUFFER_ARB;
-      glGenBuffersARB(1, &gr->id);
-      glBindBufferARB(gr->target, gr->id);
-      glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+      vrend_create_buffer(gr, args->width);
    } else if (args->bind == VREND_RES_BIND_STREAM_OUTPUT) {
       gr->target = GL_TRANSFORM_FEEDBACK_BUFFER;
-      glGenBuffersARB(1, &gr->id);
-      glBindBuffer(gr->target, gr->id);
-      glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+      vrend_create_buffer(gr, args->width);
    } else if (args->bind == VREND_RES_BIND_VERTEX_BUFFER) {
       gr->target = GL_ARRAY_BUFFER_ARB;
-      glGenBuffersARB(1, &gr->id);
-      glBindBufferARB(gr->target, gr->id);
-      glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+      vrend_create_buffer(gr, args->width);
    } else if (args->bind == VREND_RES_BIND_CONSTANT_BUFFER) {
       gr->target = GL_UNIFORM_BUFFER;
-      glGenBuffersARB(1, &gr->id);
-      glBindBufferARB(gr->target, gr->id);
-      glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+      vrend_create_buffer(gr, args->width);
    } else if (args->target == PIPE_BUFFER && args->bind == 0) {
       gr->target = GL_ARRAY_BUFFER_ARB;
-      glGenBuffersARB(1, &gr->id);
-      glBindBufferARB(gr->target, gr->id);
-      glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+      vrend_create_buffer(gr, args->width);
    } else if (args->target == PIPE_BUFFER && (args->bind & VREND_RES_BIND_SAMPLER_VIEW)) {
       GLenum internalformat;
 
@@ -4719,19 +4717,16 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
       /* need to check GL version here */
       if (vrend_state.have_arb_or_gles_ext_texture_buffer) {
          gr->target = GL_TEXTURE_BUFFER;
-         glGenBuffersARB(1, &gr->id);
-         glBindBufferARB(gr->target, gr->id);
+         vrend_create_buffer(gr, args->width);
+
          glGenTextures(1, &gr->tbo_tex_id);
-         glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
 
          glBindTexture(gr->target, gr->tbo_tex_id);
          internalformat = tex_conv_table[args->format].internalformat;
          glTexBuffer(gr->target, internalformat, gr->id);
       } else {
          gr->target = GL_PIXEL_PACK_BUFFER_ARB;
-         glGenBuffersARB(1, &gr->id);
-         glBindBufferARB(gr->target, gr->id);
-         glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
+         vrend_create_buffer(gr, args->width);
       }
    } else {
       struct vrend_texture *gt = (struct vrend_texture *)gr;
-- 
2.14.3



More information about the virglrenderer-devel mailing list