_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Macros | Functions | Variables
shaders.cpp File Reference
#include "shaders.h"
#include <stdint.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_opengl_glext.h>
#include <stdlib.h>
#include <regex>
#include <iostream>
#include <fstream>
#include "stratagus.h"
#include "parameters.h"
#include "video.h"
#include "game.h"
#include "iolib.h"
#include "script.h"
#include "./shaders/noshader.glsl"
#include "./shaders/crt.glsl"
#include "./shaders/vhs.glsl"
#include "./shaders/xbrz.glsl"

Macros

#define CCONV   __stdcall
 
#define canUseShaders   (shadersLoaded == 1)
 
#define shadersAreInitialized   (shadersLoaded != -1)
 
#define setCanUseShaders(x)   (shadersLoaded = (x ? 1 : 0))
 
#define COMPILE_BUILTIN_SHADER(name)
 

Functions

 void (CCONV *lazyGlBegin)(GLenum)
 
static std::regex invalidQuoteReplaceRegex ("\"([a-zA-Z0-9 -\\.]+)\"")
 
static GLuint compileShader (const char *source, GLuint shaderType)
 
static GLuint compileProgramSource (std::string source)
 
static GLuint compileProgram (std::string shaderFile)
 
static int loadShaders ()
 
static bool RenderWithShaderInternal (SDL_Renderer *renderer, SDL_Window *win, SDL_Texture *backBuffer)
 
bool RenderWithShader (SDL_Renderer *renderer, SDL_Window *win, SDL_Texture *backBuffer)
 
static int CclGetShader (lua_State *l)
 
static int CclSetShader (lua_State *l)
 
static int CclGetShaderNames (lua_State *l)
 
bool LoadShaderExtensions ()
 

Variables

PFNGLCREATESHADERPROC glCreateShader
 
PFNGLSHADERSOURCEPROC glShaderSource
 
PFNGLCOMPILESHADERPROC glCompileShader
 
PFNGLGETSHADERIVPROC glGetShaderiv
 
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog
 
PFNGLDELETESHADERPROC glDeleteShader
 
PFNGLATTACHSHADERPROC glAttachShader
 
PFNGLCREATEPROGRAMPROC glCreateProgram
 
PFNGLLINKPROGRAMPROC glLinkProgram
 
PFNGLVALIDATEPROGRAMPROC glValidateProgram
 
PFNGLGETPROGRAMIVPROC glGetProgramiv
 
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog
 
PFNGLUSEPROGRAMPROC glUseProgram
 
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation
 
PFNGLUNIFORM1IPROC glUniform1i
 
PFNGLUNIFORM1FPROC glUniform1f
 
PFNGLUNIFORM2FPROC glUniform2f
 
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv
 
PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation
 
PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f
 
 GLfloat
 
GLint GLfloat GLint
 
GLint GLfloat GLsizei
 
 GLdouble
 
static const int MAX_SHADERS = 128
 
static GLuint shaderPrograms [MAX_SHADERS+1] = { (GLuint) 0 }
 
static const char * shaderNames [MAX_SHADERS+1] = { NULL }
 
static char shadersLoaded = -1
 
static int currentShaderIdx = 0
 
const char * none
 
const char * CRT
 
const char * VHS
 
const char * xBRZ
 
static int LastShaderIndex = -1
 
static GLuint ShaderProgram
 
static GLint Texture
 
static GLint MVPMatrix
 
static GLint FrameDirection
 
static GLint FrameCount
 
static GLint OutputSize
 
static GLint TextureSize
 
static GLint InputSize
 
static GLint VertexCoord
 
static GLint TexCoord
 
static int RecacheCount = 0
 
uint8_t SizeChangeCounter
 Just a counter to cache window data on in other places when the size changes. More...
 
static uint16_t LastSizeVersion = -1
 
static int LastVideoWidth = -1
 
static int LastVideoHeight = -1
 
static double LastVideoVerticalPixelSize = -1.0
 
static int DrawableWidth
 
static int DrawableHeight
 
static int XBorder
 
static int YBorder
 
static GLfloat modelview [4 *4]
 
static GLfloat projection [4 *4]
 
static GLfloat matrix [4 *4] = {0.0f}
 

Macro Definition Documentation

◆ canUseShaders

#define canUseShaders   (shadersLoaded == 1)

◆ CCONV

#define CCONV   __stdcall

◆ COMPILE_BUILTIN_SHADER

#define COMPILE_BUILTIN_SHADER (   name)
Value:
std::cout << "[Shaders] Compiling shader: " #name << std::endl; \
shaderPrograms[numShdr] = compileProgramSource(std::string(name)); \
shaderNames[numShdr] = #name ; \
if (shaderPrograms[numShdr] != 0) { \
numShdr++; \
}

◆ setCanUseShaders

#define setCanUseShaders (   x)    (shadersLoaded = (x ? 1 : 0))

◆ shadersAreInitialized

#define shadersAreInitialized   (shadersLoaded != -1)

Function Documentation

◆ CclGetShader()

static int CclGetShader ( lua_State *  l)
static

Description

Get the active shader.

Example:

shader_name = GetShader() print(shader_name)

◆ CclGetShaderNames()

static int CclGetShaderNames ( lua_State *  l)
static

Description

Get the list of shaders.

Example:

shaders = GetShaderNames() for i,name in ipairs(shaders) do print(name) end

◆ CclSetShader()

static int CclSetShader ( lua_State *  l)
static

Description

Apply a shader.

Example:

– Apply a VHS shader SetShader("VHS")

◆ compileProgram()

static GLuint compileProgram ( std::string  shaderFile)
static

◆ compileProgramSource()

static GLuint compileProgramSource ( std::string  source)
static

◆ compileShader()

static GLuint compileShader ( const char *  source,
GLuint  shaderType 
)
static

◆ invalidQuoteReplaceRegex()

static std::regex invalidQuoteReplaceRegex ( "\"([a-zA-Z0-9 -\\.]+)\""  )
static

◆ LoadShaderExtensions()

bool LoadShaderExtensions ( )

◆ loadShaders()

static int loadShaders ( )
static

◆ RenderWithShader()

bool RenderWithShader ( SDL_Renderer *  renderer,
SDL_Window *  win,
SDL_Texture *  backBuffer 
)

◆ RenderWithShaderInternal()

static bool RenderWithShaderInternal ( SDL_Renderer *  renderer,
SDL_Window *  win,
SDL_Texture *  backBuffer 
)
static

◆ void()

void ( CCONV lazyGlBegin)

Variable Documentation

◆ CRT

const char* CRT
Initial value:
=
# 102 "/home/tim/stratagus/stratagus/src/video/shaders.cpp" 2

◆ currentShaderIdx

int currentShaderIdx = 0
static

◆ DrawableHeight

int DrawableHeight
static

◆ DrawableWidth

int DrawableWidth
static

◆ FrameCount

GLint FrameCount
static

◆ FrameDirection

GLint FrameDirection
static

◆ glAttachShader

PFNGLATTACHSHADERPROC glAttachShader

◆ glCompileShader

PFNGLCOMPILESHADERPROC glCompileShader

◆ glCreateProgram

PFNGLCREATEPROGRAMPROC glCreateProgram

◆ glCreateShader

PFNGLCREATESHADERPROC glCreateShader

MIT License

Copyright (c) 2020 Tim Felgentreff Copyright (c) 2017 Augusto Ruiz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

◆ glDeleteShader

PFNGLDELETESHADERPROC glDeleteShader

◆ GLdouble

GLdouble

◆ GLfloat

GLfloat

◆ glGetAttribLocation

PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation

◆ glGetProgramInfoLog

PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog

◆ glGetProgramiv

PFNGLGETPROGRAMIVPROC glGetProgramiv

◆ glGetShaderInfoLog

PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog

◆ glGetShaderiv

PFNGLGETSHADERIVPROC glGetShaderiv

◆ glGetUniformLocation

PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation

◆ GLint

GLint GLfloat GLint

◆ glLinkProgram

PFNGLLINKPROGRAMPROC glLinkProgram

◆ glShaderSource

PFNGLSHADERSOURCEPROC glShaderSource

◆ GLsizei

GLint GLfloat GLsizei

◆ glUniform1f

PFNGLUNIFORM1FPROC glUniform1f

◆ glUniform1i

PFNGLUNIFORM1IPROC glUniform1i

◆ glUniform2f

PFNGLUNIFORM2FPROC glUniform2f

◆ glUniformMatrix4fv

PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv

◆ glUseProgram

PFNGLUSEPROGRAMPROC glUseProgram

◆ glValidateProgram

PFNGLVALIDATEPROGRAMPROC glValidateProgram

◆ glVertexAttrib4f

PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f

◆ InputSize

GLint InputSize
static

◆ LastShaderIndex

int LastShaderIndex = -1
static

◆ LastSizeVersion

uint16_t LastSizeVersion = -1
static

◆ LastVideoHeight

int LastVideoHeight = -1
static

◆ LastVideoVerticalPixelSize

double LastVideoVerticalPixelSize = -1.0
static

◆ LastVideoWidth

int LastVideoWidth = -1
static

◆ matrix

GLfloat matrix[4 *4] = {0.0f}
static

◆ MAX_SHADERS

const int MAX_SHADERS = 128
static

◆ modelview

GLfloat modelview[4 *4]
static

◆ MVPMatrix

GLint MVPMatrix
static

◆ none

const char* none
Initial value:
=
# 99 "/home/tim/stratagus/stratagus/src/video/shaders.cpp" 2

◆ OutputSize

GLint OutputSize
static

◆ projection

GLfloat projection[4 *4]
static

◆ RecacheCount

int RecacheCount = 0
static

◆ shaderNames

const char* shaderNames[MAX_SHADERS+1] = { NULL }
static

◆ ShaderProgram

GLuint ShaderProgram
static

◆ shaderPrograms

GLuint shaderPrograms[MAX_SHADERS+1] = { (GLuint) 0 }
static

◆ shadersLoaded

char shadersLoaded = -1
static

◆ SizeChangeCounter

uint8_t SizeChangeCounter

Just a counter to cache window data on in other places when the size changes.

◆ TexCoord

GLint TexCoord
static

◆ Texture

GLint Texture
static

◆ TextureSize

GLint TextureSize
static

◆ VertexCoord

GLint VertexCoord
static

◆ VHS

const char* VHS
Initial value:
=
# 105 "/home/tim/stratagus/stratagus/src/video/shaders.cpp" 2

◆ XBorder

int XBorder
static

◆ xBRZ

const char* xBRZ
Initial value:
=
# 108 "/home/tim/stratagus/stratagus/src/video/shaders.cpp" 2

◆ YBorder

int YBorder
static
shaderPrograms
static GLuint shaderPrograms[MAX_SHADERS+1]
Definition: shaders.cpp:88
compileProgramSource
static GLuint compileProgramSource(std::string source)
Definition: shaders.cpp:140
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.