Blender V5.0
immediate_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "GPU_framebuffer.hh"
8#include "GPU_immediate.hh"
10#include "GPU_state.hh"
11#include "gpu_testing.hh"
12
13#include "BLI_math_vector.hh"
14
15namespace blender::gpu::tests {
16
17static constexpr int Size = 4;
18
20{
22 Size,
23 false,
24 TextureFormat::SFLOAT_16_16_16_16,
27 false,
28 nullptr);
29 BLI_assert(offscreen != nullptr);
30 GPU_offscreen_bind(offscreen, false);
31
33 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
34
36
37 float4 color(1.0, 0.5, 0.25, 1.0);
40 immVertex3f(pos, -1.0f, 1.0f, 0.0f);
41 immVertex3f(pos, 1.0f, 1.0f, 0.0f);
42 immVertex3f(pos, -1.0f, -1.0f, 0.0f);
43 immVertex3f(pos, 1.0f, -1.0f, 0.0f);
44 immEnd();
45
46 GPU_offscreen_unbind(offscreen, false);
47 GPU_flush();
48
49 /* Read back data and perform some basic tests. */
50 Vector<float4> read_data(Size * Size);
51 GPU_offscreen_read_color(offscreen, GPU_DATA_FLOAT, read_data.data());
52 for (const float4 &read_color : read_data) {
53 EXPECT_EQ(read_color, color);
54 }
55
56 GPU_offscreen_free(offscreen);
57
59}
60GPU_TEST(immediate_one_plane)
61
62
69{
71 Size,
72 false,
73 TextureFormat::SFLOAT_16_16_16_16,
76 false,
77 nullptr);
78 BLI_assert(offscreen != nullptr);
79 GPU_offscreen_bind(offscreen, false);
80
82 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
83
85
86 float4 color(1.0, 0.5, 0.25, 1.0);
89 immVertex3f(pos, -1.0f, 1.0f, 0.0f);
90 immVertex3f(pos, 0.0f, 1.0f, 0.0f);
91 immVertex3f(pos, -1.0f, -1.0f, 0.0f);
92 immVertex3f(pos, 0.0f, -1.0f, 0.0f);
93 immEnd();
94
95 float4 color2(0.25, 0.5, 1.0, 1.0);
96 immUniformColor4fv(color2);
98 immVertex3f(pos, 0.0f, 1.0f, 0.0f);
99 immVertex3f(pos, 1.0f, 1.0f, 0.0f);
100 immVertex3f(pos, 0.0f, -1.0f, 0.0f);
101 immVertex3f(pos, 1.0f, -1.0f, 0.0f);
102 immEnd();
103
104 GPU_offscreen_unbind(offscreen, false);
105 GPU_flush();
106
107 /* Read back data and perform some basic tests.
108 * Not performing detailed tests as there might be driver specific limitations. */
109 Vector<float4> read_data(Size * Size);
110 GPU_offscreen_read_color(offscreen, GPU_DATA_FLOAT, read_data.data());
111 int64_t color_num = 0;
112 int64_t color2_num = 0;
113 for (const float4 &read_color : read_data) {
114 if (read_color == color) {
115 color_num++;
116 }
117 else if (read_color == color2) {
118 color2_num++;
119 }
120 else {
121 EXPECT_TRUE(read_color == color || read_color == color2);
122 }
123 }
124 EXPECT_TRUE(color_num > 0);
125 EXPECT_TRUE(color2_num > 0);
126
127 GPU_offscreen_free(offscreen);
128
130}
131GPU_TEST(immediate_two_planes)
132
133} // namespace blender::gpu::tests
#define BLI_assert(a)
Definition BLI_assert.h:46
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
unsigned int uint
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, blender::gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_offscreen_free(GPUOffScreen *offscreen)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
void immEnd()
void immUnbindProgram()
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void immVertex3f(uint attr_id, float x, float y, float z)
GPUVertFormat * immVertexFormat()
void immUniformColor4fv(const float rgba[4])
void immBegin(GPUPrimType, uint vertex_len)
@ GPU_PRIM_TRI_STRIP
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_flush()
Definition gpu_state.cc:305
@ GPU_DATA_FLOAT
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
long long int int64_t
uint pos
#define GPU_TEST(test_name)
format
static void test_immediate_one_plane()
static constexpr int Size
static void test_immediate_two_planes()
VecBase< float, 4 > float4