- [WIP] Solventant el problema dels shaders
This commit is contained in:
1 parent
9efdbe9933
commit
7aebcfe055
4 files changed
+80
-11
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "mini/surf/surf.h"
|
||||
#include "mini/pal/pal.h"
|
||||
#include "mini/shader/shader.h"
|
||||
#include "other/log.h"
|
||||
|
||||
namespace backend
|
||||
{
|
||||
@@ -16,6 +17,9 @@ namespace backend
|
||||
SDL_Texture *tex_back { nullptr };
|
||||
SDL_Texture *tex_shader { nullptr };
|
||||
|
||||
int fullscreen_scale;
|
||||
SDL_FRect dest_rect;
|
||||
|
||||
void init() {
|
||||
const auto &title = mini::win::state.title;
|
||||
const auto &width = mini::win::state.width;
|
||||
@@ -27,8 +31,9 @@ namespace backend
|
||||
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||
while ( width * zoom > dm->w || height * zoom > dm->h) zoom--;
|
||||
|
||||
const int z = mini::win::state.fullscreen ? 1 : zoom;
|
||||
// Crear SDL_Window i SDL_Renderer
|
||||
window = SDL_CreateWindow(title, width*zoom, height*zoom, SDL_WINDOW_OPENGL|(mini::win::state.fullscreen?SDL_WINDOW_FULLSCREEN:0));
|
||||
window = SDL_CreateWindow(title, width*z, height*z, SDL_WINDOW_OPENGL|(mini::win::state.fullscreen?SDL_WINDOW_FULLSCREEN:0));
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||
renderer = SDL_CreateRenderer(window, NULL);
|
||||
SDL_SetRenderVSync(renderer, SDL_RENDERER_VSYNC_DISABLED);
|
||||
@@ -41,11 +46,44 @@ namespace backend
|
||||
SDL_SetTextureScaleMode(tex_back, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
// Crear textura shaders i inicialitzar shaders
|
||||
tex_shader = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom);
|
||||
int w = width*z;
|
||||
int h = height*z;
|
||||
if (mini::win::state.fullscreen) {
|
||||
fullscreen_scale = SDL_min(dm->w/width, dm->h/height);
|
||||
w = width * fullscreen_scale;
|
||||
h = height * fullscreen_scale;
|
||||
log_msg(LOG_INFO, "fullscreen_scale: %i\n", fullscreen_scale);
|
||||
}
|
||||
tex_shader = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
|
||||
SDL_SetTextureScaleMode(tex_shader, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
int ww, wh;
|
||||
SDL_GetWindowSize(window, &ww, &wh);
|
||||
printf("window: %ix%i\n", ww, wh);
|
||||
|
||||
if (mini::win::state.fullscreen)
|
||||
{
|
||||
dest_rect.w = width * fullscreen_scale;
|
||||
dest_rect.h = height * fullscreen_scale;
|
||||
dest_rect.x = (dm->w - dest_rect.w)/2;
|
||||
dest_rect.y = (dm->h - dest_rect.h)/2;
|
||||
|
||||
printf("width: %i, height: %i\n", width, height);
|
||||
printf("screen: %ix%i\n", dm->w, dm->h);
|
||||
printf("dest_rect: (%i,%i)-(%i,%i)\n", (int)dest_rect.x, (int)dest_rect.y, (int)dest_rect.w, (int)dest_rect.h);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest_rect.x = dest_rect.y = 0;
|
||||
dest_rect.w = width * zoom;
|
||||
dest_rect.h = height * zoom;
|
||||
printf("dest_rect: (%i,%i)-(%i,%i)\n", (int)dest_rect.x, (int)dest_rect.y, (int)dest_rect.w, (int)dest_rect.h);
|
||||
}
|
||||
shader::reinit();
|
||||
}
|
||||
|
||||
void quit() {
|
||||
shader::quit();
|
||||
SDL_DestroyTexture(tex_shader);
|
||||
SDL_DestroyTexture(tex_back);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
@@ -65,6 +103,13 @@ namespace backend
|
||||
uint8_t *p = s.p;
|
||||
for (uint32_t i=0;i<s.size;++i) pixels[i] = mini::pal::palette[p[i]];
|
||||
SDL_UnlockTexture(tex_back);
|
||||
|
||||
if (mini::win::state.fullscreen)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
SDL_RenderTexture(renderer, tex_back, NULL, NULL); //NEW
|
||||
|
||||
backend::shader::render();
|
||||
|
||||
Reference in new issue
Block a user