STARK: Ported opengl minor code changes
This commit is contained in:
parent
0d270ad89b
commit
b4f8414a44
6 changed files with 50 additions and 55 deletions
|
@ -58,9 +58,9 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
_model->updateBoundingBox();
|
_model->updateBoundingBox();
|
||||||
|
|
||||||
bool drawShadow = false;
|
bool drawShadow = false;
|
||||||
if (_castsShadow
|
if (_castsShadow &&
|
||||||
&& StarkScene->shouldRenderShadows()
|
StarkScene->shouldRenderShadows() &&
|
||||||
&& StarkSettings->getBoolSetting(Settings::kShadow)) {
|
StarkSettings->getBoolSetting(Settings::kShadow)) {
|
||||||
drawShadow = true;
|
drawShadow = true;
|
||||||
}
|
}
|
||||||
Math::Vector3d lightDirection;
|
Math::Vector3d lightDirection;
|
||||||
|
@ -101,8 +101,6 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
lightDirection = getShadowLightDirection(lights, position, modelInverse.getRotation());
|
lightDirection = getShadowLightDirection(lights, position, modelInverse.getRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
Common::Array<Face *> faces = _model->getFaces();
|
Common::Array<Face *> faces = _model->getFaces();
|
||||||
Common::Array<Material *> mats = _model->getMaterials();
|
Common::Array<Material *> mats = _model->getMaterials();
|
||||||
const Common::Array<BoneNode *> &bones = _model->getBones();
|
const Common::Array<BoneNode *> &bones = _model->getBones();
|
||||||
|
@ -116,17 +114,22 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
const Material *material = mats[(*face)->materialId];
|
const Material *material = mats[(*face)->materialId];
|
||||||
Math::Vector3d color;
|
Math::Vector3d color;
|
||||||
const Gfx::Texture *tex = resolveTexture(material);
|
const Gfx::Texture *tex = resolveTexture(material);
|
||||||
|
if (tex) {
|
||||||
|
tex->bind();
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
} else {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
auto vertexIndices = _faceEBO[*face];
|
auto vertexIndices = _faceEBO[*face];
|
||||||
auto numVertexIndices = (*face)->vertexIndices.size();
|
auto numVertexIndices = (*face)->vertexIndices.size();
|
||||||
for (uint32 i = 0; i < numVertexIndices; i++) {
|
for (uint32 i = 0; i < numVertexIndices; i++) {
|
||||||
if (tex) {
|
if (tex) {
|
||||||
tex->bind();
|
|
||||||
if (_gfx->computeLightsEnabled())
|
if (_gfx->computeLightsEnabled())
|
||||||
color = Math::Vector3d(1.0f, 1.0f, 1.0f);
|
color = Math::Vector3d(1.0f, 1.0f, 1.0f);
|
||||||
else
|
else
|
||||||
glColor3f(1.0f, 1.0f, 1.0f);
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
if (_gfx->computeLightsEnabled())
|
if (_gfx->computeLightsEnabled())
|
||||||
color = Math::Vector3d(material->r, material->g, material->b);
|
color = Math::Vector3d(material->r, material->g, material->b);
|
||||||
else
|
else
|
||||||
|
@ -139,19 +142,19 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
Math::Vector3d position1 = Math::Vector3d(vertex.pos1x, vertex.pos1y, vertex.pos1z);
|
Math::Vector3d position1 = Math::Vector3d(vertex.pos1x, vertex.pos1y, vertex.pos1z);
|
||||||
Math::Vector3d position2 = Math::Vector3d(vertex.pos2x, vertex.pos2y, vertex.pos2z);
|
Math::Vector3d position2 = Math::Vector3d(vertex.pos2x, vertex.pos2y, vertex.pos2z);
|
||||||
Math::Vector3d bone1Position = Math::Vector3d(bones[bone1]->_animPos.x(),
|
Math::Vector3d bone1Position = Math::Vector3d(bones[bone1]->_animPos.x(),
|
||||||
bones[bone1]->_animPos.y(),
|
bones[bone1]->_animPos.y(),
|
||||||
bones[bone1]->_animPos.z());
|
bones[bone1]->_animPos.z());
|
||||||
Math::Vector3d bone2Position = Math::Vector3d(bones[bone2]->_animPos.x(),
|
Math::Vector3d bone2Position = Math::Vector3d(bones[bone2]->_animPos.x(),
|
||||||
bones[bone2]->_animPos.y(),
|
bones[bone2]->_animPos.y(),
|
||||||
bones[bone2]->_animPos.z());
|
bones[bone2]->_animPos.z());
|
||||||
Math::Quaternion bone1Rotation = Math::Quaternion(bones[bone1]->_animRot.x(),
|
Math::Quaternion bone1Rotation = Math::Quaternion(bones[bone1]->_animRot.x(),
|
||||||
bones[bone1]->_animRot.y(),
|
bones[bone1]->_animRot.y(),
|
||||||
bones[bone1]->_animRot.z(),
|
bones[bone1]->_animRot.z(),
|
||||||
bones[bone1]->_animRot.w());
|
bones[bone1]->_animRot.w());
|
||||||
Math::Quaternion bone2Rotation = Math::Quaternion(bones[bone2]->_animRot.x(),
|
Math::Quaternion bone2Rotation = Math::Quaternion(bones[bone2]->_animRot.x(),
|
||||||
bones[bone2]->_animRot.y(),
|
bones[bone2]->_animRot.y(),
|
||||||
bones[bone2]->_animRot.z(),
|
bones[bone2]->_animRot.z(),
|
||||||
bones[bone2]->_animRot.w());
|
bones[bone2]->_animRot.w());
|
||||||
float boneWeight = vertex.boneWeight;
|
float boneWeight = vertex.boneWeight;
|
||||||
Math::Vector3d normal = Math::Vector3d(vertex.normalx, vertex.normaly, vertex.normalz);
|
Math::Vector3d normal = Math::Vector3d(vertex.normalx, vertex.normaly, vertex.normalz);
|
||||||
|
|
||||||
|
@ -167,9 +170,9 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
Math::Vector4d modelEyePosition;
|
Math::Vector4d modelEyePosition;
|
||||||
if (_gfx->computeLightsEnabled()) {
|
if (_gfx->computeLightsEnabled()) {
|
||||||
modelEyePosition = modelViewMatrix * Math::Vector4d(modelPosition.x(),
|
modelEyePosition = modelViewMatrix * Math::Vector4d(modelPosition.x(),
|
||||||
modelPosition.y(),
|
modelPosition.y(),
|
||||||
modelPosition.z(),
|
modelPosition.z(),
|
||||||
1.0);
|
1.0);
|
||||||
}
|
}
|
||||||
// Compute the vertex normal in eye-space
|
// Compute the vertex normal in eye-space
|
||||||
Math::Vector3d n1 = normal;
|
Math::Vector3d n1 = normal;
|
||||||
|
@ -302,7 +305,6 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
|
||||||
|
|
||||||
if (!_gfx->computeLightsEnabled())
|
if (!_gfx->computeLightsEnabled())
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
@ -363,8 +365,8 @@ uint32 *OpenGLActorRenderer::createFaceEBO(const Face *face) {
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArray &lights,
|
Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot) {
|
Math::Matrix3 worldToModelRot) {
|
||||||
Math::Vector3d sumDirection;
|
Math::Vector3d sumDirection;
|
||||||
bool hasLight = false;
|
bool hasLight = false;
|
||||||
|
|
||||||
|
@ -418,8 +420,8 @@ Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArra
|
||||||
return worldToModelRot * sumDirection;
|
return worldToModelRot * sumDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLActorRenderer::getPointLightContribution(LightEntry *light,
|
bool OpenGLActorRenderer::getPointLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Vector3d &direction, float weight) {
|
Math::Vector3d &direction, float weight) {
|
||||||
float distance = light->position.getDistanceTo(actorPosition);
|
float distance = light->position.getDistanceTo(actorPosition);
|
||||||
|
|
||||||
if (distance > light->falloffFar) {
|
if (distance > light->falloffFar) {
|
||||||
|
@ -464,14 +466,14 @@ bool OpenGLActorRenderer::getDirectionalLightContribution(LightEntry *light, Mat
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLActorRenderer::getSpotLightContribution(LightEntry *light,
|
bool OpenGLActorRenderer::getSpotLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Vector3d &direction) {
|
Math::Vector3d &direction) {
|
||||||
Math::Vector3d lightToActor = actorPosition - light->position;
|
Math::Vector3d lightToActor = actorPosition - light->position;
|
||||||
lightToActor.normalize();
|
lightToActor.normalize();
|
||||||
|
|
||||||
float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
|
float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
|
||||||
float cone = (cosAngle - light->innerConeAngle.getCosine()) /
|
float cone = (cosAngle - light->innerConeAngle.getCosine()) /
|
||||||
MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
|
MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
|
||||||
cone = CLIP(cone, 0.0f, 1.0f);
|
cone = CLIP(cone, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (cone <= 0) {
|
if (cone <= 0) {
|
||||||
|
|
|
@ -39,8 +39,6 @@ namespace Gfx {
|
||||||
|
|
||||||
class OpenGLDriver;
|
class OpenGLDriver;
|
||||||
|
|
||||||
#include "common/pack-start.h"
|
|
||||||
|
|
||||||
struct _ActorVertex {
|
struct _ActorVertex {
|
||||||
float pos1x;
|
float pos1x;
|
||||||
float pos1y;
|
float pos1y;
|
||||||
|
@ -68,11 +66,9 @@ struct _ActorVertex {
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
float b;
|
float b;
|
||||||
} PACKED_STRUCT;
|
};
|
||||||
typedef _ActorVertex ActorVertex;
|
typedef _ActorVertex ActorVertex;
|
||||||
|
|
||||||
#include "common/pack-end.h"
|
|
||||||
|
|
||||||
class OpenGLActorRenderer : public VisualActor {
|
class OpenGLActorRenderer : public VisualActor {
|
||||||
public:
|
public:
|
||||||
OpenGLActorRenderer(OpenGLDriver *gfx);
|
OpenGLActorRenderer(OpenGLDriver *gfx);
|
||||||
|
|
|
@ -86,6 +86,13 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
|
||||||
const Material &material = materials[face->materialId];
|
const Material &material = materials[face->materialId];
|
||||||
Math::Vector3d color;
|
Math::Vector3d color;
|
||||||
const Gfx::Texture *tex = _texture->getTexture(material.texture);
|
const Gfx::Texture *tex = _texture->getTexture(material.texture);
|
||||||
|
if (tex) {
|
||||||
|
tex->bind();
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
} else {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
auto vertexIndices = _faceEBO[face];
|
auto vertexIndices = _faceEBO[face];
|
||||||
auto numVertexIndices = (face)->vertexIndices.size();
|
auto numVertexIndices = (face)->vertexIndices.size();
|
||||||
if (!_gfx->computeLightsEnabled()) {
|
if (!_gfx->computeLightsEnabled()) {
|
||||||
|
@ -98,7 +105,6 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
|
||||||
uint32 index = vertexIndices[i];
|
uint32 index = vertexIndices[i];
|
||||||
auto vertex = _faceVBO[index];
|
auto vertex = _faceVBO[index];
|
||||||
if (tex) {
|
if (tex) {
|
||||||
tex->bind();
|
|
||||||
if (_gfx->computeLightsEnabled())
|
if (_gfx->computeLightsEnabled())
|
||||||
color = Math::Vector3d(1.0f, 1.0f, 1.0f);
|
color = Math::Vector3d(1.0f, 1.0f, 1.0f);
|
||||||
else
|
else
|
||||||
|
@ -111,7 +117,6 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
|
||||||
vertex.texT = 1.0f - vertex.stexT;
|
vertex.texT = 1.0f - vertex.stexT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
if (_gfx->computeLightsEnabled())
|
if (_gfx->computeLightsEnabled())
|
||||||
color = Math::Vector3d(material.r, material.g, material.b);
|
color = Math::Vector3d(material.r, material.g, material.b);
|
||||||
else
|
else
|
||||||
|
|
|
@ -40,8 +40,6 @@ namespace Gfx {
|
||||||
|
|
||||||
class Driver;
|
class Driver;
|
||||||
|
|
||||||
#include "common/pack-start.h"
|
|
||||||
|
|
||||||
struct _PropVertex {
|
struct _PropVertex {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
@ -56,11 +54,9 @@ struct _PropVertex {
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
float b;
|
float b;
|
||||||
} PACKED_STRUCT;
|
};
|
||||||
typedef _PropVertex PropVertex;
|
typedef _PropVertex PropVertex;
|
||||||
|
|
||||||
#include "common/pack-end.h"
|
|
||||||
|
|
||||||
class OpenGLPropRenderer : public VisualProp {
|
class OpenGLPropRenderer : public VisualProp {
|
||||||
public:
|
public:
|
||||||
explicit OpenGLPropRenderer(OpenGLDriver *gfx);
|
explicit OpenGLPropRenderer(OpenGLDriver *gfx);
|
||||||
|
|
|
@ -118,9 +118,9 @@ void OpenGLSActorRenderer::render(const Math::Vector3d &position, float directio
|
||||||
|
|
||||||
_shader->unbind();
|
_shader->unbind();
|
||||||
|
|
||||||
if (_castsShadow
|
if (_castsShadow &&
|
||||||
&& StarkScene->shouldRenderShadows()
|
StarkScene->shouldRenderShadows() &&
|
||||||
&& StarkSettings->getBoolSetting(Settings::kShadow)) {
|
StarkSettings->getBoolSetting(Settings::kShadow)) {
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
|
||||||
|
@ -307,8 +307,8 @@ void OpenGLSActorRenderer::setLightArrayUniform(const LightEntryArray &lights) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights,
|
void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot) {
|
Math::Matrix3 worldToModelRot) {
|
||||||
Math::Vector3d sumDirection;
|
Math::Vector3d sumDirection;
|
||||||
bool hasLight = false;
|
bool hasLight = false;
|
||||||
|
|
||||||
|
@ -363,8 +363,8 @@ void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights,
|
||||||
_shadowShader->setUniform("lightDirection", sumDirection);
|
_shadowShader->setUniform("lightDirection", sumDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLSActorRenderer::getPointLightContribution(LightEntry *light,
|
bool OpenGLSActorRenderer::getPointLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Vector3d &direction, float weight) {
|
Math::Vector3d &direction, float weight) {
|
||||||
float distance = light->position.getDistanceTo(actorPosition);
|
float distance = light->position.getDistanceTo(actorPosition);
|
||||||
|
|
||||||
if (distance > light->falloffFar) {
|
if (distance > light->falloffFar) {
|
||||||
|
@ -409,14 +409,14 @@ bool OpenGLSActorRenderer::getDirectionalLightContribution(LightEntry *light, Ma
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLSActorRenderer::getSpotLightContribution(LightEntry *light,
|
bool OpenGLSActorRenderer::getSpotLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
|
||||||
const Math::Vector3d &actorPosition, Math::Vector3d &direction) {
|
Math::Vector3d &direction) {
|
||||||
Math::Vector3d lightToActor = actorPosition - light->position;
|
Math::Vector3d lightToActor = actorPosition - light->position;
|
||||||
lightToActor.normalize();
|
lightToActor.normalize();
|
||||||
|
|
||||||
float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
|
float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
|
||||||
float cone = (cosAngle - light->innerConeAngle.getCosine()) /
|
float cone = (cosAngle - light->innerConeAngle.getCosine()) /
|
||||||
MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
|
MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
|
||||||
cone = CLIP(cone, 0.0f, 1.0f);
|
cone = CLIP(cone, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (cone <= 0) {
|
if (cone <= 0) {
|
||||||
|
|
|
@ -36,16 +36,12 @@ namespace Gfx {
|
||||||
class OpenGLDriver;
|
class OpenGLDriver;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
#include "common/pack-start.h"
|
|
||||||
|
|
||||||
struct _SurfaceVertex {
|
struct _SurfaceVertex {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
} PACKED_STRUCT;
|
};
|
||||||
typedef _SurfaceVertex SurfaceVertex;
|
typedef _SurfaceVertex SurfaceVertex;
|
||||||
|
|
||||||
#include "common/pack-end.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An programmable pipeline OpenGL surface renderer
|
* An programmable pipeline OpenGL surface renderer
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue