Skip to content

Commit da73de4

Browse files
committed
Inline vrhi_defines.h into vrhi.h and update docs
1 parent 02132a2 commit da73de4

4 files changed

Lines changed: 713 additions & 581 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ endif()
137137
# -----------------------------------------------------------------------------
138138
set(VRHI_SOURCES
139139
vrhi.h
140-
vrhi_defines.h
141140
${GENERATED_HEADER}
142141
src/vrhi_internal.h
143142
src/vrhi_utils.h
@@ -251,13 +250,9 @@ add_custom_target(package_vrhi
251250
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/vrhi_$<CONFIG>/include"
252251
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/vrhi_$<CONFIG>/lib"
253252

254-
# Copy main VRHI headers
255253
COMMAND ${CMAKE_COMMAND} -E copy_if_different
256254
"${CMAKE_SOURCE_DIR}/vrhi.h"
257255
"${CMAKE_BINARY_DIR}/vrhi_$<CONFIG>/include/"
258-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
259-
"${CMAKE_SOURCE_DIR}/vrhi_defines.h"
260-
"${CMAKE_BINARY_DIR}/vrhi_$<CONFIG>/include/"
261256
COMMAND ${CMAKE_COMMAND} -E copy_if_different
262257
"${CMAKE_SOURCE_DIR}/src/vrhi_generated.h"
263258
"${CMAKE_BINARY_DIR}/vrhi_$<CONFIG>/include/"

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,85 @@ find_package(vrhi REQUIRED)
123123
target_link_libraries(your_app vrhi::vrhi)
124124
```
125125

126+
## Quick Start
127+
128+
### Initialisation
129+
130+
```cpp
131+
#include <vrhi.h>
132+
133+
g_vhInit.appName = "MyApp";
134+
g_vhInit.resolution = glm::ivec2( 1280, 720 );
135+
g_vhInit.headless = true; // No window, compute-only
136+
vhInit();
137+
```
138+
139+
### Draw a Triangle
140+
141+
```cpp
142+
// Create resources
143+
vhTexture rt = vhAllocTexture();
144+
vhCreateTexture2D( rt, glm::ivec2( 64, 64 ), 1, nvrhi::Format::RGBA8_UNORM, VRHI_TEXTURE_RT );
145+
146+
vhBuffer vb = vhAllocBuffer();
147+
vhMem* vertData = vhAllocMem( sizeof( verts ) );
148+
memcpy( vertData->data(), verts, sizeof( verts ) );
149+
vhCreateVertexBuffer( vb, "VB", vertData, "float3 float4" ); // pos + colour
150+
151+
vhShader vs = vhAllocShader(), ps = vhAllocShader();
152+
// ... compile shaders with vhCompileShader, then vhCreateShader
153+
154+
// Set state and draw
155+
vhState state;
156+
state.SetColourAttachment( 0, rt )
157+
.SetViewRect( glm::vec4( 0, 0, 64, 64 ) )
158+
.SetViewClear( VRHI_CLEAR_COLOR, glm::vec4( 0, 0, 0, 1 ) )
159+
.SetStateFlags( VRHI_STATE_WRITE_MASK )
160+
.SetVertexBuffer( vb, 0 )
161+
.SetProgram( vhCreateGfxProgram( vs, ps ) );
162+
163+
vhStateId sid = 1;
164+
vhSetState( sid, state );
165+
vhClear( sid, VRHI_CLEAR_COLOR );
166+
vhDraw( sid, 3 );
167+
vhFinish();
168+
169+
// Reusing state for another draw? Call DirtyAll():
170+
state.SetVertexBuffer( otherVB, 0 );
171+
vhSetState( sid, state.DirtyAll() );
172+
vhDraw( sid, 3 );
173+
```
174+
175+
### Compute Dispatch
176+
177+
```cpp
178+
vhShader cs = vhAllocShader();
179+
// ... compile with VRHI_SHADER_STAGE_COMPUTE
180+
181+
vhBuffer output = vhAllocBuffer();
182+
vhCreateStorageBuffer( output, "Out", nullptr, 1024, VRHI_BUFFER_COMPUTE_READ_WRITE );
183+
184+
vhState state;
185+
state.SetProgram( vhCreateComputeProgram( cs ) )
186+
.SetBuffer( 0, { .slot = 0, .buffer = output, .computeUAV = true } );
187+
188+
vhStateId sid = 100;
189+
vhSetState( sid, state );
190+
vhDispatch( sid, glm::uvec3( 16, 1, 1 ) );
191+
vhFinish();
192+
```
193+
194+
### Cleanup
195+
196+
```cpp
197+
vhDestroyBuffer( vb );
198+
vhDestroyTexture( rt );
199+
vhDestroyShader( vs );
200+
vhDestroyShader( ps );
201+
vhFlush();
202+
vhShutdown();
203+
```
204+
126205
## FAQ
127206
128207
### Is Vrhi written by AI?

0 commit comments

Comments
 (0)