6 #define __func__ __FUNCTION__ 10 #define M_PI 3.1415926f 17 #define static_inline static 19 #define static_inline static inline 24 #if defined(_MSC_VER) && (_MSC_VER < 1900) 25 #define snprintf c99_snprintf 27 static_inline int c99_vsnprintf(
char* str,
size_t size,
const char* format, va_list ap)
32 count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
34 count = _vscprintf(format, ap);
39 static_inline int c99_snprintf(
char* str,
size_t size,
const char* format, ...)
45 count = c99_vsnprintf(str, size, format, ap);
55 #define INDEX(row,col) ((col)*4 + (row)) 60 return sqrtf(vec3[0] * vec3[0] + vec3[1] * vec3[1] + vec3[2] * vec3[2]);
73 return A[0] * B[0] + A[1] * B[1] + A[2] * B[2];
78 result[0] = A[1] * B[2] - A[2] * B[1];
79 result[1] = A[2] * B[0] - A[0] * B[2];
80 result[2] = A[0] * B[1] - A[1] * B[0];
92 float x = matrix_4x4[
INDEX(0, 0)] * vec3[0] + matrix_4x4[
INDEX(0, 1)] * vec3[1] + matrix_4x4[
INDEX(0, 2)] * vec3[2] + matrix_4x4[
INDEX(0, 3)];
93 float y = matrix_4x4[
INDEX(1, 0)] * vec3[0] + matrix_4x4[
INDEX(1, 1)] * vec3[1] + matrix_4x4[
INDEX(1, 2)] * vec3[2] + matrix_4x4[
INDEX(1, 3)];
94 float z = matrix_4x4[
INDEX(2, 0)] * vec3[0] + matrix_4x4[
INDEX(2, 1)] * vec3[1] + matrix_4x4[
INDEX(2, 2)] * vec3[2] + matrix_4x4[
INDEX(2, 3)];
95 float w = matrix_4x4[
INDEX(3, 0)] * vec3[0] + matrix_4x4[
INDEX(3, 1)] * vec3[1] + matrix_4x4[
INDEX(3, 2)] * vec3[2] + matrix_4x4[
INDEX(3, 3)];
104 #define FILL_MATRIX_4x4(A, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \ 124 memcpy(result, A, 16*
sizeof(
float));
129 memset(result, 0, 16*
sizeof(
float));
130 result[0] = result[5] = result[10] = result[15] = 1;
134 void GPU_MatrixOrtho(
float* result,
float left,
float right,
float bottom,
float top,
float near,
float far)
143 2/(right - left), 0, 0, -(right + left)/(right - left),
144 0, 2/(top - bottom), 0, -(top + bottom)/(top - bottom),
145 0, 0, -2/(far - near), -(far + near)/(far - near),
151 2 / (right - left), 0, 0, 0,
152 0, 2 / (top - bottom), 0, 0,
153 0, 0, -2 / (far - near), 0,
154 -(right + left) / (right - left), -(top + bottom) / (top - bottom), -(far + near) / (far - near), 1
163 void GPU_MatrixFrustum(
float* result,
float left,
float right,
float bottom,
float top,
float near,
float far)
171 2 * near / (right - left), 0, 0, 0,
172 0, 2 * near / (top - bottom), 0, 0,
173 (right + left) / (right - left), (top + bottom) / (top - bottom), -(far + near) / (far - near), -1,
174 0, 0, -(2 * far * near) / (far - near), 0
189 fH = tanf(fovy / 360 *
M_PI) * zNear;
194 void GPU_MatrixLookAt(
float* matrix,
float eye_x,
float eye_y,
float eye_z,
float target_x,
float target_y,
float target_z,
float up_x,
float up_y,
float up_z)
196 float forward[3] = {target_x - eye_x, target_y - eye_y, target_z - eye_z};
197 float up[3] = {up_x, up_y, up_z};
221 view[2] = -forward[0];
222 view[6] = -forward[1];
223 view[10] = -forward[2];
226 view[3] = view[7] = view[11] = 0.0f;
281 float p, radians, c, s, c_, zc_, yc_, xzc_, xyc_, yzc_, xs, ys, zs;
286 p = 1/sqrtf(x*x + y*y + z*z);
287 x *= p; y *= p; z *= p;
288 radians = degrees * (
M_PI/180);
305 x*x*c_ + c, xyc_ - zs, xzc_ + ys, 0,
306 xyc_ + zs, y*yc_ + c, yzc_ - xs, 0,
307 xzc_ - ys, yzc_ + xs, z*zc_ + c, 0,
313 x*x*c_ + c, xyc_ + zs, xzc_ - ys, 0,
314 xyc_ - zs, y*yc_ + c, yzc_ + xs, 0,
315 xzc_ + ys, yzc_ - xs, z*zc_ + c, 0,
327 float (*matR)[4] = (float(*)[4])result;
328 float (*matA)[4] = (float(*)[4])A;
329 float (*matB)[4] = (float(*)[4])B;
330 matR[0][0] = matB[0][0] * matA[0][0] + matB[0][1] * matA[1][0] + matB[0][2] * matA[2][0] + matB[0][3] * matA[3][0];
331 matR[0][1] = matB[0][0] * matA[0][1] + matB[0][1] * matA[1][1] + matB[0][2] * matA[2][1] + matB[0][3] * matA[3][1];
332 matR[0][2] = matB[0][0] * matA[0][2] + matB[0][1] * matA[1][2] + matB[0][2] * matA[2][2] + matB[0][3] * matA[3][2];
333 matR[0][3] = matB[0][0] * matA[0][3] + matB[0][1] * matA[1][3] + matB[0][2] * matA[2][3] + matB[0][3] * matA[3][3];
334 matR[1][0] = matB[1][0] * matA[0][0] + matB[1][1] * matA[1][0] + matB[1][2] * matA[2][0] + matB[1][3] * matA[3][0];
335 matR[1][1] = matB[1][0] * matA[0][1] + matB[1][1] * matA[1][1] + matB[1][2] * matA[2][1] + matB[1][3] * matA[3][1];
336 matR[1][2] = matB[1][0] * matA[0][2] + matB[1][1] * matA[1][2] + matB[1][2] * matA[2][2] + matB[1][3] * matA[3][2];
337 matR[1][3] = matB[1][0] * matA[0][3] + matB[1][1] * matA[1][3] + matB[1][2] * matA[2][3] + matB[1][3] * matA[3][3];
338 matR[2][0] = matB[2][0] * matA[0][0] + matB[2][1] * matA[1][0] + matB[2][2] * matA[2][0] + matB[2][3] * matA[3][0];
339 matR[2][1] = matB[2][0] * matA[0][1] + matB[2][1] * matA[1][1] + matB[2][2] * matA[2][1] + matB[2][3] * matA[3][1];
340 matR[2][2] = matB[2][0] * matA[0][2] + matB[2][1] * matA[1][2] + matB[2][2] * matA[2][2] + matB[2][3] * matA[3][2];
341 matR[2][3] = matB[2][0] * matA[0][3] + matB[2][1] * matA[1][3] + matB[2][2] * matA[2][3] + matB[2][3] * matA[3][3];
342 matR[3][0] = matB[3][0] * matA[0][0] + matB[3][1] * matA[1][0] + matB[3][2] * matA[2][0] + matB[3][3] * matA[3][0];
343 matR[3][1] = matB[3][0] * matA[0][1] + matB[3][1] * matA[1][1] + matB[3][2] * matA[2][1] + matB[3][3] * matA[3][1];
344 matR[3][2] = matB[3][0] * matA[0][2] + matB[3][1] * matA[1][2] + matB[3][2] * matA[2][2] + matB[3][3] * matA[3][2];
345 matR[3][3] = matB[3][0] * matA[0][3] + matB[3][1] * matA[1][3] + matB[3][2] * matA[2][3] + matB[3][3] * matA[3][3];
362 static char buffer[512];
363 static char buffer2[512];
364 static char flip = 0;
366 char* b = (flip? buffer : buffer2);
369 snprintf(b, 512,
"%.1f %.1f %.1f %.1f\n" 370 "%.1f %.1f %.1f %.1f\n" 371 "%.1f %.1f %.1f %.1f\n" 372 "%.1f %.1f %.1f %.1f",
373 A[0], A[1], A[2], A[3],
374 A[4], A[5], A[6], A[7],
375 A[8], A[9], A[10], A[11],
376 A[12], A[13], A[14], A[15]);
383 if(target == NULL || target->
context == NULL)
394 if(target == NULL || target->
context == NULL)
407 if(target == NULL || target->
context == NULL)
420 if(target == NULL || target->
context == NULL)
437 if(target == NULL || target->
context == NULL)
455 if(target == NULL || target->
context == NULL)
478 void GPU_Ortho(
float left,
float right,
float bottom,
float top,
float near,
float far)
484 void GPU_Frustum(
float left,
float right,
float bottom,
float top,
float near,
float far)
void GPU_Translate(float x, float y, float z)
#define GPU_MATRIX_STACK_MAX
void GPU_Multiply4x4(float *result, float *A, float *B)
float matrix[GPU_MATRIX_STACK_MAX][16]
void GPU_Frustum(float left, float right, float bottom, float top, float near, float far)
DECLSPEC void SDLCALL GPU_FlushBlitBuffer(void)
void GPU_MatrixPerspective(float *result, float fovy, float aspect, float zNear, float zFar)
float * GPU_GetProjection(void)
void GPU_VectorCopy(float *result, float *A)
void GPU_VectorNormalize(float *vec3)
GPU_MatrixStack modelview_matrix
void GPU_MatrixOrtho(float *result, float left, float right, float bottom, float top, float near, float far)
DECLSPEC GPU_Target *SDLCALL GPU_GetContextTarget(void)
const char * GPU_GetMatrixString(float *A)
void GPU_MatrixTranslate(float *result, float x, float y, float z)
float * GPU_GetCurrentMatrix(void)
void GPU_Ortho(float left, float right, float bottom, float top, float near, float far)
void GPU_MatrixScale(float *result, float sx, float sy, float sz)
void GPU_PushMatrix(void)
void GPU_VectorCross(float *result, float *A, float *B)
void GPU_MatrixMode(int matrix_mode)
GPU_MatrixStack projection_matrix
void GPU_MatrixCopy(float *result, const float *A)
void GPU_GetModelViewProjection(float *result)
float GPU_VectorDot(float *A, float *B)
void GPU_VectorApplyMatrix(float *vec3, float *matrix_4x4)
void GPU_LoadIdentity(void)
void GPU_MatrixIdentity(float *result)
void GPU_Scale(float sx, float sy, float sz)
float * GPU_GetModelView(void)
float GPU_VectorLength(float *vec3)
void GPU_MatrixFrustum(float *result, float left, float right, float bottom, float top, float near, float far)
void GPU_MultiplyAndAssign(float *result, float *B)
DECLSPEC void SDLCALL GPU_PushErrorCode(const char *function, GPU_ErrorEnum error, const char *details,...)
void GPU_MultMatrix(float *A)
#define FILL_MATRIX_4x4(A, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
void GPU_Rotate(float degrees, float x, float y, float z)
void GPU_MatrixRotate(float *result, float degrees, float x, float y, float z)
void GPU_MatrixLookAt(float *matrix, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z)