Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Bonzomatic
Commits
b898afda
Commit
b898afda
authored
Jan 31, 2021
by
Gargaj
Browse files
add support for texture that contains the contents of the previous frame
parent
122be000
Changes
7
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
b898afda
...
...
@@ -2,5 +2,6 @@ Bonzomatic
.obj
tmp
build
build.*
.vs
.DS_Store
cmake_all.bat
View file @
b898afda
...
...
@@ -42,10 +42,10 @@ REM --------------------- BUILD TIME -------------------------------
:build
set
BNZ_COMPILER
=
Visual
Studio
1
0
201
0
if
not
"
%BNZ
_X64
%
"
==
"ON"
goto
skip
me
set
BNZ_COMPILER
=
Visual
Studio
1
0
201
0
Win64
:skip
me
set
BNZ_COMPILER
=
Visual
Studio
1
4
201
5
if
not
"
%BNZ
_X64
%
"
==
"ON"
goto
skip
vs
set
BNZ_COMPILER
=
Visual
Studio
1
4
201
5
Win64
:skip
vs
set
BNZ_OUT_DIR
=
x86
set
BNZ_PLATFORM
=
W32
...
...
src/Renderer.h
View file @
b898afda
...
...
@@ -56,6 +56,7 @@ namespace Renderer
TEXTURETYPE
type
;
};
Texture
*
CreateRGBA8Texture
();
Texture
*
CreateRGBA8TextureFromFile
(
const
char
*
szFilename
);
Texture
*
CreateA8TextureFromData
(
int
w
,
int
h
,
const
unsigned
char
*
data
);
Texture
*
Create1DR32Texture
(
int
w
);
...
...
@@ -63,6 +64,9 @@ namespace Renderer
void
SetShaderTexture
(
const
char
*
szTextureName
,
Texture
*
tex
);
void
BindTexture
(
Texture
*
tex
);
// temporary function until all the quad rendering is moved to the renderer
void
ReleaseTexture
(
Texture
*
tex
);
void
CopyBackbufferToTexture
(
Texture
*
tex
);
struct
Vertex
{
Vertex
(
float
_x
,
float
_y
,
unsigned
int
_c
=
0xFFFFFFFF
,
float
_u
=
0.0
,
float
_v
=
0.0
)
:
...
...
src/main.cpp
View file @
b898afda
...
...
@@ -304,6 +304,7 @@ int main(int argc, const char *argv[])
return
0
;
}
Renderer
::
Texture
*
texPreviousFrame
=
Renderer
::
CreateRGBA8Texture
();
Renderer
::
Texture
*
texFFT
=
Renderer
::
Create1DR32Texture
(
FFT_SIZE
);
Renderer
::
Texture
*
texFFTSmoothed
=
Renderer
::
Create1DR32Texture
(
FFT_SIZE
);
Renderer
::
Texture
*
texFFTIntegrated
=
Renderer
::
Create1DR32Texture
(
FFT_SIZE
);
...
...
@@ -390,6 +391,7 @@ int main(int argc, const char *argv[])
bool
bShowGui
=
true
;
Timer
::
Start
();
float
fNextTick
=
0.1
f
;
float
fLastTimeMS
=
Timer
::
GetTime
();
while
(
!
Renderer
::
WantsToQuit
())
{
bool
newShader
=
false
;
...
...
@@ -481,6 +483,10 @@ int main(int argc, const char *argv[])
Renderer
::
SetShaderConstant
(
"fGlobalTime"
,
time
);
Renderer
::
SetShaderConstant
(
"v2Resolution"
,
settings
.
sRenderer
.
nWidth
,
settings
.
sRenderer
.
nHeight
);
float
fTime
=
Timer
::
GetTime
();
Renderer
::
SetShaderConstant
(
"fFrameTime"
,
(
fTime
-
fLastTimeMS
)
/
1000.0
f
);
fLastTimeMS
=
fTime
;
for
(
std
::
map
<
int
,
std
::
string
>::
iterator
it
=
midiRoutes
.
begin
();
it
!=
midiRoutes
.
end
();
it
++
)
{
Renderer
::
SetShaderConstant
(
it
->
second
.
c_str
(),
MIDI
::
GetCCValue
(
it
->
first
)
);
...
...
@@ -510,6 +516,7 @@ int main(int argc, const char *argv[])
Renderer
::
SetShaderTexture
(
"texFFT"
,
texFFT
);
Renderer
::
SetShaderTexture
(
"texFFTSmoothed"
,
texFFTSmoothed
);
Renderer
::
SetShaderTexture
(
"texFFTIntegrated"
,
texFFTIntegrated
);
Renderer
::
SetShaderTexture
(
"texPreviousFrame"
,
texPreviousFrame
);
for
(
std
::
map
<
std
::
string
,
Renderer
::
Texture
*>::
iterator
it
=
textures
.
begin
();
it
!=
textures
.
end
();
it
++
)
{
...
...
@@ -518,6 +525,8 @@ int main(int argc, const char *argv[])
Renderer
::
RenderFullscreenQuad
();
Renderer
::
CopyBackbufferToTexture
(
texPreviousFrame
);
Renderer
::
StartTextRendering
();
if
(
bShowGui
)
...
...
@@ -591,6 +600,7 @@ int main(int argc, const char *argv[])
MIDI
::
Close
();
FFT
::
Close
();
Renderer
::
ReleaseTexture
(
texPreviousFrame
);
Renderer
::
ReleaseTexture
(
texFFT
);
Renderer
::
ReleaseTexture
(
texFFTSmoothed
);
for
(
std
::
map
<
std
::
string
,
Renderer
::
Texture
*>::
iterator
it
=
textures
.
begin
();
it
!=
textures
.
end
();
it
++
)
...
...
src/platform_glfw/Renderer.cpp
View file @
b898afda
...
...
@@ -123,10 +123,12 @@ namespace Renderer
"
\n
"
"uniform float fGlobalTime; // in seconds
\n
"
"uniform vec2 v2Resolution; // viewport resolution (in pixels)
\n
"
"uniform float fFrameTime; // duration of the last frame, in seconds
\n
"
"
\n
"
"uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
\n
"
"uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
\n
"
"uniform sampler1D texFFTIntegrated; // this is continually increasing
\n
"
"uniform sampler2D texPreviousFrame; // screenshot of the previous frame
\n
"
"{%textures:begin%}"
// leave off \n here
"uniform sampler2D {%textures:name%};
\n
"
"{%textures:end%}"
// leave off \n here
...
...
@@ -690,6 +692,32 @@ namespace Renderer
};
int
textureUnit
=
0
;
Texture
*
CreateRGBA8Texture
()
{
void
*
data
=
NULL
;
GLenum
internalFormat
=
GL_SRGB8_ALPHA8
;
GLenum
srcFormat
=
GL_FLOAT
;
GLenum
format
=
GL_UNSIGNED_BYTE
;
GLuint
glTexId
=
0
;
glGenTextures
(
1
,
&
glTexId
);
glBindTexture
(
GL_TEXTURE_2D
,
glTexId
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
GLTexture
*
tex
=
new
GLTexture
();
tex
->
width
=
nWidth
;
tex
->
height
=
nHeight
;
tex
->
ID
=
glTexId
;
tex
->
type
=
TEXTURETYPE_2D
;
tex
->
unit
=
textureUnit
++
;
return
tex
;
}
Texture
*
CreateRGBA8TextureFromFile
(
const
char
*
szFilename
)
{
int
comp
=
0
;
...
...
@@ -815,6 +843,13 @@ namespace Renderer
glDeleteTextures
(
1
,
&
((
GLTexture
*
)
tex
)
->
ID
);
}
void
CopyBackbufferToTexture
(
Texture
*
tex
)
{
glActiveTexture
(
GL_TEXTURE0
+
(
(
GLTexture
*
)
tex
)
->
unit
);
glBindTexture
(
GL_TEXTURE_2D
,
(
(
GLTexture
*
)
tex
)
->
ID
);
glCopyTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGB
,
0
,
0
,
nWidth
,
nHeight
,
0
);
}
//////////////////////////////////////////////////////////////////////////
// text rendering
...
...
src/platform_w32_dx11/Renderer.cpp
View file @
b898afda
...
...
@@ -112,12 +112,14 @@ namespace Renderer
"Texture1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
\n
"
"Texture1D texFFTSmoothed; // this one has longer falloff and less harsh transients
\n
"
"Texture1D texFFTIntegrated; // this is continually increasing
\n
"
"Texture2D texPreviousFrame; // screenshot of the previous frame
\n
"
"SamplerState smp;
\n
"
"
\n
"
"cbuffer constants
\n
"
"{
\n
"
"
\t
float fGlobalTime; // in seconds
\n
"
"
\t
float2 v2Resolution; // viewport resolution (in pixels)
\n
"
"
\t
float fFrameTime; // duration of the last frame, in seconds
\n
"
"{%midi:begin%}"
"
\t
float {%midi:name%};
\n
"
"{%midi:end%}"
...
...
@@ -912,6 +914,35 @@ namespace Renderer
}
int
textureUnit
=
0
;
Renderer
::
Texture
*
CreateRGBA8Texture
()
{
D3D11_TEXTURE2D_DESC
desc
;
ZeroMemory
(
&
desc
,
sizeof
(
D3D11_TEXTURE2D_DESC
)
);
desc
.
Width
=
nWidth
;
desc
.
Height
=
nHeight
;
desc
.
Format
=
DXGI_FORMAT_R8G8B8A8_UNORM
;
desc
.
MipLevels
=
1
;
desc
.
ArraySize
=
1
;
desc
.
SampleDesc
.
Count
=
1
;
desc
.
BindFlags
=
D3D11_BIND_SHADER_RESOURCE
;
ID3D11Texture2D
*
pTex
=
NULL
;
if
(
pDevice
->
CreateTexture2D
(
&
desc
,
NULL
,
&
pTex
)
!=
S_OK
)
return
NULL
;
DX11Texture
*
tex
=
new
DX11Texture
();
tex
->
width
=
nWidth
;
tex
->
height
=
nHeight
;
tex
->
pTexture
=
pTex
;
tex
->
type
=
TEXTURETYPE_2D
;
tex
->
format
=
desc
.
Format
;
CreateResourceView
(
tex
);
return
tex
;
}
Texture
*
CreateRGBA8TextureFromFile
(
const
char
*
szFilename
)
{
int
comp
=
0
;
...
...
@@ -1057,6 +1088,13 @@ namespace Renderer
delete
tex
;
}
void
CopyBackbufferToTexture
(
Texture
*
tex
)
{
ID3D11Resource
*
pTex
=
(
(
DX11Texture
*
)
tex
)
->
pTexture
;
pContext
->
CopySubresourceRegion
(
pTex
,
0
,
0
,
0
,
0
,
pBackBuffer
,
0
,
NULL
);
}
//////////////////////////////////////////////////////////////////////////
// text rendering
...
...
src/platform_w32_dx9/Renderer.cpp
View file @
b898afda
...
...
@@ -116,6 +116,8 @@ namespace Renderer
"// this one has longer falloff and less harsh transients
\n
"
"texture texFFTIntegratedT; sampler1D texFFTIntegrated = sampler_state { Texture = <texFFTIntegratedT>; };
\n
"
"// this is continually increasing
\n
"
"texture texPreviousFrameT; sampler2D texPreviousFrame = sampler_state { Texture = <texPreviousFrameT>; };
\n
"
"// screenshot of the previous frame
\n
"
"
\n
"
"{%textures:begin%}"
// leave off \n here
"texture raw{%textures:name%}; sampler2D {%textures:name%} = sampler_state { Texture = <raw{%textures:name%}>; };
\n
"
...
...
@@ -125,6 +127,7 @@ namespace Renderer
"float {%midi:name%};
\n
"
"{%midi:end%}"
"float fGlobalTime; // in seconds
\n
"
"float fFrameTime; // duration of the last frame, in seconds
\n
"
"float2 v2Resolution; // viewport resolution (in pixels)
\n
"
"
\n
"
"float4 plas( float2 v, float time )
\n
"
...
...
@@ -480,11 +483,12 @@ namespace Renderer
D3DDECL_END
()
};
static
float
pQuad
[]
=
{
-
1.0
,
-
1.0
,
0.0
,
0.0
,
0.0
,
-
1.0
,
1.0
,
0.0
,
0.0
,
1.0
,
1.0
,
-
1.0
,
0.0
,
1.0
,
0.0
,
1.0
,
1.0
,
0.0
,
1.0
,
1.0
,
static
float
pQuad
[]
=
{
-
1.0
,
-
1.0
,
0.0
,
0.0
+
0.5
/
(
float
)
nWidth
,
0.0
+
0.5
/
(
float
)
nHeight
,
-
1.0
,
1.0
,
0.0
,
0.0
+
0.5
/
(
float
)
nWidth
,
1.0
+
0.5
/
(
float
)
nHeight
,
1.0
,
-
1.0
,
0.0
,
1.0
+
0.5
/
(
float
)
nWidth
,
0.0
+
0.5
/
(
float
)
nHeight
,
1.0
,
1.0
,
0.0
,
1.0
+
0.5
/
(
float
)
nWidth
,
1.0
+
0.5
/
(
float
)
nHeight
,
};
pDevice
->
CreateVertexBuffer
(
4
*
5
*
sizeof
(
float
),
D3DUSAGE_WRITEONLY
,
D3DFVF_XYZ
|
D3DFVF_TEX1
,
D3DPOOL_DEFAULT
,
&
pFullscreenQuadVB
,
NULL
);
...
...
@@ -623,6 +627,24 @@ namespace Renderer
};
int
textureUnit
=
0
;
Renderer
::
Texture
*
CreateRGBA8Texture
()
{
LPDIRECT3DTEXTURE9
pTex
=
NULL
;
pDevice
->
CreateTexture
(
nWidth
,
nHeight
,
1
,
D3DUSAGE_RENDERTARGET
,
D3DFMT_X8R8G8B8
,
D3DPOOL_DEFAULT
,
&
pTex
,
NULL
);
if
(
!
pTex
)
return
NULL
;
DX9Texture
*
tex
=
new
DX9Texture
();
tex
->
pTexture
=
pTex
;
tex
->
width
=
nWidth
;
tex
->
height
=
nHeight
;
tex
->
type
=
TEXTURETYPE_2D
;
return
tex
;
}
Texture
*
CreateRGBA8TextureFromFile
(
const
char
*
szFilename
)
{
LPDIRECT3DTEXTURE9
pTex
=
NULL
;
...
...
@@ -630,8 +652,8 @@ namespace Renderer
HRESULT
h
=
D3DXCreateTextureFromFileExA
(
pDevice
,
szFilename
,
D3DX_DEFAULT
,
D3DX_DEFAULT
,
D3DX_DEFAULT
_NONPOW2
,
D3DX_DEFAULT
_NONPOW2
,
0
,
NULL
,
D3DFMT_FROM_FILE
,
...
...
@@ -734,10 +756,27 @@ namespace Renderer
return
tex
;
}
void
ReleaseTexture
(
Texture
*
tex
)
{
(
(
DX9Texture
*
)
tex
)
->
pTexture
->
Release
();
delete
tex
;
}
void
CopyBackbufferToTexture
(
Texture
*
tex
)
{
LPDIRECT3DTEXTURE9
pTex
=
(
(
DX9Texture
*
)
tex
)
->
pTexture
;
LPDIRECT3DSURFACE9
pSurf
=
NULL
;
pTex
->
GetSurfaceLevel
(
0
,
&
pSurf
);
if
(
pSurf
)
{
HRESULT
res
=
pDevice
->
StretchRect
(
pBackBuffer
,
NULL
,
pSurf
,
NULL
,
D3DTEXF_LINEAR
);
pSurf
->
Release
();
}
}
//////////////////////////////////////////////////////////////////////////
// text rendering
void
StartTextRendering
()
{
pDevice
->
SetVertexShader
(
NULL
);
...
...
@@ -764,12 +803,6 @@ namespace Renderer
pDevice
->
SetTextureStageState
(
0
,
D3DTSS_ALPHAARG2
,
D3DTA_TEXTURE
);
}
void
ReleaseTexture
(
Texture
*
tex
)
{
((
DX9Texture
*
)
tex
)
->
pTexture
->
Release
();
delete
tex
;
}
int
bufferPointer
=
0
;
unsigned
char
buffer
[
GUIQUADVB_SIZE
*
sizeof
(
float
)
*
6
];
bool
lastModeIsQuad
=
true
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment