MCPcopy Create free account
hub / github.com/DavidColson/Polybox / GraphicsInit

Function GraphicsInit

source/graphics.cpp:219–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217// ***********************************************************************
218
219void GraphicsInit(SDL_Window* pWindow, i32 winWidth, i32 winHeight) {
220 Arena* pArena = ArenaCreate();
221 pRenderState = New(pArena, RenderState);
222 pRenderState->pArena = pArena;
223
224 pRenderState->vertexState.pArena = pArena;
225 pRenderState->drawList3D.pArena = pArena;
226 pRenderState->drawList2D.pArena = pArena;
227 pRenderState->perFrameVertexBuffer.pArena = pArena;
228 pRenderState->perFrameIndexBuffer.pArena = pArena;
229
230 pRenderState->targetResolution = Vec2f(320.0f, 240.0f);
231
232 // init_backend stuff
233 GraphicsBackendInit(pWindow, winWidth, winHeight);
234 sg_desc desc = {
235 .environment = SokolGetEnvironment()
236 };
237 sg_setup(&desc);
238
239 // Create white texture for non textured draws
240 {
241 u32 pixels[4];
242 memset(pixels, 0xFF, sizeof(pixels));
243
244 sg_image_desc imageDesc = {
245 .type = SG_IMAGETYPE_2D,
246 .width = 2,
247 .height = 2,
248 .pixel_format = SG_PIXELFORMAT_RGBA8,
249 .label = "white"
250 };
251
252 imageDesc.data.subimage[0][0].ptr = (void*)pixels;
253 imageDesc.data.subimage[0][0].size = sizeof(pixels);
254 pRenderState->whiteTexture = sg_make_image(&imageDesc);
255 }
256
257 // Compositor Pipeline
258 {
259 sg_pipeline_desc pipelineDesc = {
260 .shader = sg_make_shader(compositor_shader_desc(SG_BACKEND_D3D11)),
261 .layout = {
262 .buffers = { {.stride = sizeof(VertexData) } },
263 .attrs = {
264 { .offset = offsetof(VertexData, pos), .format = SG_VERTEXFORMAT_FLOAT3 },
265 { .offset = offsetof(VertexData, col), .format = SG_VERTEXFORMAT_FLOAT4 },
266 { .offset = offsetof(VertexData, tex), .format = SG_VERTEXFORMAT_FLOAT2 },
267 { .offset = offsetof(VertexData, norm), .format = SG_VERTEXFORMAT_FLOAT3 }
268 }
269 },
270 .depth = {
271 .compare = SG_COMPAREFUNC_LESS_EQUAL,
272 .write_enabled = true,
273 },
274 .colors = {
275 {
276 .write_mask = SG_COLORMASK_RGB,

Callers 1

mainFunction · 0.85

Calls 6

GraphicsBackendInitFunction · 0.85
SokolGetEnvironmentFunction · 0.85
compositor_shader_descFunction · 0.85
CreateFullScreenQuadFunction · 0.85
SokolGetSwapchainFunction · 0.85
IdentityFunction · 0.85

Tested by

no test coverage detected