Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 Apr 2012
Offline Last Active Nov 24 2013 01:19 PM

Posts I've Made

In Topic: Diffuse Lighting, GLSL.

29 October 2013 - 10:20 AM

I solved it, it's kinda embarassing. I had the offset wrong in my interleaved vbo. It gathered the wrong normals and that messed it up.

In Topic: XMVECTOR and XMMATRIX in header?

05 September 2013 - 04:22 PM

Hey, I think the fastest way to tell if your problem is alignment related is to build your project with the Debug configuration instead of Release, since I believe visual studio defaults the Debug configuration to disable SSE intrinsics.


Assuming that is the problem, and you don't get the access violation in Debug configuration,  it probably is a memory alignment issue.  That's because XMMATRIX and XMVECTOR use (i think) __m128 SSE intrinsic types for storage, and those need to have a 16 byte memory alignment.  More info here:  http://msdn.microsoft.com/en-us/library/ee418725.aspx


There are a few ways to work around that issue.  The easiest is to just build for an x64 target platform, since all allocations are 16 byte aligned for x64 processes (instead of 8 byte aligned for x86).  


The next simplest is probably to store your XMMATRIX as a XMFLOAT4X4 type instead (and XMVECTOR as XMFloat4), then use XMLoadxxx and XMStorexxx functions with temporary local XMVECTOR/XMMATRIX variables, to feed them into functions like XMVectorSet that expect 16 byte aligned arguments.   More info here:  http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.loading.xmloadfloat4.aspx


Finally you can attempt to align the containing class/struct that the XMMATRIX/XMVECTOR is a member of.  You essentially declare the class/struct in your header with __declspec(align(16)), and then make sure you declare the member variables with the XMVECTOR/XMMATRIX types first, to ensure the alignment.  For example:

__declspec(align(16)) class CMyClass
      bool SomeFunc();
      void SomeOtherFunc();
      XMMATRIX m_world;
      XMVECTOR m_camPosition;
      int m_someOtherMember;
      bool m_yetAnotherMember;

That should align the entire class/struct to 16 byte boundaries, and since the aligned XM types are declared first they begin at the requested alignment for the class/struct.  I think that can get a bit messy (with virtual functions and inheritance possibly altering the data structure within a class), perhaps someone more experienced could provide better information on that.  Personally I use SSE intrinsic DirectXMath types directly, and only compile for x64 target.

This helped me alot! I bet there is a more correct way, or even more efficient. But I simpy solved it with #define _XM_NO_INNTRINSICS_

Seemed to be alot easier for me, anything that would make this way of doing things more complicated or even wrong? Seemed to have solved my problem for now though.

In Topic: OpenGL Camera Up Problem.

16 April 2013 - 11:39 AM

I'll use  this as a bump post and hope that somebody answers me again. My problem didn't get solved.. I posted my earlier post to fast. My problem still exists unfortunately..


Here is my Camera class.

http://pastebin.com/UmRvTrQN (NOTE: This is modified to be moving "correct", pressing D makes me go right and pressing A goes left etc. Though it shouldn't.. really..?)


Hope somebody can solve this for me.. Feels like I've tried everything. Ofcourse I could just move the camera in the opposite direction that it's supposed to be moved. But I want it to be correct.

In Topic: OpenGL Camera Up Problem.

14 April 2013 - 04:50 AM

Well, stupid me. I had just set the View Matrix to Identity and thought that'd take care of it. Obviously that was not correct, I used this to setup a View Matrix and now it works like a charm!



In Topic: What objects do I use matrices for?

10 November 2012 - 03:41 PM

The three transforms: ....

Wow, yet again. That is extremely helpful! I can't believe the help im getting out of this forum, greatly appreciated. Thanks again! Posted Image