Skip to content

Commit

Permalink
[#17] : Fixed OpenGL issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jul 26, 2020
1 parent 667c060 commit e3fdf73
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions engines/basic/include/render_skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace dbasic {
RenderSkeleton();
~RenderSkeleton();

RenderNode *GetRoot();
RenderNode *NewNode();
RenderNode *GetNode(int index);
RenderNode *GetNode(const char *nodeName);
Expand Down
8 changes: 5 additions & 3 deletions engines/basic/src/render_skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dbasic::RenderSkeleton::~RenderSkeleton() {
/* void */
}

dbasic::RenderNode *dbasic::RenderSkeleton::GetRoot() {
return GetNode(0);
}

dbasic::RenderNode *dbasic::RenderSkeleton::NewNode() {
RenderNode *newNode = m_renderNodes.NewGeneric<RenderNode, 16>();
newNode->SetSkeleton(this);
Expand Down Expand Up @@ -79,9 +83,7 @@ void dbasic::RenderSkeleton::UpdateAnimation(float dt) {
TransformTarget *rotTarget = node->GetRotationTarget();

if (locTarget->IsAnimated()) {
ysVector movement = node->Transform.LocalToParentDirection(locTarget->GetLocationResult());
ysVector movementParentSpace = movement;

ysVector movementParentSpace = locTarget->GetLocationResult();
node->Transform.SetPosition(ysMath::Add(node->GetRestLocation(), movementParentSpace));
}

Expand Down
1 change: 1 addition & 0 deletions include/yds_opengl_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ysOpenGLDevice : public ysDevice {
virtual ysError ResizeRenderTarget(ysRenderTarget *target, int width, int height);
virtual ysError DestroyRenderTarget(ysRenderTarget *&target);
virtual ysError SetRenderTarget(ysRenderTarget *target);
virtual ysError SetDepthTestEnabled(ysRenderTarget *target, bool enable);

virtual ysError ClearBuffers(const float *clearColor);
virtual ysError Present();
Expand Down
9 changes: 2 additions & 7 deletions include/yds_opengl_render_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

#include "yds_render_target.h"

class ysOpenGLRenderTarget : public ysRenderTarget
{

class ysOpenGLRenderTarget : public ysRenderTarget {
friend class ysOpenGLDevice;

public:

ysOpenGLRenderTarget();
virtual ~ysOpenGLRenderTarget();

Expand All @@ -18,11 +15,9 @@ class ysOpenGLRenderTarget : public ysRenderTarget
unsigned int GetDepthBuffer() const { return m_depthBufferHandle; }

protected:

unsigned int m_framebufferHandle;
unsigned int m_depthBufferHandle;
unsigned int m_textureHandle;

};

#endif
#endif /* YDS_OPENGL_RENDER_TARGET_H */
1 change: 1 addition & 0 deletions include/yds_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ysTransform {
ysVector ParentToLocalDirection(const ysVector &p);
ysVector ParentToWorldDirection(const ysVector &p);

ysQuaternion WorldToLocalOrientation(const ysQuaternion &q);
ysQuaternion WorldToParentOrientation(const ysQuaternion &q);

ysQuaternion GetLocalOrientation() const;
Expand Down
2 changes: 1 addition & 1 deletion src/yds_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ysQuaternion ysMath::LoadQuaternion(float angle, const ysVector &axis) {
ysVector newAxis = _mm_shuffle_ps(axis, axis, _MM_SHUFFLE(2, 1, 0, 3));
newAxis = _mm_and_ps(newAxis, ysMath::Constants::MaskOffX);
newAxis = _mm_mul_ps(newAxis, ysMath::LoadScalar(sinAngle));
newAxis = _mm_or_ps(newAxis, ysMath::LoadVector(cosAngle));
newAxis = _mm_add_ps(newAxis, ysMath::LoadVector(cosAngle));

newAxis = ysMath::Normalize(newAxis);

Expand Down
15 changes: 14 additions & 1 deletion src/yds_opengl_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ ysError ysOpenGLDevice::SetRenderTarget(ysRenderTarget *target) {
m_realContext->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, realTarget->GetFramebuffer());
}

if (target->HasDepthBuffer()) glEnable(GL_DEPTH_TEST);
if (target->HasDepthBuffer() && target->IsDepthTestEnabled()) glEnable(GL_DEPTH_TEST);
else glDisable(GL_DEPTH_TEST);

int refw, refh;
Expand All @@ -288,6 +288,19 @@ ysError ysOpenGLDevice::SetRenderTarget(ysRenderTarget *target) {
return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}

ysError ysOpenGLDevice::SetDepthTestEnabled(ysRenderTarget *target, bool enable) {
YDS_ERROR_DECLARE("SetDepthTestEnabled");

bool previousState = target->IsDepthTestEnabled();
YDS_NESTED_ERROR_CALL(ysDevice::SetDepthTestEnabled(target, enable));

if (target == GetActiveRenderTarget() && previousState != enable) {
SetRenderTarget(target);
}

return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}

ysError ysOpenGLDevice::DestroyRenderTarget(ysRenderTarget *&target) {
YDS_ERROR_DECLARE("DestroyRenderTarget");

Expand Down
5 changes: 5 additions & 0 deletions src/yds_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ ysVector ysTransform::ParentToWorldDirection(const ysVector &p) {
else return m_parent->LocalToWorldDirection(p);
}

ysQuaternion ysTransform::WorldToLocalOrientation(const ysQuaternion &q) {
return ysMath::QuatMultiply(
ysMath::QuatInvert(ysMath::Normalize(GetWorldOrientation())), q);
}

ysQuaternion ysTransform::WorldToParentOrientation(const ysQuaternion &q) {
if (m_parent == nullptr) return q;
else return ysMath::QuatMultiply(
Expand Down

0 comments on commit e3fdf73

Please sign in to comment.