galdar496 / QiGameEngine

Realtime Game Engine designed with C++ and OpenGL.
http://qiengine.blogspot.com/
1 stars 0 forks source link

Get Qi running on windows #17

Closed galdar496 closed 9 years ago

galdar496 commented 9 years ago

Likely run into a couple of cross-platform issues (16-byte alignment comes to mind) but should be very straightforward. Also need to build a windows version of gtest (https://code.google.com/p/googletest/)

galdar496 commented 9 years ago

To align to 16 bytes on windows, you can use

__declspec(align(16))
msgambati commented 9 years ago

I found this. What do you think?

#if defined(_MSC_VER)
#define ALIGNED_(x) __declspec(align(x))
#else
#if defined(__GNUC__)
#define ALIGNED_(x) __attribute__ ((aligned(x)))
#endif
#endif

#define _ALIGNED_TYPE(t,x) typedef t ALIGNED_(x)

//SOME USAGE SAMPLES

ALIGNED_TYPE_(double, 16) aligned_double_t;

ALIGNED_TYPE_(struct, CACHE_LINE) tagALIGNEDSTRUCT
{
    //STRUCT MEMBERS GO HERE
}aligned_struct_t;

ALIGNED_TYPE_(union, CACHE_LINE) tagALIGNEDUNION
{
    //UNION MEMBERS GO HERE

}aligned_union_t;
galdar496 commented 9 years ago

This looks great, just pit QI_ in front of it. On Apr 4, 2015 5:27 PM, "Matthew Sgambati" notifications@github.com wrote:

I found this. What do you think?

/*

if defined(

_MSCVER) #define ALIGNED(x)

_declspec(align(x)) #else #if defined(_GNUC)

define ALIGNED_(x) attribute ((aligned(x)))

endif

endif

define _ALIGNEDTYPE(t,x) typedef t ALIGNED(x)

//SOME USAGE SAMPLES

ALIGNEDTYPE(double, 16) aligned_double_t;

ALIGNEDTYPE(struct, CACHE_LINE) tagALIGNEDSTRUCT { //STRUCT MEMBERS GO HERE }aligned_struct_t;

ALIGNEDTYPE(union, CACHE_LINE) tagALIGNEDUNION { //UNION MEMBERS GO HERE

}aligned_union_t; */

— Reply to this email directly or view it on GitHub https://github.com/galdar496/QiGameEngine/issues/17#issuecomment-89693215 .

galdar496 commented 9 years ago

I guess I would expect it to look like this (in the Defines.h file):

#if defined(QI_WINDOWS) // where we define QI_WINDOWS in the Defines.h file above this line
   #define QI_ALIGN(x) __declspec(align(x))
#else
   #define QI_ALIGN(x) __attribute__ ((aligned(x))) // works on linux and mac
#endif

// Example use
class QI_ALIGN(16) Vec4 {};

Note that I didn't test this or write it in a compiler, but that's how I think it should generally look.

galdar496 commented 9 years ago

Turns out this is unnecessary. C++11 has support for alignas() which will already be cross-platform: http://en.cppreference.com/w/cpp/language/alignas

galdar496 commented 9 years ago

d3fba63c9265d47baeb4186e4fdba53a10e3738e