Commit 1606dd39 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move the OpenGL texture format to struct wined3d_format_gl.

parent 3ad933d5
......@@ -3868,6 +3868,7 @@ static void context_bind_unordered_access_views(struct wined3d_context *context,
{
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_unordered_access_view *view;
const struct wined3d_format_gl *format_gl;
GLuint texture_name;
unsigned int i;
GLint level;
......@@ -3903,8 +3904,9 @@ static void context_bind_unordered_access_views(struct wined3d_context *context,
continue;
}
format_gl = wined3d_format_gl(view->format);
GL_EXTCALL(glBindImageTexture(i, texture_name, level, GL_TRUE, 0, GL_READ_WRITE,
view->format->glInternal));
format_gl->internal));
if (view->counter_bo)
GL_EXTCALL(glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, view->counter_bo));
......
......@@ -348,22 +348,24 @@ static BOOL fbo_blitter_supported(enum wined3d_blit_op blit_op, const struct win
static void texture2d_download_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
const struct wined3d_context *context, DWORD dst_location)
{
const struct wined3d_format *format = texture->resource.format;
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_texture_sub_resource *sub_resource;
unsigned int dst_row_pitch, dst_slice_pitch;
unsigned int src_row_pitch, src_slice_pitch;
const struct wined3d_format_gl *format_gl;
struct wined3d_bo_address data;
BYTE *temporary_mem = NULL;
unsigned int level;
GLenum target;
void *mem;
format_gl = wined3d_format_gl(texture->resource.format);
/* Only support read back of converted P8 textures. */
if (texture->flags & WINED3D_TEXTURE_CONVERTED && format->id != WINED3DFMT_P8_UINT && !format->download)
if (texture->flags & WINED3D_TEXTURE_CONVERTED && format_gl->f.id != WINED3DFMT_P8_UINT && !format_gl->f.download)
{
ERR("Trying to read back converted texture %p, %u with format %s.\n",
texture, sub_resource_idx, debug_d3dformat(format->id));
texture, sub_resource_idx, debug_d3dformat(format_gl->f.id));
return;
}
......@@ -373,7 +375,7 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
if (target == GL_TEXTURE_2D_ARRAY)
{
if (format->download)
if (format_gl->f.download)
{
FIXME("Reading back converted array texture %p is not supported.\n", texture);
return;
......@@ -396,14 +398,14 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
{
if (format->download)
if (format_gl->f.download)
{
FIXME("Reading back converted texture %p with NP2 emulation is not supported.\n", texture);
return;
}
wined3d_texture_get_pitch(texture, level, &dst_row_pitch, &dst_slice_pitch);
wined3d_format_calculate_pitch(format, texture->resource.device->surface_alignment,
wined3d_format_calculate_pitch(&format_gl->f, texture->resource.device->surface_alignment,
wined3d_texture_get_level_pow2_width(texture, level),
wined3d_texture_get_level_pow2_height(texture, level),
&src_row_pitch, &src_slice_pitch);
......@@ -419,7 +421,7 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
ERR("Unexpected compressed format for NP2 emulated texture.\n");
}
if (format->download)
if (format_gl->f.download)
{
struct wined3d_format f;
......@@ -427,10 +429,10 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
ERR("Converted texture %p uses PBO unexpectedly.\n", texture);
WARN_(d3d_perf)("Downloading converted texture %p, %u with format %s.\n",
texture, sub_resource_idx, debug_d3dformat(format->id));
texture, sub_resource_idx, debug_d3dformat(format_gl->f.id));
f = *format;
f.byte_count = format->conv_byte_count;
f = format_gl->f;
f.byte_count = format_gl->f.conv_byte_count;
wined3d_texture_get_pitch(texture, level, &dst_row_pitch, &dst_slice_pitch);
wined3d_format_calculate_pitch(&f, texture->resource.device->surface_alignment,
wined3d_texture_get_level_width(texture, level),
......@@ -462,7 +464,7 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
{
TRACE("Downloading compressed texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
texture, sub_resource_idx, level, format->glFormat, format->glType, mem);
texture, sub_resource_idx, level, format_gl->format, format_gl->type, mem);
GL_EXTCALL(glGetCompressedTexImage(target, level, mem));
checkGLcall("glGetCompressedTexImage");
......@@ -470,15 +472,15 @@ static void texture2d_download_data(struct wined3d_texture *texture, unsigned in
else
{
TRACE("Downloading texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
texture, sub_resource_idx, level, format->glFormat, format->glType, mem);
texture, sub_resource_idx, level, format_gl->format, format_gl->type, mem);
gl_info->gl_ops.gl.p_glGetTexImage(target, level, format->glFormat, format->glType, mem);
gl_info->gl_ops.gl.p_glGetTexImage(target, level, format_gl->format, format_gl->type, mem);
checkGLcall("glGetTexImage");
}
if (format->download)
if (format_gl->f.download)
{
format->download(mem, data.addr, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch,
format_gl->f.download(mem, data.addr, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch,
wined3d_texture_get_level_width(texture, level),
wined3d_texture_get_level_height(texture, level), 1);
}
......@@ -931,7 +933,9 @@ static struct wined3d_texture *surface_convert_format(struct wined3d_texture *sr
static void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD src_location, DWORD dst_location)
{
struct wined3d_device *device = texture->resource.device;
struct wined3d_resource *resource = &texture->resource;
struct wined3d_device *device = resource->device;
const struct wined3d_format_gl *format_gl;
struct wined3d_texture *restore_texture;
const struct wined3d_gl_info *gl_info;
unsigned int row_pitch, slice_pitch;
......@@ -953,10 +957,10 @@ static void texture2d_read_from_framebuffer(struct wined3d_texture *texture, uns
restore_texture = NULL;
gl_info = context->gl_info;
if (src_location != texture->resource.draw_binding)
if (src_location != resource->draw_binding)
{
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER,
&texture->resource, sub_resource_idx, NULL, 0, src_location);
resource, sub_resource_idx, NULL, 0, src_location);
context_check_fbo_status(context, GL_READ_FRAMEBUFFER);
context_invalidate_state(context, STATE_FRAMEBUFFER);
}
......@@ -969,7 +973,7 @@ static void texture2d_read_from_framebuffer(struct wined3d_texture *texture, uns
* There is no need to keep track of the current read buffer or reset it,
* every part of the code that reads sets the read buffer as desired.
*/
if (src_location != WINED3D_LOCATION_DRAWABLE || wined3d_resource_is_offscreen(&texture->resource))
if (src_location != WINED3D_LOCATION_DRAWABLE || wined3d_resource_is_offscreen(resource))
{
/* Mapping the primary render target which is not on a swapchain.
* Read from the back buffer. */
......@@ -995,16 +999,16 @@ static void texture2d_read_from_framebuffer(struct wined3d_texture *texture, uns
level = sub_resource_idx % texture->level_count;
wined3d_texture_get_pitch(texture, level, &row_pitch, &slice_pitch);
format_gl = wined3d_format_gl(resource->format);
/* Setup pixel store pack state -- to glReadPixels into the correct place */
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, row_pitch / texture->resource.format->byte_count);
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ROW_LENGTH, row_pitch / format_gl->f.byte_count);
checkGLcall("glPixelStorei");
width = wined3d_texture_get_level_width(texture, level);
height = wined3d_texture_get_level_height(texture, level);
gl_info->gl_ops.gl.p_glReadPixels(0, 0, width, height,
texture->resource.format->glFormat,
texture->resource.format->glType, data.addr);
format_gl->format, format_gl->type, data.addr);
checkGLcall("glReadPixels");
/* Reset previous pixel store pack state */
......
......@@ -169,11 +169,13 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
const struct wined3d_view_desc *desc, struct wined3d_texture *texture,
const struct wined3d_format *view_format)
{
const struct wined3d_format_gl *view_format_gl;
unsigned int level_idx, layer_idx, layer_count;
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
GLuint texture_name;
view_format_gl = wined3d_format_gl(view_format);
view->target = view_target;
context = context_acquire(texture->resource.device, NULL, 0);
......@@ -201,11 +203,11 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
}
gl_info->gl_ops.gl.p_glGenTextures(1, &view->name);
GL_EXTCALL(glTextureView(view->name, view->target, texture_name, view_format->glInternal,
GL_EXTCALL(glTextureView(view->name, view->target, texture_name, view_format_gl->internal,
level_idx, desc->u.texture.level_count, layer_idx, layer_count));
checkGLcall("create texture view");
if (is_stencil_view_format(view_format))
if (is_stencil_view_format(&view_format_gl->f))
{
static const GLint swizzle[] = {GL_ZERO, GL_RED, GL_ZERO, GL_ZERO};
......@@ -233,6 +235,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
unsigned int offset, unsigned int size)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_format_gl *view_format_gl;
if (!gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
{
......@@ -247,6 +250,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
return;
}
view_format_gl = wined3d_format_gl(view_format);
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
view->target = GL_TEXTURE_BUFFER;
......@@ -255,14 +259,14 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
context_bind_texture(context, GL_TEXTURE_BUFFER, view->name);
if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE])
{
GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format->glInternal,
GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal,
buffer->buffer_object, offset, size));
}
else
{
if (offset || size != buffer->resource.size)
FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n");
GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format->glInternal, buffer->buffer_object));
GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer->buffer_object));
}
checkGLcall("Create buffer texture");
......@@ -1006,7 +1010,7 @@ void wined3d_unordered_access_view_clear_uint(struct wined3d_unordered_access_vi
const struct wined3d_uvec4 *clear_value, struct wined3d_context *context)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_format *format;
const struct wined3d_format_gl *format;
struct wined3d_resource *resource;
struct wined3d_buffer *buffer;
unsigned int offset, size;
......@@ -1024,12 +1028,12 @@ void wined3d_unordered_access_view_clear_uint(struct wined3d_unordered_access_vi
return;
}
format = view->format;
if (format->id != WINED3DFMT_R32_UINT && format->id != WINED3DFMT_R32_SINT
&& format->id != WINED3DFMT_R32G32B32A32_UINT
&& format->id != WINED3DFMT_R32G32B32A32_SINT)
format = wined3d_format_gl(view->format);
if (format->f.id != WINED3DFMT_R32_UINT && format->f.id != WINED3DFMT_R32_SINT
&& format->f.id != WINED3DFMT_R32G32B32A32_UINT
&& format->f.id != WINED3DFMT_R32G32B32A32_SINT)
{
FIXME("Not implemented for format %s.\n", debug_d3dformat(format->id));
FIXME("Not implemented for format %s.\n", debug_d3dformat(format->f.id));
return;
}
......@@ -1037,10 +1041,10 @@ void wined3d_unordered_access_view_clear_uint(struct wined3d_unordered_access_vi
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
wined3d_unordered_access_view_invalidate_location(view, ~WINED3D_LOCATION_BUFFER);
get_buffer_view_range(buffer, &view->desc, format, &offset, &size);
get_buffer_view_range(buffer, &view->desc, &format->f, &offset, &size);
context_bind_bo(context, buffer->buffer_type_hint, buffer->buffer_object);
GL_EXTCALL(glClearBufferSubData(buffer->buffer_type_hint, format->glInternal,
offset, size, format->glFormat, format->glType, clear_value));
GL_EXTCALL(glClearBufferSubData(buffer->buffer_type_hint, format->internal,
offset, size, format->format, format->type, clear_value));
checkGLcall("clear unordered access view");
}
......
......@@ -4339,11 +4339,6 @@ struct wined3d_format
enum wined3d_ffp_emit_idx emit_idx;
GLint glInternal;
GLint glGammaInternal;
GLint rtInternal;
GLint glFormat;
GLint glType;
UINT conv_byte_count;
DWORD multisample_types;
unsigned int flags[WINED3D_GL_RES_TYPE_COUNT];
......@@ -4387,6 +4382,12 @@ struct wined3d_format_gl
GLenum vtx_type;
GLint vtx_format;
GLint internal;
GLint srgb_internal;
GLint rt_internal;
GLint format;
GLint type;
GLenum view_class;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment