-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderTexture.cpp
More file actions
63 lines (43 loc) · 1.47 KB
/
RenderTexture.cpp
File metadata and controls
63 lines (43 loc) · 1.47 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
#include "RenderTexture.hpp"
extern "C" {
#include "HW05Lib.h"
}
RenderTexture::RenderTexture(unsigned short width, unsigned short height, RTFilterMode filterMode) {
this->width = width;
this->height = height;
this->filterMode = filterMode;
this->buffer = new unsigned short[width*height]();
}
RenderTexture::RenderTexture(unsigned short width, unsigned short height) : RenderTexture(width, height, RTFilterMode::Point) {
}
RenderTexture::RenderTexture(RTFilterMode filterMode) : RenderTexture(240, 160, filterMode) {
}
RenderTexture::RenderTexture() : RenderTexture(RTFilterMode::Point) {
}
unsigned short RenderTexture::getHeight() {
return this->height;
}
unsigned short RenderTexture::getWidth() {
return this->width;
}
void RenderTexture::fill(unsigned short color) {
unsigned int src = color | color << 16;
DMANow(3, &src, this->buffer, DMA_32 | DMA_SOURCE_FIXED | DMA_DESTINATION_INCREMENT | this->width * this->height / 2);
}
bool RenderTexture::writePixel(unsigned short i, unsigned short j, unsigned short color) {
if (i < width && j < height) {
buffer[i+j*width] = color;
return true;
} else {
return false;
}
}
unsigned short RenderTexture::sampleGBAColor(int i, int j) {
return buffer[i+j*width];
}
Vector3 RenderTexture::sampleVectorColor(int i, int j) {
return Vector3::fromGBAColor(buffer[i+j*width]);
}
void RenderTexture::drawFullscreenUnsafe() {
drawFullscreenImage3(buffer);
}