-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.c
More file actions
116 lines (92 loc) · 2.77 KB
/
buffer.c
File metadata and controls
116 lines (92 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "buffer.h"
void put_line(Vec p1, Vec p2, Shader shader) {
switch (GetEngineMode()) {
case AVX256 : { _256_put_line(p1, p2, shader); break; }
case AVX512 : { _512_put_line(p1, p2, shader); break; }
}
}
static BUFCLEAR CLEARMODE = NTH_AVX;
void ClearBuffers() {
switch (GetEngineMode()) {
case AVX256 : {
switch (GetBufClearMode()) {
case ALIGNED_AVX : { _256_clear_bufs(); break; }
case DUAL_ALIGNED_AVX : { _256_clear_bufs_dual(); break; }
case NTH_AVX : { _256_clear_bufs_nth(); break; }
case DUAL_NTH_AVX : {_256_clear_bufs_nthd(); break; }
}
break;
}
case AVX512 : {
switch (GetBufClearMode()) {
case ALIGNED_AVX : { _512_clear_bufs(); break; }
case DUAL_ALIGNED_AVX : { _512_clear_bufs_dual(); break; }
case NTH_AVX : { _512_clear_bufs_nth(); break; }
case DUAL_NTH_AVX : { _512_clear_bufs_nthd(); break; }
}
break;
}
}
}
void MakeBuffers() {
PIXELS = (GetScaledWidth() + 1) * GetScaledHeight();
BUFSIZE = PIXELS * 4;
FreeBuffers();
ZBUFFER = (FLOAT*) _aligned_malloc(BUFSIZE, 64);
CBUFFER = (UINT*) _aligned_malloc(BUFSIZE, 64);
}
void FreeBuffers() {
if (ZBUFFER != NULL) {
_aligned_free(ZBUFFER);
_aligned_free(CBUFFER);
}
}
BUFCLEAR GetBufClearMode() {
return CLEARMODE;
}
void SetBufClearMode(BUFCLEAR mode) {
CLEARMODE = mode;
ResetFrameTimes();
}
COLORREF GetEngineBG() {
return ENGINE_BG;
}
void SetEngineBG(COLORREF col) {
ENGINE_BG = col;
}
static BITMAPINFO BMI;
BITMAPINFO* GetBMI() {
return &BMI;
}
static FLOAT RESOLUTION = 1.0f;
extern FLOAT Width, Height;
void UpdateBuffers() {
PIXELS = (GetScaledWidth() + 1) * GetScaledHeight();
BUFSIZE = PIXELS * 4;
Width = ((FLOAT) GetScaledWidth());
Height = ((FLOAT) GetScaledHeight());
ZBUFFER = (FLOAT*) _aligned_realloc(ZBUFFER, BUFSIZE, 64);
CBUFFER = (UINT*) _aligned_realloc(CBUFFER, BUFSIZE, 64);
if (BMI.bmiHeader.biSize == 0) {
BMI.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BMI.bmiHeader.biPlanes = 1;
BMI.bmiHeader.biBitCount = 32;
BMI.bmiHeader.biCompression = BI_RGB;
}
BMI.bmiHeader.biWidth = GetScaledWidth();
BMI.bmiHeader.biHeight = -((INT) GetScaledHeight());
}
FLOAT GetResolution() {
return RESOLUTION;
}
void SetResolution(FLOAT res) {
RESOLUTION = res;
UpdateBuffers();
ResetFrameTimes();
}
UINT GetScaledWidth() {
return (UINT) (GetWindowWidth() / RESOLUTION);
}
UINT GetScaledHeight() {
return (UINT) (GetWindowHeight() / RESOLUTION);
}