static void sceneRender(void) { // Update the uniforms C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); // Draw the VBO C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); }
static void sceneRender(void) { // Update the uniforms C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, uLoc_projection, &projection); // Draw the VBO - GPU_GEOMETRY_PRIM allows the geoshader to control primitive emission C3D_DrawArrays(GPU_GEOMETRY_PRIM, 0, vertex_list_count); }
void ctrSetViewportSize(s16 w, s16 h, bool tilt) { C3D_SetViewport(0, 0, h, w); C3D_Mtx projectionMtx; if (tilt) { Mtx_OrthoTilt(&projectionMtx, 0.0, w, h, 0.0, 0.0, 1.0, true); } else { Mtx_Ortho(&projectionMtx, 0.0, w, 0.0, h, 0.0, 1.0, true); } C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, GSH_FVEC_projectionMtx, &projectionMtx); }
//--------------------------------------------------------------------------------- static void sceneRender(void) { //--------------------------------------------------------------------------------- int i; // Update the uniforms C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); for(i = 0; i < NUM_SPRITES; i++) { drawSprite( sprites[i].x >> 8, sprites[i].y >> 8, 32, 32, sprites[i].image); } }
void init_gpu_stuff() { // Load the vertex shader, create a shader program and bind it vshader_dvlb = DVLB_ParseFile((u32*) vshader_shbin, vshader_shbin_size); shaderProgramInit(&program); shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); C3D_BindProgram(&program); // Get the location of the uniforms proj_uloc = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); // Configure attributes for use with the vertex shader // Attribute format and element count are ignored in immediate mode C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); AttrInfo_Init(attrInfo); AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // v1=texcoord AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 4); // v2=color // Compute the projection matrix // Note: we're setting top to 240 here so origin is at top left. Mtx_OrthoTilt(&proj_mat, 0.0, 400.0, 240.0, 0.0, 0.0, 1.0, true); // Configure buffers C3D_BufInfo* bufInfo = C3D_GetBufInfo(); BufInfo_Init(bufInfo); // Load textures load_texture(&background_tex, background_png, background_png_size); load_texture(&empty_tex, empty_png, empty_png_size); load_texture(&frame_tex, frame_png, frame_png_size); load_texture(&text_tex, ui_font_png, ui_font_png_size); load_texture(&tileset_tex, tileset_png, tileset_png_size); load_texture(&outline_tex, outline_png, outline_png_size); // Configure the first fragment shading substage to just pass through the texture color // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight C3D_TexEnv* env = C3D_GetTexEnv(0); C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR); //C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, 0, 0); //C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); //C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); // Configure depth test to overwrite pixels with the same depth (needed to draw overlapping sprites) C3D_DepthTest(true, GPU_GEQUAL, GPU_WRITE_ALL); C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, proj_uloc, &proj_mat); }
void OSystem_3DS::updateScreen() { if (sleeping || exiting) return; // updateFocus(); C3D_FrameBegin(C3D_FRAME_SYNCDRAW); // Render top screen C3D_FrameDrawOn(_renderTargetTop); if (config.screen == kScreenTop || config.screen == kScreenBoth) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _projectionLocation, &_projectionTop); C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _gameTopTexture.getMatrix()); _gameTopTexture.render(); _gameTopTexture.render(); if (_overlayVisible && config.screen == kScreenTop) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _overlay.getMatrix()); _overlay.render(); } if (_cursorVisible && config.showCursor && config.screen == kScreenTop) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _cursorTexture.getMatrix()); _cursorTexture.render(); } } // Render bottom screen C3D_FrameDrawOn(_renderTargetBottom); if (config.screen == kScreenBottom || config.screen == kScreenBoth) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _projectionLocation, &_projectionBottom); C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _gameBottomTexture.getMatrix()); _gameTopTexture.render(); _gameTopTexture.render(); if (_overlayVisible) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _overlay.getMatrix()); _overlay.render(); } if (_cursorVisible && config.showCursor) { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, _modelviewLocation, _cursorTexture.getMatrix()); _cursorTexture.render(); } } C3D_FrameEnd(0); }
void initialize(void) { // Load the vertex shader, create a shader program and bind it vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); shaderProgramInit(&program); shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); C3D_BindProgram(&program); // Get the location of the uniforms uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); // Compute the projection matrix Mtx_OrthoTilt(&projection, -200.0, 200.0, -120.0, 120.0, 0.0, 1.0); // Update the uniforms C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); // Create the VBO (vertex buffer object) vbo_data = linearAlloc(sizeof(vertices)); memcpy(vbo_data, vertices, sizeof(vertices)); // Configure buffers C3D_BufInfo* bufInfo = C3D_GetBufInfo(); BufInfo_Init(bufInfo); BufInfo_Add(bufInfo, vbo_data, sizeof(vertices[0]), 2, 0x10); // Configure attributes for use with the vertex shader C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); AttrInfo_Init(attrInfo); AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 2); // v0=x,y AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=r,g,b // Configure the first fragment shading substage to just pass through the vertex color // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight C3D_TexEnv* env = C3D_GetTexEnv(0); C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); }
void gfxDrawScreen() { int screenTexSize = 256; u32* transferBuffer = screenBuffer; GPU_TEXTURE_FILTER_PARAM filter = GPU_NEAREST; if(scaleMode != 0 && scaleFilter != 0) { filter = GPU_LINEAR; if(scaleFilter == 2) { screenTexSize = 512; transferBuffer = scale2xBuffer; gfxScale2xRGBA8888(screenBuffer, 256, scale2xBuffer, 512, 256, 224); } } if(!screenInit || screenTexture.width != screenTexSize || screenTexture.height != screenTexSize) { if(screenInit) { C3D_TexDelete(&screenTexture); screenInit = false; } screenInit = C3D_TexInit(&screenTexture, screenTexSize, screenTexSize, GPU_RGBA8); } C3D_TexSetFilter(&screenTexture, filter, filter); GSPGPU_FlushDataCache(transferBuffer, screenTexSize * screenTexSize * sizeof(u32)); if(R_SUCCEEDED(GX_DisplayTransfer(transferBuffer, (u32) GX_BUFFER_DIM(screenTexSize, screenTexSize), (u32*) screenTexture.data, (u32) GX_BUFFER_DIM(screenTexSize, screenTexSize), GX_TRANSFER_FLIP_VERT(1) | GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)))) { gspWaitForPPF(); } GSPGPU_InvalidateDataCache(screenTexture.data, screenTexture.size); if(!C3D_FrameBegin(0)) { return; } C3D_RenderTarget* target = gameScreen == 0 ? targetTop : targetBottom; C3D_FrameDrawOn(target); C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, shaderInstanceGetUniformLocation(program.vertexShader, "projection"), gameScreen == 0 ? &projectionTop : &projectionBottom); u16 viewportWidth = target->renderBuf.colorBuf.height; u16 viewportHeight = target->renderBuf.colorBuf.width; // Draw the screen. if(screenInit) { // Calculate the VBO dimensions. int screenWidth = 256; int screenHeight = 224; if(scaleMode == 1) { screenWidth *= 1.25f; screenHeight *= 1.25f; } else if(scaleMode == 2) { screenWidth *= 1.50f; screenHeight *= 1.50f; } else if(scaleMode == 3) { screenWidth *= viewportHeight / (float) screenHeight; screenHeight = viewportHeight; } else if(scaleMode == 4) { screenWidth = viewportWidth; screenHeight = viewportHeight; } // Calculate VBO points. const float x1 = ((int) viewportWidth - screenWidth) / 2.0f; const float y1 = ((int) viewportHeight - screenHeight) / 2.0f; const float x2 = x1 + screenWidth; const float y2 = y1 + screenHeight; static const float baseTX2 = 256.0f / 256.0f; static const float baseTY2 = 224.0f / 256.0f; static const float baseFilterMod = 0.25f / 256.0f; float tx2 = baseTX2; float ty2 = baseTY2; if(scaleMode != 0 && scaleFilter == 1) { tx2 -= baseFilterMod; ty2 -= baseFilterMod; } C3D_TexBind(0, &screenTexture); C3D_ImmDrawBegin(GPU_TRIANGLES); C3D_ImmSendAttrib(x1, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(0, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, ty2, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x1, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(0, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x1, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(0, ty2, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, ty2, 0.0f, 0.0f); C3D_ImmDrawEnd(); } // Draw the border. if(borderInit && scaleMode != 4) { // Calculate VBO points. int scaledBorderWidth = borderWidth; int scaledBorderHeight = borderHeight; if(borderScaleMode == 1) { if(scaleMode == 1) { scaledBorderWidth *= 1.25f; scaledBorderHeight *= 1.25f; } else if(scaleMode == 2) { scaledBorderWidth *= 1.50f; scaledBorderHeight *= 1.50f; } else if(scaleMode == 3) { scaledBorderWidth *= viewportHeight / 224.0f; scaledBorderHeight *= viewportHeight / 224.0f; } else if(scaleMode == 4) { scaledBorderWidth *= viewportWidth / 256.0f; scaledBorderHeight *= viewportHeight / 224.0f; } } const float x1 = ((int) viewportWidth - scaledBorderWidth) / 2.0f; const float y1 = ((int) viewportHeight - scaledBorderHeight) / 2.0f; const float x2 = x1 + scaledBorderWidth; const float y2 = y1 + scaledBorderHeight; float tx2 = (float) borderWidth / (float) gpuBorderWidth; float ty2 = (float) borderHeight / (float) gpuBorderHeight; C3D_TexBind(0, &borderTexture); C3D_ImmDrawBegin(GPU_TRIANGLES); C3D_ImmSendAttrib(x1, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(0, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, ty2, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x1, y1, 0.5f, 0.0f); C3D_ImmSendAttrib(0, 0, 0.0f, 0.0f); C3D_ImmSendAttrib(x1, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(0, ty2, 0.0f, 0.0f); C3D_ImmSendAttrib(x2, y2, 0.5f, 0.0f); C3D_ImmSendAttrib(tx2, ty2, 0.0f, 0.0f); C3D_ImmDrawEnd(); } C3D_FrameEnd(0); }
void TextEngine::Update() { C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); textVtxArrayPos = 0; }