RetroArch
sampler.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2017 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SPIRV_CROSS_SAMPLER_HPP
18 #define SPIRV_CROSS_SAMPLER_HPP
19 
20 #include <vector>
21 
22 namespace spirv_cross
23 {
25 {
26  inline virtual ~spirv_cross_sampler_2d()
27  {
28  }
29 };
30 
31 template <typename T>
33 {
35  {
36  mips.insert(mips.end(), info->mipmaps, info->mipmaps + info->num_mipmaps);
37  format = info->format;
38  wrap_s = info->wrap_s;
39  wrap_t = info->wrap_t;
40  min_filter = info->min_filter;
41  mag_filter = info->mag_filter;
42  mip_filter = info->mip_filter;
43  }
44 
45  inline virtual T sample(glm::vec2 uv, float bias)
46  {
47  return sampleLod(uv, bias);
48  }
49 
50  inline virtual T sampleLod(glm::vec2 uv, float lod)
51  {
53  {
54  uv.x = wrap(uv.x, wrap_s, mips[0].width);
55  uv.y = wrap(uv.y, wrap_t, mips[0].height);
56  glm::vec2 uv_full = uv * glm::vec2(mips[0].width, mips[0].height);
57 
58  int x = int(uv_full.x);
59  int y = int(uv_full.y);
60  return sample(x, y, 0);
61  }
62  else
63  {
64  return T(0, 0, 0, 1);
65  }
66  }
67 
68  inline float wrap(float v, spirv_cross_wrap wrap, unsigned size)
69  {
70  switch (wrap)
71  {
73  return v - glm::floor(v);
75  {
76  float half = 0.5f / size;
77  return glm::clamp(v, half, 1.0f - half);
78  }
79 
80  default:
81  return 0.0f;
82  }
83  }
84 
85  std::vector<spirv_cross_miplevel> mips;
92 };
93 
97 
98 template <typename T>
99 inline T texture(const sampler2DBase<T> &samp, const glm::vec2 &uv, float bias = 0.0f)
100 {
101  return samp.sample(uv, bias);
102 }
103 }
104 
105 #endif
sampler2DBase< glm::vec4 > sampler2D
Definition: sampler.hpp:94
Definition: external_interface.h:83
virtual T sampleLod(glm::vec2 uv, float lod)
Definition: sampler.hpp:50
#define T(x)
Definition: external_interface.h:105
Definition: libretro.h:2275
Definition: external_interface.h:76
GLsizeiptr size
Definition: glext.h:6559
GLfloat f
Definition: glext.h:8207
spirv_cross_mipfilter
Definition: external_interface.h:89
#define floor(x)
Definition: math.h:25
Definition: sampler.hpp:32
spirv_cross_filter
Definition: external_interface.h:81
GLint lod
Definition: glext.h:8462
sampler2DBase< glm::ivec4 > isampler2D
Definition: sampler.hpp:95
spirv_cross_filter mag_filter
Definition: sampler.hpp:90
Definition: barrier.hpp:23
spirv_cross_wrap
Definition: external_interface.h:73
std::vector< spirv_cross_miplevel > mips
Definition: sampler.hpp:85
spirv_cross_format wrap_t
Definition: sampler.hpp:88
float wrap(float v, spirv_cross_wrap wrap, unsigned size)
Definition: sampler.hpp:68
GLfloat bias
Definition: glext.h:8812
spirv_cross_mipfilter mip_filter
Definition: sampler.hpp:91
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295
sampler2DBase(const spirv_cross_sampler_info *info)
Definition: sampler.hpp:34
spirv_cross_format format
Definition: sampler.hpp:86
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
GLenum clamp
Definition: glext.h:6856
virtual ~spirv_cross_sampler_2d()
Definition: sampler.hpp:26
spirv_cross_filter min_filter
Definition: sampler.hpp:89
const GLdouble * v
Definition: glext.h:6391
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:6293
GLint GLint GLsizei width
Definition: glext.h:6293
T texture(const sampler2DBase< T > &samp, const glm::vec2 &uv, float bias=0.0f)
Definition: sampler.hpp:99
spirv_cross_wrap wrap_s
Definition: sampler.hpp:87
sampler2DBase< glm::uvec4 > usampler2D
Definition: sampler.hpp:96
virtual T sample(glm::vec2 uv, float bias)
Definition: sampler.hpp:45
spirv_cross_format
Definition: external_interface.h:63
Definition: external_interface.h:75
GLint GLint GLsizei GLsizei height
Definition: glext.h:6293
Definition: sampler.hpp:24