ReactOS 0.4.15-dev-5672-gf73ac17
sampler.c File Reference
#include "config.h"
#include "wine/port.h"
#include "wined3d_private.h"
Include dependency graph for sampler.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d)
 
ULONG CDECL wined3d_sampler_incref (struct wined3d_sampler *sampler)
 
static void wined3d_sampler_destroy_object (void *object)
 
ULONG CDECL wined3d_sampler_decref (struct wined3d_sampler *sampler)
 
void *CDECL wined3d_sampler_get_parent (const struct wined3d_sampler *sampler)
 
static void wined3d_sampler_cs_init (void *object)
 
static void wined3d_sampler_init (struct wined3d_sampler *sampler, struct wined3d_device *device, const struct wined3d_sampler_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT CDECL wined3d_sampler_create (struct wined3d_device *device, const struct wined3d_sampler_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler)
 
static void texture_apply_base_level (struct wined3d_texture *texture, const struct wined3d_sampler_desc *desc, const struct wined3d_gl_info *gl_info)
 
void wined3d_sampler_bind (struct wined3d_sampler *sampler, unsigned int unit, struct wined3d_texture *texture, const struct wined3d_context *context)
 

Function Documentation

◆ texture_apply_base_level()

static void texture_apply_base_level ( struct wined3d_texture texture,
const struct wined3d_sampler_desc desc,
const struct wined3d_gl_info gl_info 
)
static

Definition at line 158 of file sampler.c.

160{
161 struct gl_texture *gl_tex;
162 unsigned int base_level;
163
165 base_level = 0;
166 else if (desc->mip_filter == WINED3D_TEXF_NONE)
167 base_level = texture->lod;
168 else
169 base_level = min(max(desc->mip_base_level, texture->lod), texture->level_count - 1);
170
172 if (base_level != gl_tex->base_level)
173 {
174 /* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
175 * (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
176 * mipmap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
177 * corresponds to GL_TEXTURE_BASE_LEVEL. */
178 gl_info->gl_ops.gl.p_glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, base_level);
179 gl_tex->base_level = base_level;
180 }
181}
#define GL_TEXTURE_BASE_LEVEL
Definition: gl.h:1503
GLenum GLuint texture
Definition: glext.h:6295
static const WCHAR desc[]
Definition: protectdata.c:36
#define min(a, b)
Definition: monoChain.cc:55
unsigned int base_level
struct opengl_funcs gl_ops
#define max(a, b)
Definition: svc.c:63
@ WINED3D_TEXF_NONE
Definition: wined3d.h:685
#define WINED3D_TEXTURE_COND_NP2
static struct gl_texture * wined3d_texture_get_gl_texture(struct wined3d_texture *texture, BOOL srgb)
#define WINED3D_TEXTURE_IS_SRGB

Referenced by wined3d_sampler_bind().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_sampler_bind()

void wined3d_sampler_bind ( struct wined3d_sampler sampler,
unsigned int  unit,
struct wined3d_texture texture,
const struct wined3d_context context 
)

Definition at line 184 of file sampler.c.

186{
187 const struct wined3d_gl_info *gl_info = context->gl_info;
188
189 if (gl_info->supported[ARB_SAMPLER_OBJECTS])
190 {
191 GL_EXTCALL(glBindSampler(unit, sampler->name));
192 checkGLcall("bind sampler");
193 }
194 else if (texture)
195 {
197 }
198 else
199 {
200 ERR("Could not apply sampler state.\n");
201 }
202
203 if (texture)
204 texture_apply_base_level(texture, &sampler->desc, gl_info);
205}
#define ERR(fmt,...)
Definition: debug.h:110
void wined3d_texture_apply_sampler_desc(struct wined3d_texture *texture, const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context *context)
Definition: texture.c:896
GLuint sampler
Definition: glext.h:7283
png_const_structrp png_const_inforp int * unit
Definition: png.h:2159
static void texture_apply_base_level(struct wined3d_texture *texture, const struct wined3d_sampler_desc *desc, const struct wined3d_gl_info *gl_info)
Definition: sampler.c:158
Definition: http.c:7252
BOOL supported[WINED3D_GL_EXT_COUNT]
@ ARB_SAMPLER_OBJECTS
Definition: wined3d_gl.h:92
#define GL_EXTCALL(f)
#define checkGLcall(A)

Referenced by sampler(), and wined3d_shader_resource_view_bind().

◆ wined3d_sampler_create()

HRESULT CDECL wined3d_sampler_create ( struct wined3d_device device,
const struct wined3d_sampler_desc desc,
void parent,
const struct wined3d_parent_ops parent_ops,
struct wined3d_sampler **  sampler 
)

Definition at line 130 of file sampler.c.

132{
133 struct wined3d_sampler *object;
134
135 TRACE("device %p, desc %p, parent %p, sampler %p.\n", device, desc, parent, sampler);
136
137 if (desc->address_u < WINED3D_TADDRESS_WRAP || desc->address_u > WINED3D_TADDRESS_MIRROR_ONCE
138 || desc->address_v < WINED3D_TADDRESS_WRAP || desc->address_v > WINED3D_TADDRESS_MIRROR_ONCE
139 || desc->address_w < WINED3D_TADDRESS_WRAP || desc->address_w > WINED3D_TADDRESS_MIRROR_ONCE)
141
142 if (desc->mag_filter < WINED3D_TEXF_POINT || desc->mag_filter > WINED3D_TEXF_LINEAR
143 || desc->min_filter < WINED3D_TEXF_POINT || desc->min_filter > WINED3D_TEXF_LINEAR
144 || desc->mip_filter > WINED3D_TEXF_LINEAR)
146
147 if (!(object = heap_alloc_zero(sizeof(*object))))
148 return E_OUTOFMEMORY;
149
151
152 TRACE("Created sampler %p.\n", object);
153 *sampler = object;
154
155 return WINED3D_OK;
156}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
r parent
Definition: btrfs.c:3010
static void wined3d_sampler_init(struct wined3d_sampler *sampler, struct wined3d_device *device, const struct wined3d_sampler_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
Definition: sampler.c:117
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
const struct wined3d_parent_ops * parent_ops
#define WINED3D_OK
Definition: wined3d.h:37
@ WINED3D_TEXF_POINT
Definition: wined3d.h:686
@ WINED3D_TEXF_LINEAR
Definition: wined3d.h:687
@ WINED3D_TADDRESS_MIRROR_ONCE
Definition: wined3d.h:643
@ WINED3D_TADDRESS_WRAP
Definition: wined3d.h:639
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:48

Referenced by create_default_samplers(), and sampler().

◆ wined3d_sampler_cs_init()

static void wined3d_sampler_cs_init ( void object)
static

Definition at line 75 of file sampler.c.

76{
78 const struct wined3d_sampler_desc *desc;
79 const struct wined3d_gl_info *gl_info;
81
82 context = context_acquire(sampler->device, NULL, 0);
83 gl_info = context->gl_info;
84
85 desc = &sampler->desc;
86 GL_EXTCALL(glGenSamplers(1, &sampler->name));
87 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_S,
88 gl_info->wrap_lookup[desc->address_u - WINED3D_TADDRESS_WRAP]));
89 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_T,
90 gl_info->wrap_lookup[desc->address_v - WINED3D_TADDRESS_WRAP]));
91 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_R,
92 gl_info->wrap_lookup[desc->address_w - WINED3D_TADDRESS_WRAP]));
93 GL_EXTCALL(glSamplerParameterfv(sampler->name, GL_TEXTURE_BORDER_COLOR, &desc->border_color[0]));
94 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAG_FILTER,
95 wined3d_gl_mag_filter(desc->mag_filter)));
96 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MIN_FILTER,
97 wined3d_gl_min_mip_filter(desc->min_filter, desc->mip_filter)));
98 GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_LOD_BIAS, desc->lod_bias));
99 GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MIN_LOD, desc->min_lod));
100 GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MAX_LOD, desc->max_lod));
102 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAX_ANISOTROPY, desc->max_anisotropy));
103 if (desc->compare)
105 GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_COMPARE_FUNC,
106 wined3d_gl_compare_func(desc->comparison_func)));
107 if ((context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
108 && gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && !desc->srgb_decode)
110 checkGLcall("sampler creation");
111
112 TRACE("Created sampler %u.\n", sampler->name);
113
115}
#define NULL
Definition: types.h:112
struct wined3d_context * context_acquire(const struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: context.c:4242
void context_release(struct wined3d_context *context)
Definition: context.c:1571
GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f)
Definition: state.c:348
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:649
#define GL_TEXTURE_BORDER_COLOR
Definition: gl.h:656
#define GL_TEXTURE_WRAP_R
Definition: gl.h:1518
#define GL_TEXTURE_WRAP_S
Definition: gl.h:646
#define GL_TEXTURE_MAX_LOD
Definition: gl.h:1502
#define GL_TEXTURE_WRAP_T
Definition: gl.h:647
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:648
#define GL_TEXTURE_MIN_LOD
Definition: gl.h:1501
#define GL_SKIP_DECODE_EXT
Definition: glext.h:5291
#define GL_TEXTURE_COMPARE_FUNC
Definition: glext.h:300
#define GL_COMPARE_R_TO_TEXTURE
Definition: glext.h:326
#define GL_TEXTURE_LOD_BIAS
Definition: glext.h:295
#define GL_TEXTURE_SRGB_DECODE_EXT
Definition: glext.h:5289
#define GL_TEXTURE_COMPARE_MODE
Definition: glext.h:299
const struct wined3d_gl_info * gl_info
#define GL_TEXTURE_MAX_ANISOTROPY
Definition: wgl.h:4357
#define WINED3D_SRGB_READ_WRITE_CONTROL
Definition: wined3d.h:1324
@ ARB_TEXTURE_FILTER_ANISOTROPIC
Definition: wined3d_gl.h:117
@ EXT_TEXTURE_SRGB_DECODE
Definition: wined3d_gl.h:183
static GLenum wined3d_gl_mag_filter(enum wined3d_texture_filter_type mag_filter)
static GLenum wined3d_gl_min_mip_filter(enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter)

Referenced by wined3d_sampler_init().

◆ wined3d_sampler_decref()

ULONG CDECL wined3d_sampler_decref ( struct wined3d_sampler sampler)

Definition at line 53 of file sampler.c.

54{
55 ULONG refcount = InterlockedDecrement(&sampler->refcount);
56
57 TRACE("%p decreasing refcount to %u.\n", sampler, refcount);
58
59 if (!refcount)
60 {
61 sampler->parent_ops->wined3d_object_destroyed(sampler->parent);
63 }
64
65 return refcount;
66}
#define InterlockedDecrement
Definition: armddk.h:52
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:1885
static void wined3d_sampler_destroy_object(void *object)
Definition: sampler.c:36
uint32_t ULONG
Definition: typedefs.h:59

Referenced by destroy_default_samplers(), device_free_sampler(), sampler(), state_unbind_resources(), and wined3d_device_set_sampler().

◆ wined3d_sampler_destroy_object()

static void wined3d_sampler_destroy_object ( void object)
static

Definition at line 36 of file sampler.c.

37{
39 const struct wined3d_gl_info *gl_info;
41
42 if (sampler->name)
43 {
44 context = context_acquire(sampler->device, NULL, 0);
45 gl_info = context->gl_info;
46 GL_EXTCALL(glDeleteSamplers(1, &sampler->name));
48 }
49
51}
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by wined3d_sampler_decref().

◆ wined3d_sampler_get_parent()

void *CDECL wined3d_sampler_get_parent ( const struct wined3d_sampler sampler)

Definition at line 68 of file sampler.c.

69{
70 TRACE("sampler %p.\n", sampler);
71
72 return sampler->parent;
73}

◆ wined3d_sampler_incref()

ULONG CDECL wined3d_sampler_incref ( struct wined3d_sampler sampler)

Definition at line 27 of file sampler.c.

28{
29 ULONG refcount = InterlockedIncrement(&sampler->refcount);
30
31 TRACE("%p increasing refcount to %u.\n", sampler, refcount);
32
33 return refcount;
34}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by wined3d_device_set_sampler().

◆ wined3d_sampler_init()

static void wined3d_sampler_init ( struct wined3d_sampler sampler,
struct wined3d_device device,
const struct wined3d_sampler_desc desc,
void parent,
const struct wined3d_parent_ops parent_ops 
)
static

Definition at line 117 of file sampler.c.

119{
120 sampler->refcount = 1;
121 sampler->device = device;
122 sampler->parent = parent;
123 sampler->parent_ops = parent_ops;
124 sampler->desc = *desc;
125
126 if (device->adapter->gl_info.supported[ARB_SAMPLER_OBJECTS])
128}
void wined3d_cs_init_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:1890
static void wined3d_sampler_cs_init(void *object)
Definition: sampler.c:75

Referenced by wined3d_sampler_create().