Skip to content

Commit

Permalink
Support mdc models.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcy committed Apr 12, 2016
1 parent d2225e9 commit 9629ff2
Show file tree
Hide file tree
Showing 6 changed files with 495 additions and 157 deletions.
26 changes: 16 additions & 10 deletions code/renderer_bgfx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,21 @@ void Main::renderScene(const SceneDefinition &scene)
floatTime_ = time_ * 0.001f;

// Clamp view rect to screen.
const int x = std::max(0, scene.rect.x);
const int y = std::max(0, scene.rect.y);
const int w = std::min(window::GetWidth(), x + scene.rect.w) - x;
const int h = std::min(window::GetHeight(), y + scene.rect.h) - y;
Rect rect;
rect.x = std::max(0, scene.rect.x);
rect.y = std::max(0, scene.rect.y);
#if 0
rect.w = std::min(window::GetWidth(), rect.x + scene.rect.w) - rect.x;
rect.h = std::min(window::GetHeight(), rect.y + scene.rect.h) - rect.y;
#else
rect.w = scene.rect.w;
rect.h = scene.rect.h;
#endif

if (scene.flags & SceneDefinitionFlags::Hyperspace)
{
const uint8_t c = time_ & 255;
const uint8_t viewId = pushView(defaultFb_, 0, mat4::identity, mat4::identity, Rect(x, y, w, h));
const uint8_t viewId = pushView(defaultFb_, 0, mat4::identity, mat4::identity, rect);
bgfx::setViewClear(viewId, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, (c<<24)|(c<<16)|(c<<8)|0xff);
bgfx::touch(viewId);
}
Expand All @@ -634,7 +640,7 @@ void Main::renderScene(const SceneDefinition &scene)

// Render camera(s).
sceneRotation_ = scene.rotation;
renderCamera(mainVisCacheId_, scene.position, scene.position, sceneRotation_, Rect(x, y, w, h), scene.fov, scene.areaMask);
renderCamera(mainVisCacheId_, scene.position, scene.position, sceneRotation_, rect, scene.fov, scene.areaMask);

if (isWorldScene_)
{
Expand Down Expand Up @@ -706,7 +712,7 @@ void Main::renderScene(const SceneDefinition &scene)
}
else if (aa_ == AntiAliasing::SMAA)
{
uniforms_->smaaMetrics.set(vec4(1.0f / w, 1.0f / h, (float)w, (float)h));
uniforms_->smaaMetrics.set(vec4(1.0f / rect.w, 1.0f / rect.h, (float)rect.w, (float)rect.h));

// Edge detection.
if (g_cvars.hdr.getBool())
Expand Down Expand Up @@ -1186,7 +1192,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
continue;
}

const bool doFogPass = dc.fogIndex >= 0 && mat->fogPass != MaterialFogPass::None;
const bool doFogPass = !dc.material->noFog && dc.fogIndex >= 0 && mat->fogPass != MaterialFogPass::None;

if (mat->numUnfoggedPasses == 0 && !doFogPass)
continue;
Expand Down Expand Up @@ -1230,7 +1236,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
vec4 fogColor, fogDistance, fogDepth;
float eyeT;

if (dc.fogIndex >= 0)
if (!dc.material->noFog && dc.fogIndex >= 0)
{
world::CalculateFog(dc.fogIndex, dc.modelMatrix, modelViewMatrix, position, localViewPosition, rotation, &fogColor, &fogDistance, &fogDepth, &eyeT);
uniforms_->fogDistance.set(fogDistance);
Expand All @@ -1243,7 +1249,7 @@ void Main::renderCamera(uint8_t visCacheId, vec3 pvsPosition, vec3 position, mat
if (!stage.active)
continue;

if (dc.fogIndex >= 0 && stage.adjustColorsForFog != MaterialAdjustColorsForFog::None)
if (!dc.material->noFog && dc.fogIndex >= 0 && stage.adjustColorsForFog != MaterialAdjustColorsForFog::None)
{
uniforms_->fogEnabled.set(vec4(1, 0, 0, 0));
matStageUniforms_->fogColorMask.set(stage.getFogColorMask());
Expand Down
5 changes: 5 additions & 0 deletions code/renderer_bgfx/Material_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ bool Material::parse(char **text)
{
parseSkyParms(text);
}
// Ridah, allow disable fog for some shaders
else if (!util::Stricmp(token, "nofog"))
{
noFog = true;
}
// RF, allow each shader to permit compression if available
else if (!util::Stricmp(token, "allowcompress"))
{
Expand Down
46 changes: 28 additions & 18 deletions code/renderer_bgfx/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ struct ModelHandler
Create create;
};

// Note that the ordering indicates the order of preference used when there are multiple models of different formats available.
static const ModelHandler s_modelHandlers[] =
{
{ "md3", Model::createMD3 }
{ "md3", Model::createMD3 },
{ "mdc", Model::createMDC }
};

Transform Model::lerpTag(const char *name, int startFrame, int endFrame, float fraction)
Expand All @@ -56,13 +58,13 @@ Model *ModelCache::findModel(const char *name)
{
if (!name || !name[0])
{
interface::Printf("ModelCache::findModel: NULL name\n");
interface::PrintWarningf("ModelCache::findModel: NULL name\n");
return nullptr;
}

if (strlen(name) >= MAX_QPATH)
{
interface::Printf("Model name exceeds MAX_QPATH\n");
interface::PrintWarningf("Model name exceeds MAX_QPATH\n");
return nullptr;
}

Expand All @@ -79,29 +81,37 @@ Model *ModelCache::findModel(const char *name)
}

// Create/load the model
// Calculate the filename extension to determine which handler to try first.
const char *extension = util::GetExtension(name);

if (strlen(extension) == 0)
extension = s_modelHandlers[0].extension;
// First pass: try the handler that corresponds to the filename extension.
// Second pass: if we got this far, either the extension was omitted, or the filename with the supplied extension doesn't exist. Either way, try loading using all supported extensions.
for (int i = 0; i < 2; i++)
{
for (const ModelHandler &handler : s_modelHandlers)
{
// First pass: ignore handlers that don't match the extension.
if (i == 0 && util::Stricmp(extension, handler.extension))
continue;

char filename[MAX_QPATH];
util::StripExtension(name, filename, sizeof(filename));
util::Strcat(filename, sizeof(filename), util::VarArgs(".%s", extension));
std::unique_ptr<Model> m;
char filename[MAX_QPATH];
util::StripExtension(name, filename, sizeof(filename));
util::Strcat(filename, sizeof(filename), util::VarArgs(".%s", handler.extension));
ReadOnlyFile file(filename);

for (const ModelHandler &handler : s_modelHandlers)
{
if (util::Stricmp(extension, handler.extension))
continue;

std::unique_ptr<Model> m = handler.create(filename);
if (!file.isValid())
continue;

if (!m->load())
return nullptr;
std::unique_ptr<Model> m = handler.create(filename);

return addModel(std::move(m));
if (!m->load(file))
return nullptr; // The load function will print any error messages.

return addModel(std::move(m));
}
}

interface::PrintDeveloperf("Model %s: file doesn't exist\n", name);
return nullptr;
}

Expand Down
Loading

0 comments on commit 9629ff2

Please sign in to comment.