Skip to content

Commit

Permalink
Model|Resources: Internal Model API improvements; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 2, 2013
1 parent e962b62 commit 0bcf673
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 116 deletions.
57 changes: 42 additions & 15 deletions doomsday/client/include/gl/gl_model.h
Expand Up @@ -95,23 +95,41 @@ class Model
typedef QList<Skin> Skins;

/**
* Level of detail information.
* Prepared model geometry uses lists of primitives.
*/
struct DetailLevel
struct Primitive
{
struct Primitive
struct Element
{
struct Element
{
de::Vector2f texCoord;
int index; ///< Index into the model's vertex mesh.
};
typedef QVector<Element> Elements;
Elements elements;
bool triFan; ///< @c true= triangle fan; otherwise triangle strip.
de::Vector2f texCoord;
int index; ///< Index into the model's vertex mesh.
};
typedef QList<Primitive> Primitives;
typedef QVector<Element> Elements;
Elements elements;
bool triFan; ///< @c true= triangle fan; otherwise triangle strip.
};
typedef QList<Primitive> Primitives;

/**
* Level of detail information.
*
* Used with DMD models to reduce complexity of the drawn model geometry.
*/
struct DetailLevel
{
Model &model;
int level;
Primitives primitives;

DetailLevel(Model &model, int level)
: model(model), level(level)
{}

/**
* Returns @c true iff the specified vertex @a number is in use for this
* detail level.
*/
bool hasVertex(int number) const;
};
typedef QList<DetailLevel *> DetailLevels;

Expand Down Expand Up @@ -228,6 +246,18 @@ class Model
*/
void clearAllSkins();

/**
* Convenient method of accessing the primitive list used for drawing the
* model with the highest degree of geometric fidelity (i.e., detail level
* zero).
*/
Primitives const &primitives() const;

/**
* Returns the total number of vertices used at detail level zero.
*/
int vertexCount() const;

/**
* Convenient method of determining whether the specified model detail
* @a level is valid (i.e., detail information is defined for it).
Expand All @@ -251,9 +281,6 @@ class Model
*/
DetailLevels const &lods() const;

/// @todo Remove me.
int vertexCount() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/include/render/rend_model.h
Expand Up @@ -31,7 +31,8 @@ class TextureVariantSpec;
#define RENDER_MAX_MODEL_VERTS 16192

/// @todo Split this large inflexible structure into logical subcomponent pieces.
typedef struct rendmodelparams_s {
struct rendmodelparams_t
{
// Animation, frame interpolation.
ModelDef *mf, *nextMF;
float inter;
Expand Down Expand Up @@ -64,7 +65,7 @@ typedef struct rendmodelparams_s {
float shinePitchOffset;
boolean shineTranslateWithViewerPos;
boolean shinepspriteCoordSpace; // Use the psprite coordinate space hack.
} rendmodelparams_t;
};

DENG_EXTERN_C int modelLight;
DENG_EXTERN_C int frameInter;
Expand Down Expand Up @@ -106,9 +107,9 @@ void Rend_ModelShutdown();
* @return @c true= successfully expanded. May fail if @a numVertices is larger
* than RENDER_MAX_MODEL_VERTS.
*/
boolean Rend_ModelExpandVertexBuffers(uint numVertices);
bool Rend_ModelExpandVertexBuffers(uint numVertices);

void Rend_ModelSetFrame(modeldef_t *modef, int frame);
void Rend_ModelSetFrame(modeldef_t &modef, int frame);

/**
* Lookup the texture specification for diffuse model skins.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/models.h
Expand Up @@ -255,7 +255,7 @@ void Models_Shutdown();
*
* @return Index of the definition; otherwise @c -1 if @a modelDef is unknown.
*/
int Models_ToIndex(modeldef_t const *modelDef);
int Models_IndexOf(modeldef_t const *modelDef);

/**
* Retrieve a model by it's unique @a id. O(1)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/def_main.cpp
Expand Up @@ -1902,7 +1902,7 @@ void Def_PostInit(void)
Model *mdl = Models_Model(modef->subModelId(0));
DENG2_ASSERT(mdl != 0);

st->model = Models_ToIndex(modef);
st->model = Models_IndexOf(modef);
st->frame = mdl->frameNumber(st->frameName);
if(st->frame < 0) st->frame = 0;
if(st->endFrameName[0])
Expand Down
10 changes: 10 additions & 0 deletions doomsday/client/src/gl/gl_model.cpp
Expand Up @@ -29,6 +29,11 @@

using namespace de;

bool Model::DetailLevel::hasVertex(int number) const
{
return model._vertexUsage.testBit(number * model.lodCount() + level);
}

void Model::Frame::bounds(Vector3f &retMin, Vector3f &retMax) const
{
retMin = min;
Expand Down Expand Up @@ -188,6 +193,11 @@ Model::DetailLevels const &Model::lods() const
return _lods;
}

Model::Primitives const &Model::primitives() const
{
return lod(0).primitives;
}

int Model::vertexCount() const
{
return _numVertices;
Expand Down

0 comments on commit 0bcf673

Please sign in to comment.