Skip to content

Commit

Permalink
get shaders to work with texture rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed May 21, 2022
1 parent b723bef commit f25fe38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
35 changes: 16 additions & 19 deletions src/video/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,27 +798,24 @@ void RealizeVideoMemory()
if (dummyRenderer) {
return;
}
if (NumRects) {
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
if (!RenderWithShader(TheRenderer, TheWindow, TheTexture)) {
SDL_SetTextureBlendMode(TheTexture, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
if (EnableDebugPrint) {
// show a bar representing fps scaled by 10
SDL_SetRenderDrawColor(TheRenderer, 255, 0, 0, 255);
Uint32 nextTick = SDL_GetTicks();
double fps = 10000.0 / (nextTick - LastTick);
SDL_RenderDrawLine(TheRenderer, 0, 0, floorl(fps), 0);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
LastTick = nextTick;
}
SDL_RenderPresent(TheRenderer);
// SDL_RenderClear(TheRenderer);
}
NumRects = 0;
} else {
if (EnableDebugPrint) {
// show a bar representing fps scaled by 10
SDL_SetRenderDrawColor(TheRenderer, 255, 0, 0, 255);
Uint32 nextTick = SDL_GetTicks();
double fps = 10000.0 / (nextTick - LastTick);
SDL_RenderDrawLine(TheRenderer, 0, 0, floorl(fps), 0);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
LastTick = nextTick;
}
if (!RenderWithShader(TheRenderer, TheWindow, TheTexture)) {
SDL_SetRenderTarget(TheRenderer, NULL);
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
// SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
// SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
SDL_RenderPresent(TheRenderer);
}
SDL_SetRenderTarget(TheRenderer, TheTexture);
// SDL_RenderClear(TheRenderer);
if (!Preference.HardwareCursor) {
HideCursor();
}
Expand Down
6 changes: 3 additions & 3 deletions src/video/shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* back
GLint oldProgramId;
// Detach the texture
SDL_SetRenderTarget(renderer, NULL);
// SDL_RenderClear(renderer);
SDL_RenderClear(renderer);

SDL_GL_BindTexture(backBuffer, NULL, NULL);
if (LastShaderIndex != currentShaderIdx) {
Expand Down Expand Up @@ -368,8 +368,8 @@ bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* back

const GLfloat minu = 0.0f;
const GLfloat maxu = 1.0f;
const GLfloat minv = 0.0f;
const GLfloat maxv = 1.0f;
const GLfloat minv = 1.0f;
const GLfloat maxv = 0.0f;

lazyGlMatrixMode(GL_PROJECTION);
lazyGlLoadIdentity();
Expand Down
3 changes: 2 additions & 1 deletion src/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ bool CVideo::ResizeScreen(int w, int h)
}
TheTexture = SDL_CreateTexture(TheRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
SDL_TEXTUREACCESS_TARGET,
w, h);
SDL_SetRenderTarget(TheRenderer, TheTexture);

SetClipping(0, 0, w - 1, h - 1);

Expand Down

0 comments on commit f25fe38

Please sign in to comment.