1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
/* bzflag
* Copyright (c) 1993-2025 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* TetraBuilding:
* Encapsulates a tetrahederon in the game environment.
*/
#ifndef BZ_MATERIAL_H
#define BZ_MATERIAL_H
#include "common.h"
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
class BzMaterial;
typedef std::set<const BzMaterial*> MaterialSet;
typedef std::map<const BzMaterial*,
const BzMaterial*> MaterialMap;
class BzMaterial
{
public:
BzMaterial();
BzMaterial(const BzMaterial& material);
~BzMaterial();
bool operator==(const BzMaterial& material) const;
BzMaterial& operator=(const BzMaterial& material);
void reset();
void setReference() const; // const exploits mutable "referenced" variable below
bool getReference() const;
//
// Parameter setting
//
bool setName(const std::string&);
bool addAlias(const std::string&);
void setDynamicColor(int);
void setAmbient(const float[4]);
void setDiffuse(const float[4]);
void setSpecular(const float[3]);
void setEmission(const float[3]);
void setShininess(const float);
void setOccluder(bool);
void setGroupAlpha(bool);
void setNoLighting(bool);
void setNoRadar(bool);
void setNoShadow(bool);
void setNoCulling(bool);
void setNoSorting(bool);
void setAlphaThreshold(const float);
// the following set()'s operate on the last added texture
void addTexture(const std::string&);
void setTexture(const std::string&);
void setTextureLocal(int texid, const std::string& localname);
void setTextureMatrix(int);
void setCombineMode(int);
void setUseTextureAlpha(bool);
void setUseColorOnTexture(bool);
void setUseSphereMap(bool);
void clearTextures(); // remove all textures
void addShader(const std::string&);
void setShader(const std::string&);
void clearShaders(); // remove all shaders
//
// Parameter getting
//
const std::string& getName() const;
const std::vector<std::string>& getAliases() const;
int getDynamicColor() const;
const float* getAmbient() const;
const float* getDiffuse() const;
const float* getSpecular() const;
const float* getEmission() const;
float getShininess() const;
bool getOccluder() const;
bool getGroupAlpha() const;
bool getNoRadar() const;
bool getNoShadow() const;
bool getNoCulling() const;
bool getNoSorting() const;
bool getNoLighting() const;
float getAlphaThreshold() const;
int getTextureCount() const;
const std::string& getTexture(int) const;
const std::string& getTextureLocal(int) const;
int getTextureMatrix(int) const;
int getCombineMode(int) const;
bool getUseTextureAlpha(int) const;
bool getUseColorOnTexture(int) const;
bool getUseSphereMap(int) const;
int getShaderCount() const;
const std::string& getShader(int) const;
//
// Utilities
//
bool isInvisible() const;
int packSize() const;
void *pack(void *) const;
const void *unpack(const void *);
void print(std::ostream& out, const std::string& indent) const;
void printMTL(std::ostream& out, const std::string& indent) const;
static const BzMaterial* getDefault();
// data
private:
std::string name;
std::vector<std::string> aliases;
mutable bool referenced;
int dynamicColor;
float ambient[4];
float diffuse[4];
float specular[4];
float emission[4];
float shininess;
bool occluder;
bool groupAlpha;
bool noRadar;
bool noShadow;
bool noCulling;
bool noSorting;
bool noLighting;
float alphaThreshold;
enum CombineModes
{
replace = 0,
modulate,
decal,
blend,
add,
combine
};
int textureCount;
typedef struct
{
std::string name;
std::string localname;
int matrix;
int combineMode;
bool useAlpha;
bool useColor;
bool useSphereMap;
} TextureInfo;
TextureInfo* textures;
int shaderCount;
typedef struct
{
std::string name;
} ShaderInfo;
ShaderInfo* shaders;
private:
static std::string nullString;
static BzMaterial defaultMaterial;
};
inline const BzMaterial* BzMaterial::getDefault()
{
return &defaultMaterial;
}
inline void BzMaterial::setReference() const
{
referenced = true;
return;
}
inline bool BzMaterial::getReference() const
{
return referenced;
}
class BzMaterialManager
{
public:
BzMaterialManager();
~BzMaterialManager();
void update();
void clear();
const BzMaterial* addMaterial(const BzMaterial* material);
const BzMaterial* findMaterial(const std::string& name) const;
const BzMaterial* getMaterial(int id) const;
int getIndex(const BzMaterial* material) const;
typedef std::set<std::string> TextureSet;
void makeTextureList(TextureSet& set, bool referenced) const;
void setTextureLocal(const std::string& url, const std::string& local);
void* pack(void*);
const void* unpack(const void*);
int packSize();
void print(std::ostream& out, const std::string& indent) const;
void printMTL(std::ostream& out, const std::string& indent) const;
void printReference(std::ostream& out, const BzMaterial* mat) const;
private:
std::vector<BzMaterial*> materials;
};
extern BzMaterialManager MATERIALMGR;
#endif // BZ_MATERIAL_H
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|