(self, *, image=None, width=None, height=None, channels=None, dtype=None, bilinear=True, mipmap=True)
| 128 | |
| 129 | class Texture: |
| 130 | def __init__(self, *, image=None, width=None, height=None, channels=None, dtype=None, bilinear=True, mipmap=True): |
| 131 | self.gl_id = None |
| 132 | self.bilinear = bilinear |
| 133 | self.mipmap = mipmap |
| 134 | |
| 135 | # Determine size and dtype. |
| 136 | if image is not None: |
| 137 | image = prepare_texture_data(image) |
| 138 | self.height, self.width, self.channels = image.shape |
| 139 | self.dtype = image.dtype |
| 140 | else: |
| 141 | assert width is not None and height is not None |
| 142 | self.width = width |
| 143 | self.height = height |
| 144 | self.channels = channels if channels is not None else 3 |
| 145 | self.dtype = np.dtype(dtype) if dtype is not None else np.uint8 |
| 146 | |
| 147 | # Validate size and dtype. |
| 148 | assert isinstance(self.width, int) and self.width >= 0 |
| 149 | assert isinstance(self.height, int) and self.height >= 0 |
| 150 | assert isinstance(self.channels, int) and self.channels >= 1 |
| 151 | assert self.is_compatible(width=width, height=height, channels=channels, dtype=dtype) |
| 152 | |
| 153 | # Create texture object. |
| 154 | self.gl_id = gl.glGenTextures(1) |
| 155 | with self.bind(): |
| 156 | gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) |
| 157 | gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) |
| 158 | gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR if self.bilinear else gl.GL_NEAREST) |
| 159 | gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR if self.mipmap else gl.GL_NEAREST) |
| 160 | self.update(image) |
| 161 | |
| 162 | def delete(self): |
| 163 | if self.gl_id is not None: |
nothing calls this directly
no test coverage detected