Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Commits
6d346928
Commit
6d346928
authored
3 years ago
by
Vanessa Karolek
Browse files
Options
Downloads
Patches
Plain Diff
[
#94
] use rendered texture in shaders
parent
482bb3e5
No related branches found
No related tags found
1 merge request
!77
Resolve "SAF-R Module"
Pipeline
#26475
passed
3 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
projects/saf_r/shaders/shader.frag
+8
-2
8 additions, 2 deletions
projects/saf_r/shaders/shader.frag
projects/saf_r/shaders/shader.vert
+8
-2
8 additions, 2 deletions
projects/saf_r/shaders/shader.vert
projects/saf_r/src/main.cpp
+34
-13
34 additions, 13 deletions
projects/saf_r/src/main.cpp
with
50 additions
and
17 deletions
projects/saf_r/shaders/shader.frag
+
8
−
2
View file @
6d346928
...
...
@@ -2,8 +2,14 @@
#extension GL_ARB_separate_shader_objects : enable
layout
(
location
=
0
)
in
vec3
fragColor
;
layout
(
location
=
0
)
out
vec4
outColor
;
layout
(
location
=
1
)
in
vec2
texCoord
;
layout
(
location
=
0
)
out
vec3
outColor
;
layout
(
set
=
0
,
binding
=
0
)
uniform
texture2D
tex
;
layout
(
set
=
0
,
binding
=
1
)
uniform
sampler
textureSampler
;
void
main
()
{
outColor
=
vec4
(
fragColor
,
1
.
0
);
outColor
=
fragColor
;
outColor
=
texture
(
sampler2D
(
tex
,
textureSampler
),
texCoord
).
rgb
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
projects/saf_r/shaders/shader.vert
+
8
−
2
View file @
6d346928
...
...
@@ -2,6 +2,7 @@
#extension GL_ARB_separate_shader_objects : enable
layout
(
location
=
0
)
out
vec3
fragColor
;
layout
(
location
=
1
)
out
vec2
texCoord
;
layout
(
push_constant
)
uniform
constants
{
mat4
mvp
;
...
...
@@ -11,7 +12,7 @@ void main() {
vec3
positions
[
3
]
=
{
vec3
(
-
1
,
-
1
,
-
1
),
vec3
(
3
,
-
1
,
-
1
),
vec3
(
-
1
,
3
,
-
1
)
,
vec3
(
-
1
,
3
,
-
1
)
};
vec3
colors
[
3
]
=
{
...
...
@@ -20,6 +21,11 @@ void main() {
vec3
(
0
,
0
,
1
)
};
gl_Position
=
mvp
*
vec4
(
positions
[
gl_VertexIndex
],
1
.
0
);
vec4
position
=
mvp
*
vec4
(
positions
[
gl_VertexIndex
],
1
.
0
);
gl_Position
=
position
;
texCoord
.
x
=
(
position
.
x
+
1
.
0
)
*
0
.
5
;
texCoord
.
y
=
(
position
.
y
+
1
.
0
)
*
0
.
5
;
fragColor
=
colors
[
gl_VertexIndex
];
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
projects/saf_r/src/main.cpp
+
34
−
13
View file @
6d346928
...
...
@@ -153,12 +153,43 @@ int main(int argc, const char** argv) {
{
"VK_KHR_swapchain"
}
);
vkcv
::
ShaderProgram
triangleShaderProgram
;
vkcv
::
shader
::
GLSLCompiler
compiler
;
compiler
.
compile
(
vkcv
::
ShaderStage
::
VERTEX
,
std
::
filesystem
::
path
(
"shaders/shader.vert"
),
[
&
triangleShaderProgram
](
vkcv
::
ShaderStage
shaderStage
,
const
std
::
filesystem
::
path
&
path
)
{
triangleShaderProgram
.
addShader
(
shaderStage
,
path
);
});
compiler
.
compile
(
vkcv
::
ShaderStage
::
FRAGMENT
,
std
::
filesystem
::
path
(
"shaders/shader.frag"
),
[
&
triangleShaderProgram
](
vkcv
::
ShaderStage
shaderStage
,
const
std
::
filesystem
::
path
&
path
)
{
triangleShaderProgram
.
addShader
(
shaderStage
,
path
);
});
uint32_t
setID
=
0
;
std
::
vector
<
vkcv
::
DescriptorBinding
>
descriptorBindings
=
{
triangleShaderProgram
.
getReflectedDescriptors
()[
setID
]
};
vkcv
::
DescriptorSetHandle
descriptorSet
=
core
.
createDescriptorSet
(
descriptorBindings
);
vkcv
::
asset
::
TextureData
texData
=
vkcv
::
asset
::
loadTexture
(
"textures/texture.png"
);
vkcv
::
Image
texture
=
core
.
createImage
(
vk
::
Format
::
eR8G8B8A8Srgb
,
800
,
600
);
texture
.
fill
(
texData
.
data
.
data
());
texture
.
generateMipChainImmediate
();
texture
.
switchLayout
(
vk
::
ImageLayout
::
eShaderReadOnlyOptimal
);
vkcv
::
SamplerHandle
sampler
=
core
.
createSampler
(
vkcv
::
SamplerFilterType
::
LINEAR
,
vkcv
::
SamplerFilterType
::
LINEAR
,
vkcv
::
SamplerMipmapMode
::
LINEAR
,
vkcv
::
SamplerAddressMode
::
REPEAT
);
vkcv
::
DescriptorWrites
setWrites
;
setWrites
.
sampledImageWrites
=
{
vkcv
::
SampledImageDescriptorWrite
(
0
,
texture
.
getHandle
())
};
setWrites
.
samplerWrites
=
{
vkcv
::
SamplerDescriptorWrite
(
1
,
sampler
)
};
core
.
writeDescriptorSet
(
descriptorSet
,
setWrites
);
const
auto
&
context
=
core
.
getContext
();
auto
triangleIndexBuffer
=
core
.
createBuffer
<
uint16_t
>
(
vkcv
::
BufferType
::
INDEX
,
3
,
vkcv
::
BufferMemoryType
::
DEVICE_LOCAL
);
...
...
@@ -180,18 +211,7 @@ int main(int argc, const char** argv) {
return
EXIT_FAILURE
;
}
vkcv
::
ShaderProgram
triangleShaderProgram
;
vkcv
::
shader
::
GLSLCompiler
compiler
;
compiler
.
compile
(
vkcv
::
ShaderStage
::
VERTEX
,
std
::
filesystem
::
path
(
"shaders/shader.vert"
),
[
&
triangleShaderProgram
](
vkcv
::
ShaderStage
shaderStage
,
const
std
::
filesystem
::
path
&
path
)
{
triangleShaderProgram
.
addShader
(
shaderStage
,
path
);
});
compiler
.
compile
(
vkcv
::
ShaderStage
::
FRAGMENT
,
std
::
filesystem
::
path
(
"shaders/shader.frag"
),
[
&
triangleShaderProgram
](
vkcv
::
ShaderStage
shaderStage
,
const
std
::
filesystem
::
path
&
path
)
{
triangleShaderProgram
.
addShader
(
shaderStage
,
path
);
});
const
vkcv
::
PipelineConfig
trianglePipelineDefinition
{
triangleShaderProgram
,
...
...
@@ -199,7 +219,7 @@ int main(int argc, const char** argv) {
(
uint32_t
)
windowHeight
,
trianglePass
,
{},
{},
{
core
.
getDescriptorSet
(
descriptorSet
).
layout
},
false
};
...
...
@@ -214,7 +234,8 @@ int main(int argc, const char** argv) {
auto
start
=
std
::
chrono
::
system_clock
::
now
();
const
vkcv
::
Mesh
renderMesh
({},
triangleIndexBuffer
.
getVulkanHandle
(),
3
);
vkcv
::
DrawcallInfo
drawcall
(
renderMesh
,
{},
1
);
vkcv
::
DescriptorSetUsage
descriptorUsage
(
0
,
core
.
getDescriptorSet
(
descriptorSet
).
vulkanHandle
);
vkcv
::
DrawcallInfo
drawcall
(
renderMesh
,
{
descriptorUsage
},
1
);
const
vkcv
::
ImageHandle
swapchainInput
=
vkcv
::
ImageHandle
::
createSwapchainImageHandle
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment