Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pierre NARVOR
rtac_base
Commits
16b397c1
Commit
16b397c1
authored
Oct 21, 2021
by
Pierre NARVOR
Browse files
Completed Texture2D with move and copy constructor and assignment
parent
146bf9d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
cuda/include/rtac_base/cuda/Texture2D.h
View file @
16b397c1
...
...
@@ -59,8 +59,13 @@ class Texture2D
public:
Texture2D
();
Texture2D
(
const
Texture2D
<
T
>&
other
);
Texture2D
(
Texture2D
<
T
>&&
other
);
~
Texture2D
();
Texture2D
<
T
>&
operator
=
(
const
Texture2D
<
T
>&
other
);
Texture2D
<
T
>&
operator
=
(
Texture2D
<
T
>&&
other
);
void
allocate_data
(
size_t
width
,
size_t
height
);
void
set_image
(
size_t
width
,
size_t
height
,
const
T
*
data
);
void
set_image
(
size_t
width
,
size_t
height
,
const
DeviceVector
<
T
>&
data
);
...
...
@@ -101,17 +106,7 @@ class Texture2D
void
disable_mipmap
(
bool
updateTexture
=
true
);
};
//Implementation
template
<
typename
T
>
Texture2D
<
T
>::
Texture2D
()
:
width_
(
0
),
height_
(
0
),
data_
(
nullptr
),
description_
(
default_texture_description
()),
textureHandle_
(
0
)
{
}
// Implementation (static methods)
template
<
typename
T
>
cudaChannelFormatDesc
Texture2D
<
T
>::
channel_description
()
{
...
...
@@ -164,6 +159,62 @@ cudaTextureDesc Texture2D<T>::default_texture_description()
return
res
;
}
// Implementation (non-static methods)
template
<
typename
T
>
Texture2D
<
T
>::
Texture2D
()
:
width_
(
0
),
height_
(
0
),
data_
(
nullptr
),
description_
(
default_texture_description
()),
textureHandle_
(
0
)
{}
template
<
typename
T
>
Texture2D
<
T
>::
Texture2D
(
const
Texture2D
<
T
>&
other
)
:
Texture2D
<
T
>
()
{
*
this
=
other
;
}
template
<
typename
T
>
Texture2D
<
T
>::
Texture2D
(
Texture2D
<
T
>&&
other
)
:
width_
(
std
::
exchange
(
other
.
width_
,
0
)),
height_
(
std
::
exchange
(
other
.
height_
,
0
)),
data_
(
std
::
exchange
(
other
.
data_
,
nullptr
)),
description_
(
std
::
move
(
other
.
description_
)),
textureHandle_
(
std
::
exchange
(
other
.
textureHandle_
,
0
))
{}
template
<
typename
T
>
Texture2D
<
T
>&
Texture2D
<
T
>::
operator
=
(
const
Texture2D
<
T
>&
other
)
{
this
->
allocate_data
(
other
.
width_
,
other
.
height_
);
description_
=
other
.
description_
;
CUDA_CHECK
(
cudaMemcpy2DArrayToArray
(
data_
,
0
,
0
,
other
.
data_
,
0
,
0
,
sizeof
(
T
)
*
width_
,
height_
,
cudaMemcpyDeviceToDevice
)
);
this
->
update_texture_handle
();
return
*
this
;
}
template
<
typename
T
>
Texture2D
<
T
>&
Texture2D
<
T
>::
operator
=
(
Texture2D
<
T
>&&
other
)
{
this
->
free_data
();
this
->
destroy_texture_handle
();
width_
=
std
::
exchange
(
other
.
width_
,
0
);
height_
=
std
::
exchange
(
other
.
height_
,
0
);
data_
=
std
::
exchange
(
other
.
data_
,
nullptr
);
description_
=
std
::
move
(
other
.
description_
);
textureHandle_
=
std
::
exchange
(
other
.
textureHandle_
,
0
);
return
*
this
;
}
template
<
typename
T
>
Texture2D
<
T
>::~
Texture2D
()
{
...
...
cuda/tests/texture/src/texture_test.cpp
View file @
16b397c1
...
...
@@ -44,6 +44,9 @@ int main()
std
::
vector
<
float4
>
subdata1
(
W2
*
H2
,
float4
({
0.5
f
,
0.5
f
,
0.5
f
,
1.0
f
}));
tex1
.
set_subimage
(
W2
,
H2
,
W2
,
H2
,
subdata1
.
data
());
res1
=
render_texture
(
Wout
,
Hout
,
tex1
);
// testing texture copy
Texture2D
<
float4
>
tex2
(
tex1
);
tex2
.
set_subimage
(
W2
,
H2
,
0
,
0
,
subdata1
.
data
());
auto
rgbData
=
std
::
vector
<
uint8_t
>
(
3
*
res1
.
size
());
for
(
int
i
=
0
,
j
=
0
;
i
<
res1
.
size
();
i
++
)
{
...
...
@@ -52,9 +55,31 @@ int main()
rgbData
[
j
+
2
]
=
255
*
res1
[
i
].
z
;
j
+=
3
;
}
write_ppm
(
"output.ppm"
,
Wout
,
Hout
,
(
const
char
*
)
rgbData
.
data
());
HostVector
<
float4
>
res2
;
res2
=
render_texture
(
Wout
,
Hout
,
tex2
);
rgbData
.
resize
(
3
*
res2
.
size
());
for
(
int
i
=
0
,
j
=
0
;
i
<
res2
.
size
();
i
++
)
{
rgbData
[
j
]
=
255
*
res2
[
i
].
x
;
rgbData
[
j
+
1
]
=
255
*
res2
[
i
].
y
;
rgbData
[
j
+
2
]
=
255
*
res2
[
i
].
z
;
j
+=
3
;
}
write_ppm
(
"output_copy.ppm"
,
Wout
,
Hout
,
(
const
char
*
)
rgbData
.
data
());
Texture2D
<
float4
>
tex3
(
std
::
move
(
tex2
));
res2
=
render_texture
(
Wout
,
Hout
,
tex3
);
rgbData
.
resize
(
3
*
res2
.
size
());
for
(
int
i
=
0
,
j
=
0
;
i
<
res2
.
size
();
i
++
)
{
rgbData
[
j
]
=
255
*
res2
[
i
].
x
;
rgbData
[
j
+
1
]
=
255
*
res2
[
i
].
y
;
rgbData
[
j
+
2
]
=
255
*
res2
[
i
].
z
;
j
+=
3
;
}
write_ppm
(
"output_move.ppm"
,
Wout
,
Hout
,
(
const
char
*
)
rgbData
.
data
());
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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