mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 21:36:12 +02:00
more hacking sams tweaks
This commit is contained in:
parent
34fd1bd470
commit
1b8572640b
9 changed files with 267 additions and 165 deletions
|
@ -842,7 +842,7 @@ void Application::paintGL() {
|
||||||
_glWidget->makeCurrent();
|
_glWidget->makeCurrent();
|
||||||
|
|
||||||
auto lodManager = DependencyManager::get<LODManager>();
|
auto lodManager = DependencyManager::get<LODManager>();
|
||||||
gpu::Context context;
|
gpu::Context context(new gpu::GLBackend());
|
||||||
RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),
|
RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),
|
||||||
lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
|
lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
|
||||||
RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
|
RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
|
||||||
|
|
|
@ -524,7 +524,7 @@ void EntityTreeRenderer::render(RenderArgs* renderArgs) {
|
||||||
_tree->unlock();
|
_tree->unlock();
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
renderArgs->_context->enqueueBatch(batch);
|
renderArgs->_context->render(batch);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
renderArgs->_batch = nullptr;
|
renderArgs->_batch = nullptr;
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
Context::Context() {
|
Context::Context(Backend* backend) :
|
||||||
|
_backend(backend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Context::Context(const Context& context) {
|
Context::Context(const Context& context) {
|
||||||
|
@ -31,6 +32,7 @@ bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::enqueueBatch(Batch& batch) {
|
void Context::render(Batch& batch) {
|
||||||
GLBackend::renderBatch(batch, true);
|
_backend->render(batch);
|
||||||
|
// GLBackend::renderBatch(batch, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ class Batch;
|
||||||
class Backend {
|
class Backend {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual~ Backend() {};
|
||||||
|
virtual void render(Batch& batch) = 0;
|
||||||
|
|
||||||
class TransformObject {
|
class TransformObject {
|
||||||
public:
|
public:
|
||||||
Mat4 _model;
|
Mat4 _model;
|
||||||
|
@ -107,15 +110,14 @@ protected:
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
Context();
|
Context(Backend* backend);
|
||||||
Context(const Context& context);
|
|
||||||
~Context();
|
~Context();
|
||||||
|
|
||||||
void enqueueBatch(Batch& batch);
|
void render(Batch& batch);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Context(const Context& context);
|
||||||
|
|
||||||
// This function can only be called by "static Shader::makeProgram()"
|
// This function can only be called by "static Shader::makeProgram()"
|
||||||
// makeProgramShader(...) make a program shader ready to be used in a Batch.
|
// makeProgramShader(...) make a program shader ready to be used in a Batch.
|
||||||
|
@ -123,6 +125,8 @@ protected:
|
||||||
// If the shader passed is not a program, nothing happens.
|
// If the shader passed is not a program, nothing happens.
|
||||||
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
|
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
|
||||||
|
|
||||||
|
std::unique_ptr<Backend> _backend;
|
||||||
|
|
||||||
friend class Shader;
|
friend class Shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -442,6 +442,8 @@ void Batch::_glUniform1f(GLint location, GLfloat v0) {
|
||||||
}
|
}
|
||||||
void GLBackend::do_glUniform1f(Batch& batch, uint32 paramOffset) {
|
void GLBackend::do_glUniform1f(Batch& batch, uint32 paramOffset) {
|
||||||
if (_pipeline._program == 0) {
|
if (_pipeline._program == 0) {
|
||||||
|
// We should call updatePipeline() to bind the program but we are not doing that
|
||||||
|
// because these uniform setters are deprecated and we don;t want to create side effect
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glUniform1f(
|
glUniform1f(
|
||||||
|
@ -460,6 +462,11 @@ void Batch::_glUniform2f(GLint location, GLfloat v0, GLfloat v1) {
|
||||||
DO_IT_NOW(_glUniform2f, 1);
|
DO_IT_NOW(_glUniform2f, 1);
|
||||||
}
|
}
|
||||||
void GLBackend::do_glUniform2f(Batch& batch, uint32 paramOffset) {
|
void GLBackend::do_glUniform2f(Batch& batch, uint32 paramOffset) {
|
||||||
|
if (_pipeline._program == 0) {
|
||||||
|
// We should call updatePipeline() to bind the program but we are not doing that
|
||||||
|
// because these uniform setters are deprecated and we don;t want to create side effect
|
||||||
|
return;
|
||||||
|
}
|
||||||
glUniform2f(
|
glUniform2f(
|
||||||
batch._params[paramOffset + 2]._int,
|
batch._params[paramOffset + 2]._int,
|
||||||
batch._params[paramOffset + 1]._float,
|
batch._params[paramOffset + 1]._float,
|
||||||
|
@ -478,6 +485,11 @@ void Batch::_glUniform4fv(GLint location, GLsizei count, const GLfloat* value) {
|
||||||
DO_IT_NOW(_glUniform4fv, 3);
|
DO_IT_NOW(_glUniform4fv, 3);
|
||||||
}
|
}
|
||||||
void GLBackend::do_glUniform4fv(Batch& batch, uint32 paramOffset) {
|
void GLBackend::do_glUniform4fv(Batch& batch, uint32 paramOffset) {
|
||||||
|
if (_pipeline._program == 0) {
|
||||||
|
// We should call updatePipeline() to bind the program but we are not doing that
|
||||||
|
// because these uniform setters are deprecated and we don;t want to create side effect
|
||||||
|
return;
|
||||||
|
}
|
||||||
glUniform4fv(
|
glUniform4fv(
|
||||||
batch._params[paramOffset + 2]._int,
|
batch._params[paramOffset + 2]._int,
|
||||||
batch._params[paramOffset + 1]._uint,
|
batch._params[paramOffset + 1]._uint,
|
||||||
|
@ -498,6 +510,11 @@ void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpo
|
||||||
DO_IT_NOW(_glUniformMatrix4fv, 4);
|
DO_IT_NOW(_glUniformMatrix4fv, 4);
|
||||||
}
|
}
|
||||||
void GLBackend::do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset) {
|
void GLBackend::do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset) {
|
||||||
|
if (_pipeline._program == 0) {
|
||||||
|
// We should call updatePipeline() to bind the program but we are not doing that
|
||||||
|
// because these uniform setters are deprecated and we don;t want to create side effect
|
||||||
|
return;
|
||||||
|
}
|
||||||
glUniformMatrix4fv(
|
glUniformMatrix4fv(
|
||||||
batch._params[paramOffset + 3]._int,
|
batch._params[paramOffset + 3]._int,
|
||||||
batch._params[paramOffset + 2]._uint,
|
batch._params[paramOffset + 2]._uint,
|
||||||
|
|
|
@ -26,9 +26,9 @@ public:
|
||||||
|
|
||||||
explicit GLBackend(bool syncCache);
|
explicit GLBackend(bool syncCache);
|
||||||
GLBackend();
|
GLBackend();
|
||||||
~GLBackend();
|
virtual ~GLBackend();
|
||||||
|
|
||||||
void render(Batch& batch);
|
virtual void render(Batch& batch);
|
||||||
|
|
||||||
// Render Batch create a local Context and execute the batch with it
|
// Render Batch create a local Context and execute the batch with it
|
||||||
// WARNING:
|
// WARNING:
|
||||||
|
|
|
@ -107,7 +107,7 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured) {
|
void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured) {
|
||||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true);
|
// DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, true, true);
|
||||||
|
|
||||||
if (textured) {
|
if (textured) {
|
||||||
batch.setPipeline(_simpleProgramTextured);
|
batch.setPipeline(_simpleProgramTextured);
|
||||||
|
@ -117,7 +117,7 @@ void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) {
|
void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) {
|
||||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, false, false);
|
// DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(batch, true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) {
|
void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) {
|
||||||
|
|
|
@ -783,7 +783,7 @@ namespace render {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> const Item::Bound payloadGetBound(const TransparentMeshPart::Pointer& payload) {
|
template <> const Item::Bound payloadGetBound(const TransparentMeshPart::Pointer& payload) {
|
||||||
qDebug() << "payloadGetBound(TransparentMeshPart) url:" << payload->model->getURL();
|
//qDebug() << "payloadGetBound(TransparentMeshPart) url:" << payload->model->getURL();
|
||||||
if (payload) {
|
if (payload) {
|
||||||
//return payload->model->getPartBounds(payload->meshIndex, payload->partIndex);
|
//return payload->model->getPartBounds(payload->meshIndex, payload->partIndex);
|
||||||
}
|
}
|
||||||
|
@ -791,7 +791,7 @@ namespace render {
|
||||||
}
|
}
|
||||||
template <> void payloadRender(const TransparentMeshPart::Pointer& payload, RenderArgs* args) {
|
template <> void payloadRender(const TransparentMeshPart::Pointer& payload, RenderArgs* args) {
|
||||||
if (args) {
|
if (args) {
|
||||||
qDebug() << "payloadRender(TransparentMeshPart) url:" << payload->model->getURL();
|
// qDebug() << "payloadRender(TransparentMeshPart) url:" << payload->model->getURL();
|
||||||
args->_elementsTouched++;
|
args->_elementsTouched++;
|
||||||
return payload->model->renderPart(args, payload->meshIndex, payload->partIndex, true);
|
return payload->model->renderPart(args, payload->meshIndex, payload->partIndex, true);
|
||||||
}
|
}
|
||||||
|
@ -815,7 +815,7 @@ namespace render {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> const Item::Bound payloadGetBound(const OpaqueMeshPart::Pointer& payload) {
|
template <> const Item::Bound payloadGetBound(const OpaqueMeshPart::Pointer& payload) {
|
||||||
qDebug() << "payloadGetBound(OpaqueMeshPart) url:" << payload->model->getURL();
|
// qDebug() << "payloadGetBound(OpaqueMeshPart) url:" << payload->model->getURL();
|
||||||
if (payload) {
|
if (payload) {
|
||||||
//return payload->model->getPartBounds(payload->meshIndex, payload->partIndex);
|
//return payload->model->getPartBounds(payload->meshIndex, payload->partIndex);
|
||||||
}
|
}
|
||||||
|
@ -823,7 +823,7 @@ namespace render {
|
||||||
}
|
}
|
||||||
template <> void payloadRender(const OpaqueMeshPart::Pointer& payload, RenderArgs* args) {
|
template <> void payloadRender(const OpaqueMeshPart::Pointer& payload, RenderArgs* args) {
|
||||||
if (args) {
|
if (args) {
|
||||||
qDebug() << "payloadRender(OpaqueMeshPart) url:" << payload->model->getURL();
|
// qDebug() << "payloadRender(OpaqueMeshPart) url:" << payload->model->getURL();
|
||||||
args->_elementsTouched++;
|
args->_elementsTouched++;
|
||||||
return payload->model->renderPart(args, payload->meshIndex, payload->partIndex, false);
|
return payload->model->renderPart(args, payload->meshIndex, payload->partIndex, false);
|
||||||
}
|
}
|
||||||
|
@ -1957,9 +1957,12 @@ void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::endScene(RenderArgs* args) {
|
void Model::endScene(RenderArgs* args) {
|
||||||
|
// Now that we migrated everything to the new RENDER/SCENE no more work to do!
|
||||||
|
return;
|
||||||
PROFILE_RANGE(__FUNCTION__);
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if (GPU_TRANSFORM_PROFILE == GPU_LEGACY)
|
#if (GPU_TRANSFORM_PROFILE == GPU_LEGACY)
|
||||||
// with legacy transform profile, we still to protect that transform stack...
|
// with legacy transform profile, we still to protect that transform stack...
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -1972,6 +1975,7 @@ void Model::endScene(RenderArgs* args) {
|
||||||
renderSide = args->_renderSide;
|
renderSide = args->_renderSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gpu::GLBackend backend;
|
gpu::GLBackend backend;
|
||||||
backend.syncCache(); // force sync with gl state here
|
backend.syncCache(); // force sync with gl state here
|
||||||
|
|
||||||
|
@ -2191,7 +2195,7 @@ AABox Model::getPartBounds(int meshIndex, int partIndex) {
|
||||||
void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool translucent) {
|
void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool translucent) {
|
||||||
//renderCore(args, 1.0f);
|
//renderCore(args, 1.0f);
|
||||||
//return;
|
//return;
|
||||||
qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
//qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
||||||
renderSetup(args);
|
renderSetup(args);
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
|
|
||||||
|
@ -2229,7 +2233,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
|
|
||||||
|
|
||||||
// FIXME: Do I need this? it doesn't seem to do anything.
|
// FIXME: Do I need this? it doesn't seem to do anything.
|
||||||
{
|
/* {
|
||||||
GLenum buffers[3];
|
GLenum buffers[3];
|
||||||
int bufferCount = 0;
|
int bufferCount = 0;
|
||||||
|
|
||||||
|
@ -2243,7 +2247,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
|
||||||
}
|
}
|
||||||
GLBATCH(glDrawBuffers)(bufferCount, buffers);
|
GLBATCH(glDrawBuffers)(bufferCount, buffers);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
const float DEFAULT_ALPHA_THRESHOLD = 0.5f; //
|
const float DEFAULT_ALPHA_THRESHOLD = 0.5f; //
|
||||||
auto alphaThreshold = DEFAULT_ALPHA_THRESHOLD; // FIX ME
|
auto alphaThreshold = DEFAULT_ALPHA_THRESHOLD; // FIX ME
|
||||||
|
@ -2285,7 +2289,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
|
|
||||||
if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {
|
if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {
|
||||||
_meshGroupsKnown = false; // regenerate these lists next time around.
|
_meshGroupsKnown = false; // regenerate these lists next time around.
|
||||||
qDebug() << "if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {.... BAIL!!!";
|
// qDebug() << "if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {.... BAIL!!!";
|
||||||
return; // FIXME!
|
return; // FIXME!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2297,7 +2301,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
int vertexCount = mesh.vertices.size();
|
int vertexCount = mesh.vertices.size();
|
||||||
if (vertexCount == 0) {
|
if (vertexCount == 0) {
|
||||||
// sanity check
|
// sanity check
|
||||||
qDebug() << "if (vertexCount == 0) {.... BAIL!!!";
|
// qDebug() << "if (vertexCount == 0) {.... BAIL!!!";
|
||||||
return; // FIXME!
|
return; // FIXME!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2321,10 +2325,10 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh.colors.isEmpty()) {
|
if (mesh.colors.isEmpty()) {
|
||||||
qDebug() << " colors empty ... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
// qDebug() << " colors empty ... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
||||||
GLBATCH(glColor4f)(1.0f, 1.0f, 1.0f, 1.0f);
|
GLBATCH(glColor4f)(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << " colors size:" << mesh.colors.size() << " ... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
// qDebug() << " colors size:" << mesh.colors.size() << " ... meshIndex:" << meshIndex << "partIndex:" << partIndex << "url:" << _url;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 offset = 0;
|
qint64 offset = 0;
|
||||||
|
@ -2333,6 +2337,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
const FBXMeshPart& part = mesh.parts.at(j);
|
const FBXMeshPart& part = mesh.parts.at(j);
|
||||||
model::MaterialPointer material = part._material;
|
model::MaterialPointer material = part._material;
|
||||||
|
|
||||||
|
if (material != nullptr) {
|
||||||
/*
|
/*
|
||||||
if ((networkPart.isTranslucent() || part.opacity != 1.0f) != translucent) {
|
if ((networkPart.isTranslucent() || part.opacity != 1.0f) != translucent) {
|
||||||
offset += (part.quadIndices.size() + part.triangleIndices.size()) * sizeof(int);
|
offset += (part.quadIndices.size() + part.triangleIndices.size()) * sizeof(int);
|
||||||
|
@ -2346,7 +2351,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (true) { //lastMaterialID != part.materialID) {
|
if (true) { //lastMaterialID != part.materialID) {
|
||||||
const bool wantDebug = true;
|
const bool wantDebug = false;
|
||||||
if (wantDebug) {
|
if (wantDebug) {
|
||||||
qCDebug(renderutils) << "Material Changed ---------------------------------------------";
|
qCDebug(renderutils) << "Material Changed ---------------------------------------------";
|
||||||
qCDebug(renderutils) << "part INDEX:" << j;
|
qCDebug(renderutils) << "part INDEX:" << j;
|
||||||
|
@ -2364,31 +2369,31 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
}
|
}
|
||||||
static bool showDiffuse = true;
|
static bool showDiffuse = true;
|
||||||
if (showDiffuse && diffuseMap) {
|
if (showDiffuse && diffuseMap) {
|
||||||
qCDebug(renderutils) << " batch.setUniformTexture(0, diffuseMap->getGPUTexture());";
|
// qCDebug(renderutils) << " batch.setUniformTexture(0, diffuseMap->getGPUTexture());";
|
||||||
batch.setUniformTexture(0, diffuseMap->getGPUTexture());
|
batch.setUniformTexture(0, diffuseMap->getGPUTexture());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCDebug(renderutils) << " batch.setUniformTexture(0, textureCache->getWhiteTexture());";
|
// qCDebug(renderutils) << " batch.setUniformTexture(0, textureCache->getWhiteTexture());";
|
||||||
batch.setUniformTexture(0, textureCache->getWhiteTexture());
|
batch.setUniformTexture(0, textureCache->getWhiteTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locations->texcoordMatrices >= 0) {
|
if (locations->texcoordMatrices >= 0) {
|
||||||
glm::mat4 texcoordTransform[2];
|
glm::mat4 texcoordTransform[2];
|
||||||
if (!part.diffuseTexture.transform.isIdentity()) {
|
if (!part.diffuseTexture.transform.isIdentity()) {
|
||||||
qCDebug(renderutils) << " part.diffuseTexture.transform.getMatrix(texcoordTransform[0]);";
|
// qCDebug(renderutils) << " part.diffuseTexture.transform.getMatrix(texcoordTransform[0]);";
|
||||||
part.diffuseTexture.transform.getMatrix(texcoordTransform[0]);
|
part.diffuseTexture.transform.getMatrix(texcoordTransform[0]);
|
||||||
}
|
}
|
||||||
if (!part.emissiveTexture.transform.isIdentity()) {
|
if (!part.emissiveTexture.transform.isIdentity()) {
|
||||||
qCDebug(renderutils) << " part.emissiveTexture.transform.getMatrix(texcoordTransform[1]);";
|
// qCDebug(renderutils) << " part.emissiveTexture.transform.getMatrix(texcoordTransform[1]);";
|
||||||
part.emissiveTexture.transform.getMatrix(texcoordTransform[1]);
|
part.emissiveTexture.transform.getMatrix(texcoordTransform[1]);
|
||||||
}
|
}
|
||||||
qCDebug(renderutils) << " GLBATCH(glUniformMatrix4fv)(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform);";
|
// qCDebug(renderutils) << " GLBATCH(glUniformMatrix4fv)(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform);";
|
||||||
GLBATCH(glUniformMatrix4fv)(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform);
|
GLBATCH(glUniformMatrix4fv)(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mesh.tangents.isEmpty()) {
|
if (!mesh.tangents.isEmpty()) {
|
||||||
Texture* normalMap = networkPart.normalTexture.data();
|
Texture* normalMap = networkPart.normalTexture.data();
|
||||||
qCDebug(renderutils) << " batch.setUniformTexture(1, !normalMap ? textureCache->getBlueTexture() : normalMap->getGPUTexture());";
|
// qCDebug(renderutils) << " batch.setUniformTexture(1, !normalMap ? textureCache->getBlueTexture() : normalMap->getGPUTexture());";
|
||||||
batch.setUniformTexture(1, !normalMap ?
|
batch.setUniformTexture(1, !normalMap ?
|
||||||
textureCache->getBlueTexture() : normalMap->getGPUTexture());
|
textureCache->getBlueTexture() : normalMap->getGPUTexture());
|
||||||
|
|
||||||
|
@ -2396,7 +2401,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
|
|
||||||
if (locations->specularTextureUnit >= 0) {
|
if (locations->specularTextureUnit >= 0) {
|
||||||
Texture* specularMap = networkPart.specularTexture.data();
|
Texture* specularMap = networkPart.specularTexture.data();
|
||||||
qCDebug(renderutils) << " batch.setUniformTexture(locations->specularTextureUnit, !specularMap ? textureCache->getWhiteTexture() : specularMap->getGPUTexture());";
|
// qCDebug(renderutils) << " batch.setUniformTexture(locations->specularTextureUnit, !specularMap ? textureCache->getWhiteTexture() : specularMap->getGPUTexture());";
|
||||||
batch.setUniformTexture(locations->specularTextureUnit, !specularMap ?
|
batch.setUniformTexture(locations->specularTextureUnit, !specularMap ?
|
||||||
textureCache->getWhiteTexture() : specularMap->getGPUTexture());
|
textureCache->getWhiteTexture() : specularMap->getGPUTexture());
|
||||||
}
|
}
|
||||||
|
@ -2416,10 +2421,12 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale);
|
GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale);
|
||||||
|
|
||||||
Texture* emissiveMap = networkPart.emissiveTexture.data();
|
Texture* emissiveMap = networkPart.emissiveTexture.data();
|
||||||
qCDebug(renderutils) << " batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ? textureCache->getWhiteTexture() : emissiveMap->getGPUTexture());";
|
// qCDebug(renderutils) << " batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ? textureCache->getWhiteTexture() : emissiveMap->getGPUTexture());";
|
||||||
batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ?
|
batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ?
|
||||||
textureCache->getWhiteTexture() : emissiveMap->getGPUTexture());
|
textureCache->getWhiteTexture() : emissiveMap->getGPUTexture());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
lastMaterialID = part.materialID;
|
lastMaterialID = part.materialID;
|
||||||
}
|
}
|
||||||
|
@ -2427,13 +2434,13 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
meshPartsRendered++;
|
meshPartsRendered++;
|
||||||
|
|
||||||
if (part.quadIndices.size() > 0) {
|
if (part.quadIndices.size() > 0) {
|
||||||
qDebug() << "batch.drawIndexed(gpu::QUADS) size:" << part.quadIndices.size();
|
// qDebug() << "batch.drawIndexed(gpu::QUADS) size:" << part.quadIndices.size();
|
||||||
batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset);
|
batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset);
|
||||||
offset += part.quadIndices.size() * sizeof(int);
|
offset += part.quadIndices.size() * sizeof(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.triangleIndices.size() > 0) {
|
if (part.triangleIndices.size() > 0) {
|
||||||
qDebug() << "batch.drawIndexed(gpu::TRIANGLES) size:" << part.triangleIndices.size();
|
// qDebug() << "batch.drawIndexed(gpu::TRIANGLES) size:" << part.triangleIndices.size();
|
||||||
batch.drawIndexed(gpu::TRIANGLES, part.triangleIndices.size(), offset);
|
batch.drawIndexed(gpu::TRIANGLES, part.triangleIndices.size(), offset);
|
||||||
offset += part.triangleIndices.size() * sizeof(int);
|
offset += part.triangleIndices.size() * sizeof(int);
|
||||||
}
|
}
|
||||||
|
@ -2483,7 +2490,7 @@ qDebug() << "Model::renderPart()... meshIndex:" << meshIndex << "partIndex:" <<
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Back to no program
|
// Back to no program
|
||||||
GLBATCH(glUseProgram)(0); // NOTE: We need this or else the avatar will end up with the texture of the last entity
|
// GLBATCH(glUseProgram)(0); // NOTE: We need this or else the avatar will end up with the texture of the last entity
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::segregateMeshGroups() {
|
void Model::segregateMeshGroups() {
|
||||||
|
|
|
@ -55,73 +55,6 @@ void DrawSceneTask::run(const SceneContextPointer& sceneContext, const RenderCon
|
||||||
Job::~Job() {
|
Job::~Job() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> void render::jobRun(const DrawOpaque& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
|
||||||
assert(renderContext->args);
|
|
||||||
assert(renderContext->args->_viewFrustum);
|
|
||||||
|
|
||||||
// render opaques
|
|
||||||
auto& scene = sceneContext->_scene;
|
|
||||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::opaqueShape());
|
|
||||||
|
|
||||||
ItemIDs inItems;
|
|
||||||
inItems.reserve(items.size());
|
|
||||||
for (auto id : items) {
|
|
||||||
inItems.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemIDs culledItems;
|
|
||||||
cullItems(sceneContext, renderContext, inItems, culledItems);
|
|
||||||
|
|
||||||
ItemIDs sortedItems;
|
|
||||||
depthSortItems(sceneContext, renderContext, true, culledItems, sortedItems); // Sort Front to back opaque items!
|
|
||||||
|
|
||||||
renderItems(sceneContext, renderContext, sortedItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <> void render::jobRun(const DrawTransparent& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
|
||||||
assert(renderContext->args);
|
|
||||||
assert(renderContext->args->_viewFrustum);
|
|
||||||
|
|
||||||
// render transparents
|
|
||||||
auto& scene = sceneContext->_scene;
|
|
||||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::transparentShape());
|
|
||||||
|
|
||||||
ItemIDs inItems;
|
|
||||||
inItems.reserve(items.size());
|
|
||||||
for (auto id : items) {
|
|
||||||
inItems.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemIDs culledItems;
|
|
||||||
cullItems(sceneContext, renderContext, inItems, culledItems);
|
|
||||||
|
|
||||||
ItemIDs sortedItems;
|
|
||||||
depthSortItems(sceneContext, renderContext, false, culledItems, sortedItems); // Sort Back to front transparent items!
|
|
||||||
|
|
||||||
renderItems(sceneContext, renderContext, sortedItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> void render::jobRun(const DrawLight& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
|
||||||
assert(renderContext->args);
|
|
||||||
assert(renderContext->args->_viewFrustum);
|
|
||||||
|
|
||||||
// render lights
|
|
||||||
auto& scene = sceneContext->_scene;
|
|
||||||
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::light());
|
|
||||||
|
|
||||||
|
|
||||||
ItemIDs inItems;
|
|
||||||
inItems.reserve(items.size());
|
|
||||||
for (auto id : items) {
|
|
||||||
inItems.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemIDs culledItems;
|
|
||||||
cullItems(sceneContext, renderContext, inItems, culledItems);
|
|
||||||
renderItems(sceneContext, renderContext, culledItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
||||||
const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it.
|
const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it.
|
||||||
|
@ -263,16 +196,155 @@ void render::depthSortItems(const SceneContextPointer& sceneContext, const Rende
|
||||||
void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDs& inItems) {
|
void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDs& inItems) {
|
||||||
auto& scene = sceneContext->_scene;
|
auto& scene = sceneContext->_scene;
|
||||||
RenderArgs* args = renderContext->args;
|
RenderArgs* args = renderContext->args;
|
||||||
gpu::Batch theBatch;
|
|
||||||
args->_batch = &theBatch;
|
|
||||||
|
|
||||||
// render
|
// render
|
||||||
for (auto id : inItems) {
|
for (auto id : inItems) {
|
||||||
auto item = scene->getItem(id);
|
auto item = scene->getItem(id);
|
||||||
item.render(args);
|
item.render(args);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
args->_context->enqueueBatch((*args->_batch));
|
void addClearStateCommands(gpu::Batch& batch) {
|
||||||
|
batch._glDepthMask(true);
|
||||||
|
batch._glDepthFunc(GL_LESS);
|
||||||
|
batch._glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
batch._glActiveTexture(GL_TEXTURE0 + 1);
|
||||||
|
batch._glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
batch._glActiveTexture(GL_TEXTURE0 + 2);
|
||||||
|
batch._glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
batch._glActiveTexture(GL_TEXTURE0 + 3);
|
||||||
|
batch._glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
batch._glActiveTexture(GL_TEXTURE0);
|
||||||
|
batch._glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// deactivate vertex arrays after drawing
|
||||||
|
batch._glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
batch._glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
batch._glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
batch._glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
batch._glDisableVertexAttribArray(gpu::Stream::TANGENT);
|
||||||
|
batch._glDisableVertexAttribArray(gpu::Stream::SKIN_CLUSTER_INDEX);
|
||||||
|
batch._glDisableVertexAttribArray(gpu::Stream::SKIN_CLUSTER_WEIGHT);
|
||||||
|
|
||||||
|
// bind with 0 to switch back to normal operation
|
||||||
|
batch._glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
batch._glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
// Back to no program
|
||||||
|
batch._glUseProgram(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <> void render::jobRun(const DrawOpaque& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||||
|
assert(renderContext->args);
|
||||||
|
assert(renderContext->args->_viewFrustum);
|
||||||
|
|
||||||
|
// render opaques
|
||||||
|
auto& scene = sceneContext->_scene;
|
||||||
|
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::opaqueShape());
|
||||||
|
|
||||||
|
ItemIDs inItems;
|
||||||
|
inItems.reserve(items.size());
|
||||||
|
for (auto id : items) {
|
||||||
|
inItems.push_back(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemIDs culledItems;
|
||||||
|
cullItems(sceneContext, renderContext, inItems, culledItems);
|
||||||
|
|
||||||
|
ItemIDs sortedItems;
|
||||||
|
depthSortItems(sceneContext, renderContext, true, culledItems, sortedItems); // Sort Front to back opaque items!
|
||||||
|
|
||||||
|
RenderArgs* args = renderContext->args;
|
||||||
|
gpu::Batch theBatch;
|
||||||
|
args->_batch = &theBatch;
|
||||||
|
|
||||||
|
glm::mat4 proj;
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
theBatch.setProjectionTransform(proj);
|
||||||
|
|
||||||
|
renderContext->args->_renderMode = RenderArgs::NORMAL_RENDER_MODE;
|
||||||
|
{
|
||||||
|
GLenum buffers[3];
|
||||||
|
int bufferCount = 0;
|
||||||
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
|
||||||
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
|
||||||
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
|
||||||
|
theBatch._glDrawBuffers(bufferCount, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderItems(sceneContext, renderContext, sortedItems);
|
||||||
|
|
||||||
|
addClearStateCommands((*args->_batch));
|
||||||
|
args->_context->render((*args->_batch));
|
||||||
|
args->_batch = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <> void render::jobRun(const DrawTransparent& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||||
|
assert(renderContext->args);
|
||||||
|
assert(renderContext->args->_viewFrustum);
|
||||||
|
|
||||||
|
// render transparents
|
||||||
|
auto& scene = sceneContext->_scene;
|
||||||
|
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::transparentShape());
|
||||||
|
|
||||||
|
ItemIDs inItems;
|
||||||
|
inItems.reserve(items.size());
|
||||||
|
for (auto id : items) {
|
||||||
|
inItems.push_back(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemIDs culledItems;
|
||||||
|
cullItems(sceneContext, renderContext, inItems, culledItems);
|
||||||
|
|
||||||
|
ItemIDs sortedItems;
|
||||||
|
depthSortItems(sceneContext, renderContext, false, culledItems, sortedItems); // Sort Back to front transparent items!
|
||||||
|
|
||||||
|
RenderArgs* args = renderContext->args;
|
||||||
|
gpu::Batch theBatch;
|
||||||
|
args->_batch = &theBatch;
|
||||||
|
|
||||||
|
renderContext->args->_renderMode = RenderArgs::NORMAL_RENDER_MODE;
|
||||||
|
{
|
||||||
|
GLenum buffers[3];
|
||||||
|
int bufferCount = 0;
|
||||||
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
|
||||||
|
theBatch._glDrawBuffers(bufferCount, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderItems(sceneContext, renderContext, sortedItems);
|
||||||
|
|
||||||
|
addClearStateCommands((*args->_batch));
|
||||||
|
args->_context->render((*args->_batch));
|
||||||
|
args->_batch = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> void render::jobRun(const DrawLight& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||||
|
assert(renderContext->args);
|
||||||
|
assert(renderContext->args->_viewFrustum);
|
||||||
|
|
||||||
|
// render lights
|
||||||
|
auto& scene = sceneContext->_scene;
|
||||||
|
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::light());
|
||||||
|
|
||||||
|
|
||||||
|
ItemIDs inItems;
|
||||||
|
inItems.reserve(items.size());
|
||||||
|
for (auto id : items) {
|
||||||
|
inItems.push_back(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemIDs culledItems;
|
||||||
|
cullItems(sceneContext, renderContext, inItems, culledItems);
|
||||||
|
|
||||||
|
RenderArgs* args = renderContext->args;
|
||||||
|
gpu::Batch theBatch;
|
||||||
|
args->_batch = &theBatch;
|
||||||
|
renderItems(sceneContext, renderContext, culledItems);
|
||||||
|
args->_context->render((*args->_batch));
|
||||||
args->_batch = nullptr;
|
args->_batch = nullptr;
|
||||||
}
|
}
|
Loading…
Reference in a new issue