Path: blob/master/modules/gltf/structures/gltf_texture_sampler.h
10278 views
/**************************************************************************/1/* gltf_texture_sampler.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/resources/material.h"3334class GLTFTextureSampler : public Resource {35GDCLASS(GLTFTextureSampler, Resource);3637public:38enum FilterMode {39NEAREST = 9728,40LINEAR = 9729,41NEAREST_MIPMAP_NEAREST = 9984,42LINEAR_MIPMAP_NEAREST = 9985,43NEAREST_MIPMAP_LINEAR = 9986,44LINEAR_MIPMAP_LINEAR = 998745};4647enum WrapMode {48CLAMP_TO_EDGE = 33071,49MIRRORED_REPEAT = 33648,50REPEAT = 10497,51DEFAULT = REPEAT52};5354int get_mag_filter() const {55return mag_filter;56}5758void set_mag_filter(const int filter_mode) {59mag_filter = (FilterMode)filter_mode;60}6162int get_min_filter() const {63return min_filter;64}6566void set_min_filter(const int filter_mode) {67min_filter = (FilterMode)filter_mode;68}6970int get_wrap_s() const {71return wrap_s;72}7374void set_wrap_s(const int wrap_mode) {75wrap_s = (WrapMode)wrap_mode;76}7778int get_wrap_t() const {79return wrap_t;80}8182void set_wrap_t(const int wrap_mode) {83wrap_s = (WrapMode)wrap_mode;84}8586StandardMaterial3D::TextureFilter get_filter_mode() const {87using TextureFilter = StandardMaterial3D::TextureFilter;8889switch (min_filter) {90case NEAREST:91return TextureFilter::TEXTURE_FILTER_NEAREST;92case LINEAR:93return TextureFilter::TEXTURE_FILTER_LINEAR;94case NEAREST_MIPMAP_NEAREST:95case NEAREST_MIPMAP_LINEAR:96return TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS;97case LINEAR_MIPMAP_NEAREST:98case LINEAR_MIPMAP_LINEAR:99default:100return TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;101}102}103104void set_filter_mode(StandardMaterial3D::TextureFilter mode) {105using TextureFilter = StandardMaterial3D::TextureFilter;106107switch (mode) {108case TextureFilter::TEXTURE_FILTER_NEAREST:109min_filter = FilterMode::NEAREST;110mag_filter = FilterMode::NEAREST;111break;112case TextureFilter::TEXTURE_FILTER_LINEAR:113min_filter = FilterMode::LINEAR;114mag_filter = FilterMode::LINEAR;115break;116case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:117case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:118min_filter = FilterMode::NEAREST_MIPMAP_LINEAR;119mag_filter = FilterMode::NEAREST;120break;121case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:122case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:123default:124min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;125mag_filter = FilterMode::LINEAR;126break;127}128}129130bool get_wrap_mode() const {131// BaseMaterial3D presents wrapping as a boolean property. Either the texture is repeated132// in both dimensions, non-mirrored, or it isn't repeated at all. This will cause oddities133// when people import models having other wrapping mode combinations.134return (wrap_s == WrapMode::REPEAT) && (wrap_t == WrapMode::REPEAT);135}136137void set_wrap_mode(bool mat_repeats) {138if (mat_repeats) {139wrap_s = WrapMode::REPEAT;140wrap_t = WrapMode::REPEAT;141} else {142wrap_s = WrapMode::CLAMP_TO_EDGE;143wrap_t = WrapMode::CLAMP_TO_EDGE;144}145}146147protected:148static void _bind_methods();149150private:151FilterMode mag_filter = FilterMode::LINEAR;152FilterMode min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;153WrapMode wrap_s = WrapMode::REPEAT;154WrapMode wrap_t = WrapMode::REPEAT;155};156157VARIANT_ENUM_CAST(GLTFTextureSampler::FilterMode);158VARIANT_ENUM_CAST(GLTFTextureSampler::WrapMode);159160161