-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add texcube sample * vertexpull example added * noninterleaved and quad examples added * shapes and bufferoffsets exampels added * instancing example added math module add `@nogc` & `nothrow` attributes * offscreen example added * some minor change - all examples modules have private content module - build-system detect by module name
- Loading branch information
Showing
28 changed files
with
2,709 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.{ | ||
.name = "sokol-d", | ||
.version = "0.1.6", | ||
.version = "0.1.7", | ||
.min_zig_version = "0.13.0", | ||
.paths = .{ | ||
"src", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//------------------------------------------------------------------------------ | ||
// bufferoffsets.d | ||
// | ||
// Render separate geometries in vertex- and index-buffers with | ||
// buffer offsets. | ||
//------------------------------------------------------------------------------ | ||
module examples.bufferoffsets; | ||
|
||
private: | ||
|
||
import sg = sokol.gfx; | ||
import app = sokol.app; | ||
import log = sokol.log; | ||
import sglue = sokol.glue; | ||
import shd = examples.shaders.bufferoffsets; | ||
|
||
extern (C): | ||
@safe: | ||
|
||
struct State | ||
{ | ||
sg.Pipeline pip; | ||
sg.Bindings bind; | ||
sg.PassAction passAction = {}; | ||
} | ||
|
||
struct Vertex | ||
{ | ||
float x = 0.0f, y = 0.0f; | ||
float r = 0.0f, g = 0.0f, b = 0.0f; | ||
} | ||
|
||
static State state; | ||
|
||
void init() | ||
{ | ||
sg.Desc gfxd = {environment: sglue.environment, | ||
logger: {func: &log.func}}; | ||
sg.setup(gfxd); | ||
|
||
state.passAction.colors[0].load_action = sg.LoadAction.Clear; | ||
state.passAction.colors[0].clear_value.r = 0.5; | ||
state.passAction.colors[0].clear_value.g = 0.5; | ||
state.passAction.colors[0].clear_value.b = 1.0; | ||
state.passAction.colors[0].clear_value.a = 1.0; | ||
|
||
Vertex[7] vertices = [ | ||
Vertex(0.0, 0.55, 1.0, 0.0, 0.0), | ||
Vertex(0.25, 0.05, 0.0, 1.0, 0.0), | ||
Vertex(-0.25, 0.05, 0.0, 0.0, 1.0), | ||
|
||
Vertex(-0.25, -0.05, 0.0, 0.0, 1.0), | ||
Vertex(0.25, -0.05, 0.0, 1.0, 0.0), | ||
Vertex(0.25, -0.55, 1.0, 0.0, 0.0), | ||
Vertex(-0.25, -0.55, 1.0, 1.0, 0.0), | ||
]; | ||
|
||
sg.BufferDesc vbufd = {data: {ptr: vertices.ptr, size: vertices.sizeof},}; | ||
state.bind.vertex_buffers[0] = sg.makeBuffer(vbufd); | ||
|
||
ushort[9] indices = [ | ||
0, 1, 2, | ||
0, 1, 2, | ||
0, 2, 3, | ||
]; | ||
|
||
// dfmt off | ||
sg.BufferDesc ibufd = { | ||
type: sg.BufferType.Indexbuffer, | ||
data: {ptr: indices.ptr, size: indices.sizeof}, | ||
}; | ||
state.bind.index_buffer = sg.makeBuffer(ibufd); | ||
|
||
sg.PipelineDesc pld = { | ||
layout: { | ||
attrs: [ | ||
shd.ATTR_BUFFEROFFSETS_POSITION: {format: sg.VertexFormat.Float2}, | ||
shd.ATTR_BUFFEROFFSETS_COLOR0: {format: sg.VertexFormat.Float3}, | ||
], | ||
}, | ||
shader: sg.makeShader(shd.bufferoffsetsShaderDesc(sg.queryBackend())), | ||
index_type: sg.IndexType.Uint16, | ||
}; | ||
// dfmt on | ||
state.pip = sg.makePipeline(pld); | ||
} | ||
|
||
void frame() | ||
{ | ||
sg.Pass pass = {action: state.passAction, swapchain: sglue.swapchain()}; | ||
sg.beginPass(pass); | ||
sg.applyPipeline(state.pip); | ||
|
||
// render the triangle | ||
state.bind.vertex_buffer_offsets[0] = 0; | ||
state.bind.index_buffer_offset = 0; | ||
sg.applyBindings(state.bind); | ||
sg.draw(0, 3, 1); | ||
|
||
// render the quad | ||
state.bind.vertex_buffer_offsets[0] = 3 * Vertex.sizeof; | ||
state.bind.index_buffer_offset = 3 * ushort.sizeof; | ||
sg.applyBindings(state.bind); | ||
sg.draw(0, 6, 1); | ||
|
||
sg.endPass(); | ||
sg.commit(); | ||
} | ||
|
||
void cleanup() | ||
{ | ||
sg.shutdown(); | ||
} | ||
|
||
// dfmt off | ||
void main() | ||
{ | ||
app.Desc runner = { | ||
window_title: "bufferoffsets.d", | ||
init_cb: &init, | ||
frame_cb: &frame, | ||
cleanup_cb: &cleanup, | ||
width: 800, | ||
height: 600, | ||
sample_count: 4, | ||
icon: {sokol_default: true}, | ||
logger: {func: &log.func} | ||
}; | ||
app.run(runner); | ||
} | ||
// dfmt on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.