Skip to content

Commit ccac3ca

Browse files
committed
generate textures by rlloadtexture
1 parent 328e4c3 commit ccac3ca

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

Source/Managers/FrameMan.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int FrameMan::CreateBackBuffers() {
142142
m_BackBuffer32 = std::unique_ptr<BITMAP, BitmapDeleter>(create_bitmap_ex(c_BPP, resX, resY));
143143
ClearBackBuffer32();
144144

145-
m_BackBuffer = std::make_unique<RenderTarget>(FloatRect(0, 0, resX, resY), FloatRect(0, 0, resX, resY));
145+
m_BackBuffer = std::make_unique<RenderTarget>(FloatRect(0, 0, resX, resY), FloatRect(0, 0, resX, resY), 8);
146146

147147
m_OverlayBitmap32 = std::unique_ptr<BITMAP, BitmapDeleter>(create_bitmap_ex(c_BPP, resX, resY));
148148
clear_to_color(m_OverlayBitmap32.get(), 0);
@@ -173,7 +173,7 @@ int FrameMan::CreateBackBuffers() {
173173
clear_to_color(m_PlayerScreen8.get(), 0);
174174
set_clip_state(m_PlayerScreen8.get(), 1);
175175

176-
m_PlayerScreen = std::make_unique<RenderTarget>(FloatRect(0, 0, resX / (m_VSplit ? 2 : 1), resY / (m_HSplit ? 2 : 1)), FloatRect(0, 0, resX / (m_VSplit ? 2 : 1), resY / (m_HSplit ? 2 : 1)), g_GLResourceMan.GetStaticTextureFromBitmap(m_PlayerScreen8.get()));
176+
m_PlayerScreen = std::make_unique<RenderTarget>(FloatRect(0, 0, resX / (m_VSplit ? 2 : 1), resY / (m_HSplit ? 2 : 1)), FloatRect(0, 0, resX / (m_VSplit ? 2 : 1), resY / (m_HSplit ? 2 : 1)), 8, g_GLResourceMan.GetStaticTextureFromBitmap(m_PlayerScreen8.get()));
177177

178178
// Update these to represent the split screens
179179
m_PlayerScreenWidth = m_PlayerScreen->GetSize().w;
@@ -269,7 +269,7 @@ void FrameMan::ResetSplitScreens(bool hSplit, bool vSplit) {
269269
clear_to_color(m_PlayerScreen8.get(), 0);
270270
set_clip_state(m_PlayerScreen8.get(), 1);
271271

272-
m_PlayerScreen = std::make_unique<RenderTarget>(FloatRect(0, 0, g_WindowMan.GetResX() / (m_VSplit ? 2 : 1), g_WindowMan.GetResY() / (m_HSplit ? 2 : 1)), FloatRect(0, 0, g_WindowMan.GetResX() / (m_VSplit ? 2 : 1), g_WindowMan.GetResY() / (m_HSplit ? 2 : 1)), g_GLResourceMan.GetStaticTextureFromBitmap(m_PlayerScreen8.get()));
272+
m_PlayerScreen = std::make_unique<RenderTarget>(FloatRect(0, 0, g_WindowMan.GetResX() / (m_VSplit ? 2 : 1), g_WindowMan.GetResY() / (m_HSplit ? 2 : 1)), FloatRect(0, 0, g_WindowMan.GetResX() / (m_VSplit ? 2 : 1), g_WindowMan.GetResY() / (m_HSplit ? 2 : 1)), 8, g_GLResourceMan.GetStaticTextureFromBitmap(m_PlayerScreen8.get()));
273273

274274
// Update these to represent the split screens
275275
m_PlayerScreenWidth = m_PlayerScreen->GetSize().w;
@@ -831,6 +831,9 @@ void FrameMan::Draw() {
831831

832832
m_PlayerScreen->Begin(true);
833833
backgroundShader.Begin();
834+
backgroundShader.Enable();
835+
backgroundShader.SetInt("drawMasked", 1);
836+
834837
//rlSetUniformSampler(backgroundShader.GetUniformLocation("rtePalette"), g_PostProcessMan.GetPaletteTexture());
835838
BITMAP* drawScreen = (screenCount == 1) ? m_BackBuffer8.get() : m_PlayerScreen8.get();
836839
BITMAP* drawScreenGUI = (screenCount == 1) ? m_BackBuffer8.get() : m_PlayerScreen8.get();

Source/Managers/GLResourceMan.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,10 @@ Texture2D GLResourceMan::GetStaticTextureFromBitmap(BITMAP* bitmap) {
7171
if (!bitmap->extra) {
7272
m_StaticTextures.emplace_back(new GLBitmapInfo);
7373
m_StaticTextures.back()->m_ID = m_StaticTextures.size();
74-
GL_CHECK(glGenTextures(1, &m_StaticTextures.back()->m_Texture));
7574
bitmap->extra = reinterpret_cast<void*>(m_StaticTextures.back().get());
7675
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap_color_depth(bitmap) == 8 ? 1 : 4));
77-
GL_CHECK(glActiveTexture(GL_TEXTURE0));
78-
GL_CHECK(glBindTexture(GL_TEXTURE_2D, GetBitmapInfo(bitmap)->m_Texture));
79-
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, bitmap_color_depth(bitmap) == 8 ? GL_R8 : GL_RGBA, bitmap->w, bitmap->h, 0, bitmap_color_depth(bitmap) == 8 ? GL_RED : GL_RGBA, GL_UNSIGNED_BYTE, bitmap->line[0]));
80-
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
81-
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
82-
// GL_CHECK(glGenerateMipmap(GL_TEXTURE_2D));
76+
m_StaticTextures.back()->m_Texture = rlLoadTexture(bitmap->line[0], bitmap->w, bitmap->h, bitmap_color_depth(bitmap) == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
77+
8378
return {
8479
.id = m_StaticTextures.back()->m_Texture,
8580
.width = bitmap->w,

Source/Renderer/RenderTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
using namespace RTE;
1212

13-
RenderTarget::RenderTarget(const FloatRect& size, const FloatRect& defaultViewport, Texture2D colorTexture, bool defaultFB0) {
13+
RenderTarget::RenderTarget(const FloatRect& size, const FloatRect& defaultViewport, int bitDepth, Texture2D colorTexture, bool defaultFB0) {
1414
m_Size = size;
1515
m_Viewport = defaultViewport;
1616
if (colorTexture.id != 0) {
1717
m_Texture = colorTexture;
1818
m_ColorTextureOwned = false;
1919
} else {
2020
m_Texture = {
21-
.id = rlLoadTexture(nullptr, size.w, size.h, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1),
21+
.id = rlLoadTexture(nullptr, size.w, size.h, bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1),
2222
.width = static_cast<int>(size.w),
2323
.height = static_cast<int>(size.h),
2424
.mipmaps = 0,
25-
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
25+
.format = bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
2626
};
2727
}
2828
m_Depth = {

Source/Renderer/RenderTarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace RTE {
88
class Shader;
99
class RenderTarget {
1010
public:
11-
RenderTarget(const FloatRect& size, const FloatRect& defaultViewport, Texture2D colorTexture = {0, 0, 0, 0, -1}, bool defaultFB0 = false);
11+
RenderTarget(const FloatRect& size, const FloatRect& defaultViewport, int bitDepth = 32, Texture2D colorTexture = {0, 0, 0, 0, -1}, bool defaultFB0 = false);
1212
virtual ~RenderTarget();
1313
void Begin(bool clear = true);
1414
void End();

0 commit comments

Comments
 (0)