* A Material that is not managed by C++ RAII. * * Make sure to Unload() this if needed, otherwise use raylib::Material. * * @see raylib::Material */
| 16 | * @see raylib::Material |
| 17 | */ |
| 18 | class MaterialUnmanaged : public ::Material { |
| 19 | public: |
| 20 | /** |
| 21 | * Creates a MaterialUnmanaged from an existing Material struct. |
| 22 | */ |
| 23 | MaterialUnmanaged(const ::Material& material) : ::Material(material) {} |
| 24 | |
| 25 | /** |
| 26 | * Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps). |
| 27 | */ |
| 28 | MaterialUnmanaged() : ::Material(::LoadMaterialDefault()) {} |
| 29 | |
| 30 | /** |
| 31 | * Load materials from model file. |
| 32 | */ |
| 33 | static std::vector<MaterialUnmanaged> Load(const std::string& fileName) { |
| 34 | int count = 0; |
| 35 | ::Material* mats = ::LoadMaterials(fileName.c_str(), &count); |
| 36 | return std::vector<MaterialUnmanaged>(mats, mats + count); |
| 37 | } |
| 38 | |
| 39 | GETTERSETTER(::Shader, Shader, shader) |
| 40 | GETTERSETTER(::MaterialMap*, Maps, maps) |
| 41 | |
| 42 | MaterialUnmanaged& operator=(const ::Material& material) { |
| 43 | set(material); |
| 44 | return *this; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Unload material from memory. |
| 49 | */ |
| 50 | void Unload() { |
| 51 | if (maps != nullptr) { |
| 52 | ::UnloadMaterial(*this); |
| 53 | maps = nullptr; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...). |
| 59 | */ |
| 60 | MaterialUnmanaged& SetTexture(int mapType, const ::Texture2D& texture) { |
| 61 | ::SetMaterialTexture(this, mapType, texture); |
| 62 | return *this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Draw a 3d mesh with material and transform. |
| 67 | */ |
| 68 | void DrawMesh(const ::Mesh& mesh, ::Matrix transform) const { ::DrawMesh(mesh, *this, transform); } |
| 69 | |
| 70 | /** |
| 71 | * Draw multiple mesh instances with material and different transforms. |
| 72 | */ |
| 73 | void DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const { |
| 74 | ::DrawMeshInstanced(mesh, *this, transforms, instances); |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected