Browse Source

Fix model loading

master
C. J. Howard 7 years ago
parent
commit
d2319fec12
6 changed files with 69 additions and 7 deletions
  1. +15
    -3
      README.md
  2. +1
    -1
      data
  3. +2
    -3
      src/application.cpp
  4. +4
    -0
      src/model-loader.cpp
  5. +46
    -0
      src/render-passes.cpp
  6. +1
    -0
      src/render-passes.hpp

+ 15
- 3
README.md View File

@ -28,11 +28,19 @@ Antkeeper uses the CMake build system for configuration.
cmake --build . cmake --build .
4. Testing
## Workflow
cmake --build . --target run
### Making Changes
If any changes have been made to the submodules, commit those first. Each submodule can then be updated to their latest commits with the following command:
git submodule update --recursive --remote
5. Cleaning
### Testing
cmake --build . --target run
### Cleaning
First perform a dry run to check what will be deleted: First perform a dry run to check what will be deleted:
@ -42,6 +50,10 @@ If there are no issues, clean:
git clean -d -f -x git clean -d -f -x
### Shipping
## License ## License
The source code for Antkeeper is licensed under the GNU General Public License, version 3. See [COPYING](./COPYING) for details. The source code for Antkeeper is licensed under the GNU General Public License, version 3. See [COPYING](./COPYING) for details.

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 9e0511889e2d3b1c0c60c0878db02c5c8b7e6b8e
Subproject commit 6ddb419437560e06e12ff6c6d1e42ba88ed5098a

+ 2
- 3
src/application.cpp View File

@ -19,6 +19,8 @@
#include "application.hpp" #include "application.hpp"
#include "application-state.hpp" #include "application-state.hpp"
#include "model-loader.hpp"
#include "material-loader.hpp"
#include "states/splash-state.hpp" #include "states/splash-state.hpp"
#include "states/title-state.hpp" #include "states/title-state.hpp"
#include "states/experiment-state.hpp" #include "states/experiment-state.hpp"
@ -29,9 +31,6 @@
#define OPENGL_VERSION_MAJOR 3 #define OPENGL_VERSION_MAJOR 3
#define OPENGL_VERSION_MINOR 3 #define OPENGL_VERSION_MINOR 3
#include "model-loader.hpp"
#include "material-loader.hpp"
Application::Application(int argc, char* argv[]): Application::Application(int argc, char* argv[]):
state(nullptr), state(nullptr),
nextState(nullptr), nextState(nullptr),

+ 4
- 0
src/model-loader.cpp View File

@ -252,6 +252,10 @@ Model* ModelLoader::load(const std::string& filename)
// Allocate model // Allocate model
Model* model = new Model(); Model* model = new Model();
model->setVAO(vao);
model->setVBO(vbo);
model->setIBO(ibo);
model->setVertexFormat(modelData->vertexFormat);
model->setBounds(modelData->bounds); model->setBounds(modelData->bounds);
// Create model groups // Create model groups

+ 46
- 0
src/render-passes.cpp View File

@ -277,6 +277,7 @@ LightingRenderPass::LightingRenderPass():
bool LightingRenderPass::load(const RenderContext* renderContext) bool LightingRenderPass::load(const RenderContext* renderContext)
{ {
// For each render operation // For each render operation
/*
if (renderContext != nullptr) if (renderContext != nullptr)
{ {
const std::list<RenderOperation>* operations = renderContext->queue->getOperations(); const std::list<RenderOperation>* operations = renderContext->queue->getOperations();
@ -285,6 +286,7 @@ bool LightingRenderPass::load(const RenderContext* renderContext)
loadShader(operation); loadShader(operation);
} }
} }
*/
// Load tree shadow // Load tree shadow
if (!treeShadow.load("data/textures/tree-shadow-0.png")) if (!treeShadow.load("data/textures/tree-shadow-0.png"))
@ -320,6 +322,18 @@ bool LightingRenderPass::load(const RenderContext* renderContext)
return false; return false;
} }
// Load lighting shader
shaderLoader.undefine();
shaderLoader.define("TEXTURE_COUNT", 0);
shaderLoader.define("VERTEX_POSITION", EMERGENT_VERTEX_POSITION);
shaderLoader.define("VERTEX_NORMAL", EMERGENT_VERTEX_NORMAL);
lightingShader = shaderLoader.load("data/shaders/lit-object.glsl");
if (!lightingShader)
{
return false;
}
time = 0.0f; time = 0.0f;
return true; return true;
@ -330,6 +344,8 @@ void LightingRenderPass::unload()
cappingRenderQueue.clear(); cappingRenderQueue.clear();
clippingRenderPass.unload(); clippingRenderPass.unload();
cappingRenderPass.unload(); cappingRenderPass.unload();
delete lightingShader;
lightingShader = nullptr;
for (auto it = shaderCache.begin(); it != shaderCache.end(); ++it) for (auto it = shaderCache.begin(); it != shaderCache.end(); ++it)
{ {
@ -723,6 +739,36 @@ void LightingRenderPass::render(const RenderContext* renderContext)
// Disable clipping // Disable clipping
glDisable(GL_CLIP_DISTANCE0); glDisable(GL_CLIP_DISTANCE0);
*/ */
// Enable depth testing
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
// Enable backface culling
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// Enable alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Bind shader
lightingShader->bind();
ShaderParameterSet* parameters = lightingShader->getParameters();
const Camera& camera = *(renderContext->camera);
const std::list<RenderOperation>* operations = renderContext->queue->getOperations();
// Render operations
for (const RenderOperation& operation: *operations)
{
const Matrix4& modelMatrix = operation.transform;
Matrix4 modelViewProjectionMatrix = camera.getViewProjection() * modelMatrix;
parameters->setValue(ShaderParameter::MODEL_VIEW_PROJECTION_MATRIX, modelViewProjectionMatrix);
glBindVertexArray(operation.vao);
glDrawElementsBaseVertex(GL_TRIANGLES, operation.triangleCount * 3, GL_UNSIGNED_INT, (void*)0, operation.indexOffset);
}
} }
bool LightingRenderPass::loadShader(const RenderOperation& operation) bool LightingRenderPass::loadShader(const RenderOperation& operation)

+ 1
- 0
src/render-passes.hpp View File

@ -111,6 +111,7 @@ private:
bool loadShader(const RenderOperation& operation); bool loadShader(const RenderOperation& operation);
ShaderLoader shaderLoader; ShaderLoader shaderLoader;
std::map<std::size_t, Shader*> shaderCache; std::map<std::size_t, Shader*> shaderCache;
Shader* lightingShader;
Matrix4 biasMatrix; Matrix4 biasMatrix;
GLuint shadowMap; GLuint shadowMap;

Loading…
Cancel
Save