[PATCH 1/2] wined3d: Move the OpenGL vertex format to a separate structure.

Henri Verbeet hverbeet at codeweavers.com
Fri Sep 21 07:41:50 CDT 2018


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/context.c         | 38 +++++++++++++++++++++++++-------------
 dlls/wined3d/utils.c           | 34 +++++++++++++++++++++++++---------
 dlls/wined3d/wined3d_private.h | 15 +++++++++++++--
 3 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 19f0fcbd2b0..167241a6f0f 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -5045,6 +5045,7 @@ void context_load_tex_coords(const struct wined3d_context *context, const struct
         GLuint *current_bo, const struct wined3d_state *state)
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
+    const struct wined3d_format_gl *format_gl;
     unsigned int mapped_stage = 0;
     unsigned int texture_idx;
 
@@ -5079,7 +5080,8 @@ void context_load_tex_coords(const struct wined3d_context *context, const struct
             checkGLcall("glClientActiveTextureARB");
 
             /* The coords to supply depend completely on the fvf/vertex shader. */
-            gl_info->gl_ops.gl.p_glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
+            format_gl = wined3d_format_gl(e->format);
+            gl_info->gl_ops.gl.p_glTexCoordPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
                     e->data.addr + state->load_base_vertex_index * e->stride);
             gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
         }
@@ -5121,6 +5123,7 @@ static void context_load_vertex_data(struct wined3d_context *context,
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
     const struct wined3d_stream_info_element *e;
+    const struct wined3d_format_gl *format_gl;
     GLuint current_bo;
 
     TRACE("context %p, si %p, state %p.\n", context, si, state);
@@ -5151,6 +5154,7 @@ static void context_load_vertex_data(struct wined3d_context *context,
     if (si->use_map & (1u << WINED3D_FFP_POSITION))
     {
         e = &si->elements[WINED3D_FFP_POSITION];
+        format_gl = wined3d_format_gl(e->format);
 
         if (current_bo != e->data.buffer_object)
         {
@@ -5160,9 +5164,9 @@ static void context_load_vertex_data(struct wined3d_context *context,
         }
 
         TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
-                e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
+                format_gl->vtx_format, format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
-        gl_info->gl_ops.gl.p_glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
+        gl_info->gl_ops.gl.p_glVertexPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glVertexPointer(...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
@@ -5173,6 +5177,7 @@ static void context_load_vertex_data(struct wined3d_context *context,
     if (si->use_map & (1u << WINED3D_FFP_NORMAL))
     {
         e = &si->elements[WINED3D_FFP_NORMAL];
+        format_gl = wined3d_format_gl(e->format);
 
         if (current_bo != e->data.buffer_object)
         {
@@ -5181,9 +5186,9 @@ static void context_load_vertex_data(struct wined3d_context *context,
             current_bo = e->data.buffer_object;
         }
 
-        TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
+        TRACE("glNormalPointer(%#x, %#x, %p);\n", format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
-        gl_info->gl_ops.gl.p_glNormalPointer(e->format->gl_vtx_type, e->stride,
+        gl_info->gl_ops.gl.p_glNormalPointer(format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glNormalPointer(...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
@@ -5200,6 +5205,7 @@ static void context_load_vertex_data(struct wined3d_context *context,
     if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
     {
         e = &si->elements[WINED3D_FFP_DIFFUSE];
+        format_gl = wined3d_format_gl(e->format);
 
         if (current_bo != e->data.buffer_object)
         {
@@ -5209,9 +5215,9 @@ static void context_load_vertex_data(struct wined3d_context *context,
         }
 
         TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
-                e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
+                format_gl->vtx_format, format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
-        gl_info->gl_ops.gl.p_glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
+        gl_info->gl_ops.gl.p_glColorPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
                 e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
@@ -5233,8 +5239,12 @@ static void context_load_vertex_data(struct wined3d_context *context,
 
         if (gl_info->supported[EXT_SECONDARY_COLOR])
         {
-            GLenum type = e->format->gl_vtx_type;
-            GLint format = e->format->gl_vtx_format;
+            GLint format;
+            GLenum type;
+
+            format_gl = wined3d_format_gl(e->format);
+            type = format_gl->vtx_type;
+            format = format_gl->vtx_format;
 
             if (current_bo != e->data.buffer_object)
             {
@@ -5342,6 +5352,7 @@ static void context_load_numbered_arrays(struct wined3d_context *context,
     {
         const struct wined3d_stream_info_element *element = &stream_info->elements[i];
         const struct wined3d_stream_state *stream;
+        const struct wined3d_format_gl *format_gl;
 
         if (!(stream_info->use_map & (1u << i)))
         {
@@ -5354,6 +5365,7 @@ static void context_load_numbered_arrays(struct wined3d_context *context,
             continue;
         }
 
+        format_gl = wined3d_format_gl(element->format);
         stream = &state->streams[element->stream_idx];
 
         if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count)
@@ -5376,7 +5388,7 @@ static void context_load_numbered_arrays(struct wined3d_context *context,
 
         if (element->stride)
         {
-            DWORD format_flags = element->format->flags[WINED3D_GL_RES_TYPE_BUFFER];
+            DWORD format_flags = format_gl->f.flags[WINED3D_GL_RES_TYPE_BUFFER];
 
             if (current_bo != element->data.buffer_object)
             {
@@ -5390,12 +5402,12 @@ static void context_load_numbered_arrays(struct wined3d_context *context,
              * won't be load converted attributes anyway. */
             if (vs && vs->reg_maps.shader_version.major >= 4 && (format_flags & WINED3DFMT_FLAG_INTEGER))
             {
-                GL_EXTCALL(glVertexAttribIPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
+                GL_EXTCALL(glVertexAttribIPointer(i, format_gl->vtx_format, format_gl->vtx_type,
                         element->stride, element->data.addr + state->load_base_vertex_index * element->stride));
             }
             else
             {
-                GL_EXTCALL(glVertexAttribPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
+                GL_EXTCALL(glVertexAttribPointer(i, format_gl->vtx_format, format_gl->vtx_type,
                         !!(format_flags & WINED3DFMT_FLAG_NORMALISED), element->stride,
                         element->data.addr + state->load_base_vertex_index * element->stride));
             }
@@ -5419,7 +5431,7 @@ static void context_load_numbered_arrays(struct wined3d_context *context,
             if (context->numbered_array_mask & (1u << i))
                 context_unload_numbered_array(context, i);
 
-            switch (element->format->id)
+            switch (format_gl->f.id)
             {
                 case WINED3DFMT_R32_FLOAT:
                     GL_EXTCALL(glVertexAttrib1fv(i, (const GLfloat *)ptr));
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index bf32953032e..45d1f07b39c 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -1925,6 +1925,11 @@ static inline int get_format_idx(enum wined3d_format_id format_id)
     return -1;
 }
 
+static struct wined3d_format_gl *wined3d_format_gl_mutable(struct wined3d_format *format)
+{
+    return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
+}
+
 static struct wined3d_format *get_format_by_idx(const struct wined3d_adapter *adapter, int fmt_idx)
 {
     return (struct wined3d_format *)((BYTE *)adapter->formats + fmt_idx * adapter->format_size);
@@ -1944,6 +1949,17 @@ static struct wined3d_format *get_format_internal(const struct wined3d_adapter *
     return get_format_by_idx(adapter, fmt_idx);
 }
 
+static struct wined3d_format_gl *get_format_gl_internal(const struct wined3d_adapter *adapter,
+        enum wined3d_format_id format_id)
+{
+    struct wined3d_format *format;
+
+    if ((format = get_format_internal(adapter, format_id)))
+        return wined3d_format_gl_mutable(format);
+
+    return NULL;
+}
+
 static void copy_format(const struct wined3d_adapter *adapter,
         struct wined3d_format *dst_format, const struct wined3d_format *src_format)
 {
@@ -3665,27 +3681,27 @@ static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_
 static BOOL init_format_vertex_info(const struct wined3d_adapter *adapter,
         struct wined3d_gl_info *gl_info)
 {
-    struct wined3d_format *format;
+    struct wined3d_format_gl *format;
     unsigned int i;
 
     for (i = 0; i < ARRAY_SIZE(format_vertex_info); ++i)
     {
-        if (!(format = get_format_internal(adapter, format_vertex_info[i].id)))
+        if (!(format = get_format_gl_internal(adapter, format_vertex_info[i].id)))
             return FALSE;
 
         if (!gl_info->supported[format_vertex_info[i].extension])
             continue;
 
-        format->emit_idx = format_vertex_info[i].emit_idx;
-        format->gl_vtx_type = format_vertex_info[i].gl_vtx_type;
-        format->gl_vtx_format = format->component_count;
-        format->flags[WINED3D_GL_RES_TYPE_BUFFER] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE;
+        format->f.emit_idx = format_vertex_info[i].emit_idx;
+        format->vtx_type = format_vertex_info[i].gl_vtx_type;
+        format->vtx_format = format->f.component_count;
+        format->f.flags[WINED3D_GL_RES_TYPE_BUFFER] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE;
     }
 
     if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
     {
-        format = get_format_internal(adapter, WINED3DFMT_B8G8R8A8_UNORM);
-        format->gl_vtx_format = GL_BGRA;
+        format = get_format_gl_internal(adapter, WINED3DFMT_B8G8R8A8_UNORM);
+        format->vtx_format = GL_BGRA;
     }
 
     return TRUE;
@@ -3968,7 +3984,7 @@ BOOL wined3d_adapter_gl_init_format_info(struct wined3d_adapter *adapter, struct
 {
     struct wined3d_gl_info *gl_info = &adapter->gl_info;
 
-    if (!wined3d_adapter_init_format_info(adapter, sizeof(struct wined3d_format)))
+    if (!wined3d_adapter_init_format_info(adapter, sizeof(struct wined3d_format_gl)))
         return FALSE;
 
     if (!init_format_texture_info(adapter, gl_info)) goto fail;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 637c7218c18..e11d61379c2 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4336,8 +4336,6 @@ struct wined3d_format
     UINT block_byte_count;
 
     enum wined3d_ffp_emit_idx emit_idx;
-    GLenum gl_vtx_type;
-    GLint gl_vtx_format;
 
     GLint glInternal;
     GLint glGammaInternal;
@@ -4381,6 +4379,19 @@ const struct wined3d_color_key_conversion * wined3d_format_get_color_key_convers
 BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1,
         enum wined3d_format_id format2) DECLSPEC_HIDDEN;
 
+struct wined3d_format_gl
+{
+    struct wined3d_format f;
+
+    GLenum vtx_type;
+    GLint vtx_format;
+};
+
+static inline const struct wined3d_format_gl *wined3d_format_gl(const struct wined3d_format *format)
+{
+    return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
+}
+
 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
 
 static inline BOOL wined3d_format_is_typeless(const struct wined3d_format *format)
-- 
2.11.0




More information about the wine-devel mailing list