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