Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbid committed Nov 15, 2022
1 parent 3629130 commit e817d6d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
5 changes: 5 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ clang main.c glad_gl.c -Ofast -lglfw -lm -o cubes2
i686-w64-mingw32-gcc main.c glad_gl.c -Ofast -Llib -lglfw3dll -lm -o cubes2.exe
upx cubes2
upx cubes2.exe

clang main_fullbright.c glad_gl.c -Ofast -lglfw -lm -o cubes2_fullbright
i686-w64-mingw32-gcc main_fullbright.c glad_gl.c -Ofast -Llib -lglfw3dll -lm -o cubes2_fullbright.exe
upx cubes2_fullbright
upx cubes2_fullbright.exe
39 changes: 19 additions & 20 deletions esAux2.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ void shadePhong3(GLint* position, GLint* projection, GLint* modelview, GLint* no

GLuint esRand(const GLuint min, const GLuint max)
{
static GLfloat rndmax = 1.f/(GLfloat)RAND_MAX;
return (((GLfloat)rand()) * rndmax) * (max-min) + min;
return (rand()%(max+1-min))+min;
}

GLfloat esRandFloat(const GLfloat min, const GLfloat max)
{
static GLfloat rndmax = 1.f/(GLfloat)RAND_MAX;
return ( (((GLfloat)rand()) * rndmax) * (max-min) ) + min;
static GLfloat rrndmax = 1.f/(GLfloat)RAND_MAX;
return ( (((GLfloat)rand()) * rrndmax) * (max-min) ) + min;
}

void esBind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage)
Expand Down Expand Up @@ -352,13 +351,13 @@ const GLchar* v2 =
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;"
"vertPos = vec3(vertPos4) / vertPos4.w;"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vec3(vertPos4) / vertPos4.w;\n"
"vertCol = color;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"normalInterp = vec3(normalmat * vec4(position.xyz, 0.0));"
"gl_Position = projection * modelview * position;"
"normalInterp = vec3(normalmat * vec4(position.xyz, 0.0));\n"
"gl_Position = projection * modelview * position;\n"
"}\n";

const GLchar* v21 =
Expand All @@ -378,13 +377,13 @@ const GLchar* v21 =
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;"
"vertPos = vec3(vertPos4) / vertPos4.w;"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vec3(vertPos4) / vertPos4.w;\n"
"vertCol = color;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"normalInterp = vec3(normalmat * vec4(normal.xyz, 0.0));"
"gl_Position = projection * modelview * position;"
"normalInterp = vec3(normalmat * vec4(normal.xyz, 0.0));\n"
"gl_Position = projection * modelview * position;\n"
"}\n";

const GLchar* v22 =
Expand All @@ -403,13 +402,13 @@ const GLchar* v22 =
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;"
"vertPos = vec3(vertPos4) / vertPos4.w;"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vec3(vertPos4) / vertPos4.w;\n"
"vertCol = color;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"normalInterp = vec3(normalmat * vec4(position.xyz, 0.0));"
"gl_Position = projection * modelview * position;"
"normalInterp = vec3(normalmat * vec4(position.xyz, 0.0));\n"
"gl_Position = projection * modelview * position;\n"
"}\n";

const GLchar* v23 =
Expand All @@ -429,13 +428,13 @@ const GLchar* v23 =
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;"
"vertPos = vec3(vertPos4) / vertPos4.w;"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vec3(vertPos4) / vertPos4.w;\n"
"vertCol = color;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"normalInterp = vec3(normalmat * vec4(normal.xyz, 0.0));"
"gl_Position = projection * modelview * position;"
"normalInterp = vec3(normalmat * vec4(normal.xyz, 0.0));\n"
"gl_Position = projection * modelview * position;\n"
"}\n";

const GLchar* f2 =
Expand Down
32 changes: 20 additions & 12 deletions mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ typedef struct
} mat;

void mIdent(mat *m);
void mCopy(mat* r, const mat* v);
void mMul(mat *r, const mat *a, const mat *b);
void mMulP(vec *r, const mat *a, const float x, const float y, const float z);
void mMulV(vec *r, const mat *a, const vec v);
void mCopy(mat *restrict r, const mat *restrict v);
void mMul(mat *restrict r, const mat *restrict a, const mat *restrict b);
void mMulP(vec *restrict r, const mat *restrict a, const float x, const float y, const float z);
void mMulV(vec *restrict r, const mat *restrict a, const vec v);
void mScale(mat *r, const float x, const float y, const float z);
void mTranslate(mat *r, const float x, const float y, const float z);
void mRotate(mat *r, const float radians, float x, float y, float z);
Expand All @@ -32,13 +32,14 @@ void mFrustum(mat *r, const float left, const float right, const float bottom, c
void mPerspective(mat *r, const float fovy, const float aspect, const float nearZ, const float farZ);
void mOrtho(mat *r, const float left, const float right, const float bottom, const float top, const float nearZ, const float farZ);
void mLookAt(mat *r, const vec origin, const vec unit_dir);
void mInvert(float *dst, const float *mat);
void mTranspose(mat *r, const mat* m);
void mInvert(float *restrict dst, const float *restrict mat);
void mTranspose(mat *restrict r, const mat *restrict m);
void mSetViewDir(mat *r, const vec dir_norm, const vec up_norm);
void mGetViewDir(vec *r, const mat matrix); // returns normal/unit vector
void mGetDirX(vec *r, const mat matrix);
void mGetDirY(vec *r, const mat matrix);
void mGetDirZ(vec *r, const mat matrix);
void mGetPos(vec *r, const mat matrix);

//

Expand All @@ -51,12 +52,12 @@ void mIdent(mat *m)
m->m[3][3] = 1.0f;
}

void mCopy(mat* r, const mat* v)
void mCopy(mat *restrict r, const mat *restrict v)
{
memcpy(r, v, sizeof(mat));
}

void mMul(mat *r, const mat *a, const mat *b)
void mMul(mat *restrict r, const mat *restrict a, const mat *restrict b)
{
mat tmp;
for(int i = 0; i < 4; i++)
Expand Down Expand Up @@ -84,7 +85,7 @@ void mMul(mat *r, const mat *a, const mat *b)
memcpy(r, &tmp, sizeof(mat));
}

void mMulP(vec *r, const mat *a, const float x, const float y, const float z)
void mMulP(vec *restrict r, const mat *restrict a, const float x, const float y, const float z)
{
r->x = (a->m[0][0] * x) +
(a->m[0][1] * x) +
Expand All @@ -102,7 +103,7 @@ void mMulP(vec *r, const mat *a, const float x, const float y, const float z)
(a->m[2][3] * z) ;
}

void mMulV(vec *r, const mat *a, const vec v)
void mMulV(vec *restrict r, const mat *restrict a, const vec v)
{
r->x = (a->m[0][0] * v.x) +
(a->m[0][1] * v.x) +
Expand Down Expand Up @@ -327,7 +328,7 @@ void mLookAt(mat *r, const vec origin, const vec unit_dir)
r->m[3][2] = origin.z;
}

void mInvert(float *dst, const float *mat)
void mInvert(float *restrict dst, const float *restrict mat)
{
// original source: ftp:https://download.intel.com/design/PentiumIII/sml/24504301.pdf
// mirrored: https://github.com/esAux/esAux-Menger/raw/main/SIMD%20Matrix%20Inverse.pdf
Expand Down Expand Up @@ -418,7 +419,7 @@ void mInvert(float *dst, const float *mat)
for(int j = 0; j < 16; j++){dst[j] *= det;}
}

void mTranspose(mat *r, const mat* m)
void mTranspose(mat *r, const mat *restrict m)
{
r->m[1][0] = m->m[0][1];
r->m[2][0] = m->m[0][2];
Expand Down Expand Up @@ -490,4 +491,11 @@ void mGetDirZ(vec *r, const mat matrix)
r->z = matrix.m[2][2];
}

void mGetPos(vec *r, const mat matrix)
{
r->x = matrix.m[3][0];
r->y = matrix.m[3][1];
r->z = matrix.m[3][2];
}

#endif
9 changes: 5 additions & 4 deletions vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ typedef struct{

static inline float rsqrtss(float f);
static inline float sqrtps(float f);
float randf(); // uniform
float randfn(); // box-muller normal
float randf(); // uniform [0 to 1]
float randfc(); // uniform [-1 to 1]
float randfn(); // box-muller normal [bi-directional]
int vec_ftoi(float f); // float to integer quantise

// normalising the result is optional / at the callers responsibility
Expand Down Expand Up @@ -146,7 +147,7 @@ float randf()
mm0 = _mm_add_pi32(mm0, mm1);
srandfq = _m_to_int64(mm0);
_m_empty();
return fabsf(srandfq) * INV_FLOAT_MAX;
return fabsf((float)srandfq) * INV_FLOAT_MAX;
}

float randfc()
Expand All @@ -156,7 +157,7 @@ float randfc()
mm0 = _mm_add_pi32(mm0, mm1);
srandfq = _m_to_int64(mm0);
_m_empty();
return srandfq * INV_FLOAT_MAX;
return ((float)srandfq) * INV_FLOAT_MAX;
}

#endif
Expand Down

0 comments on commit e817d6d

Please sign in to comment.