bool OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderLines3D() { const auto gpuAPI = getGPUAPI(); const auto& internalState = getInternalState(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->useVAO(_vaoLine3D); // Activate program glUseProgram(_programLine3D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: glUniformMatrix4fv(_programLine3D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(internalState.mPerspectiveProjectionView)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_lines3D)) { const auto& line = primitive.first; const auto& color = primitive.second; // Set line color glUniform4f(_programLine3D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Iterate over pairs of points auto itV0 = line.cbegin(); auto itV1 = itV0 + 1; for(const auto itEnd = line.cend(); itV1 != itEnd; itV0 = itV1, ++itV1) { const auto& v0 = *itV0; const auto& v1 = *itV1; // Set line coordinates glUniform4f(_programLine3D.vs.param.v0, v0.x, v0.y, v0.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programLine3D.vs.param.v1, v1.x, v1.y, v1.z, 1.0f); GL_CHECK_RESULT; // Draw the line actually glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; gpuAPI->unuseVAO(); return true; }
bool OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderQuads3D() { const auto gpuAPI = getGPUAPI(); const auto& internalState = getInternalState(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->useVAO(_vaoQuad3D); // Activate program glUseProgram(_programQuad3D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: glUniformMatrix4fv(_programQuad3D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(internalState.mPerspectiveProjectionView)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_quads3D)) { const auto& p0 = std::get<0>(primitive); const auto& p1 = std::get<1>(primitive); const auto& p2 = std::get<2>(primitive); const auto& p3 = std::get<3>(primitive); const auto& color = std::get<4>(primitive); // Set quad color glUniform4f(_programQuad3D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Set points glUniform4f(_programQuad3D.vs.param.v0, p0.x, p0.y, p0.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v1, p1.x, p1.y, p1.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v2, p2.x, p2.y, p2.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v3, p3.x, p3.y, p3.z, 1.0f); GL_CHECK_RESULT; // Draw the quad actually glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; gpuAPI->unuseVAO(); return true; }
bool OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderRects2D() { const auto gpuAPI = getGPUAPI(); const auto& internalState = getInternalState(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->useVAO(_vaoRect2D); // Activate program glUseProgram(_programRect2D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: glUniformMatrix4fv(_programRect2D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(internalState.mOrthographicProjection)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_rects2D)) { const auto& rect = std::get<0>(primitive); const auto& color = std::get<1>(primitive); const auto& angle = std::get<2>(primitive); // Set rectangle coordinates const auto center = rect.center(); glUniform4f(_programRect2D.vs.param.rect, currentState.windowSize.y - center.y, center.x, rect.height(), rect.width()); GL_CHECK_RESULT; // Set rotation angle glUniform1f(_programRect2D.vs.param.angle, angle); GL_CHECK_RESULT; // Set rectangle color glUniform4f(_programRect2D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Draw the rectangle actually glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; gpuAPI->unuseVAO(); return true; }
/* * ======== IRESMAN_HDVICP_init ======== * Function to initialize the device specific resource manager implementation */ IRES_Status IRESMAN_HDVICP_init(IRESMAN_Params * initArgs) { IRESMAN_HdVicpParams * resmanArgs = (IRESMAN_HdVicpParams *)initArgs; Registry_Result result; if (!regInit) { /* * Enable logging. We only want to do this once, since there is * no Registry_removeModule(). */ result = Registry_addModule(&ti_sdo_fc_ires_hdvicp_desc, HDVICP_MODNAME); Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL); if (result == Registry_SUCCESS) { /* Set the diags mask to the FC default */ FCSettings_init(); FCSettings_setDiags(HDVICP_MODNAME); } regInit = 1; } Log_print1(Diags_ENTRY, "[+E] IRESMAN_HDVICP_init> Enter (initArgs=0x%x)", (IArg)initArgs); Assert_isTrue(initArgs != NULL, (Assert_Id)NULL); /* Check if already initialized */ if (_initialized) { Log_print0(Diags_EXIT, "[+X] IRESMAN_HDVICP_init> Exit (status=IRES_EEXISTS)"); return (IRES_EEXISTS); } /* * Information regarding the memory allocation/free functions * is stored as part of the internal state of the resource * manager */ allocFxn = resmanArgs->baseConfig.allocFxn; freeFxn = resmanArgs->baseConfig.freeFxn; #ifdef xdc_target__os_Linux if (gate == NULL) { OsalSupport_createGate(_HDVICP_ipcKeyBase); } if (gate == NULL) { Log_print0(Diags_USER7, "[+7] IRESMAN_VICP2_init> Failed to create gate"); Log_print0(Diags_EXIT, "[+X] IRESMAN_VICP2_init> Exit (status=IRES_EFAIL)"); return (IRES_EFAIL); } #endif getInternalState(); if ((NULL == _resmanInternalState) || (_resmanInternalState->sharedMemId == -1)) { Log_print0(Diags_USER7, "[+7] IRESMAN_VICP2_init> Failed to obtain Internal state " "Object"); Log_print0(Diags_EXIT, "[+X] IRESMAN_VICP2_init> Exit (status=IRES_EFAIL)"); return (IRES_EFAIL); } _resmanInternalState->numOpens++; if (sizeof(IRESMAN_Params) == resmanArgs->baseConfig.size) { _resmanInternalState->numResources = _HDVICP_NUMRESOURCES; } else { _resmanInternalState->numResources = resmanArgs->numResources; } Assert_isTrue( _resmanInternalState->numResources <= IRES_HDVICP_MAXRESOURCES, (Assert_Id)NULL); /* Set Initalized flag to 1 if successful */ _initialized = 1; Log_print0(Diags_EXIT, "[+X] IRESMAN_HDVICP_init> Exit (status=IRES_OK)"); return (IRES_OK); }
/* ARGSUSED - this line tells the compiler not to warn about unused args. */ IRES_Status IRESMAN_MEMTCM_init(IRESMAN_Params * initArgs) { SMGRMP_Attrs attrs; IRESMAN_MemTcmParams * resmanArgs = (IRESMAN_MemTcmParams *)initArgs; /* CMEM_AllocParams params; */ GT_assert(ti_sdo_fc_ires_memtcm, initArgs != NULL); /* * Check if already initialized */ if (_initialized) { GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EEXISTS)\n"); return (IRES_EEXISTS); } if (gtInit == 0) { GT_init(); GT_create(&CURTRACE, "ti.sdo.fc.ires.memtcm"); gtInit = 1; } GT_1trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Enter (initArgs=0x%x)\n", initArgs); /* * Information regarding the memory allocation/free functions * is stored as part of the internal state of the resource * manager */ if (NULL == _MEMTCM_lock) { /* Create a lock for protecting MEMTCM internal state object */ _MEMTCM_lock = LockMP_create(_MEMTCM_LOCKID); if (_MEMTCM_lock == NULL) { GT_1trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Failed to create IPC lock, " "key = 0x%x\n", _MEMTCM_LOCKID); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); return (IRES_EFAIL); } } getInternalState(); if (NULL == _resmanInternalState) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init>Failed to obtain Internal state Object\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } /* * Information regarding the memory allocation/free functions */ _allocFxn = resmanArgs->baseConfig.allocFxn; _freeFxn = resmanArgs->baseConfig.freeFxn; if (0 != CMEM_init()) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Could not initialize CMEM\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } /* TODO: Figure out how to populate the params */ if (_resmanInternalState->numOpens == 0) { armtcmAddr = CMEM_alloc2(MEMTCM_blockId, MEMTCM_size, NULL); _resmanInternalState->armtcmAddr = (void *)CMEM_getPhys(armtcmAddr); } else { armtcmAddr = CMEM_registerAlloc( (unsigned long)_resmanInternalState->armtcmAddr); } if (NULL == armtcmAddr) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Could not allocate TCM memory from CMEM" "\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } if (NULL == smgr) { attrs.numScratchGroups = MEMTCM_NUM_GROUPS; attrs.numResources = (MEMTCM_NUMRES); /* One resource corresponds to a 1/2 K chunk of memory (0x200), Manage memory in chunks of 0x200 */ attrs.lock = _MEMTCM_lock; attrs.key = (void *)_MEMTCM_MEMID; /* A key specific to the resource being managed */ /* This will create a new resource manager or return a process-specific handle to an existing smgr */ smgr = SMGRMP_create(&attrs); if (NULL == smgr) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Error creating" " scratch resource manager.\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } } _resmanInternalState->numOpens++; /* * Set Initalized flag to 1 if successful */ _initialized = 1; GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_OK)\n"); return (IRES_OK); }
/* * ======== RMAN_init ======== * Initialize the RMAN object with static information from the headers/ * configuration etc. This function has to return successfully before the * other APIs can be called */ IRES_Status RMAN_init() { Int i = 0; IRES_Status status; IRESMAN_Params nullParams; Registry_Result regResult; /* * Register the module name for logging only once. Do this before any * Log functions are called. */ if (regInit == 0) { regResult = Registry_addModule(&ti_sdo_fc_rman_desc, RMAN_MODNAME); Assert_isTrue(regResult == Registry_SUCCESS, (Assert_Id)NULL); /* Set diags mask to FC default */ FCSettings_init(); FCSettings_setDiags(RMAN_MODNAME); regInit = 1; } /* Ensure it is called/initialized at least once */ if (rmanInit++) { Log_print0(Diags_ENTRY, "[+E] RMAN_init> Enter"); Log_print0(Diags_EXIT, "[+X] RMAN_init> Exit (status=IRES_OK)"); /* TODO: Return IRES_OK even if RMAN_init() failed earlier? */ return (IRES_OK); } Log_print0(Diags_ENTRY, "[+E] RMAN_init> Enter"); if ((NULL == RMAN_PARAMS.allocFxn) || (NULL == RMAN_PARAMS.freeFxn)) { Log_print0(Diags_USER7, "[+7] RMAN_init> RMAN_PARAMS not " "configured with allocFxn and freeFxn functions"); initStatus = IRES_ENOMEM; } else { /* Set initStatus to IRES_OK so RMAN_register() can succeed. */ initStatus = IRES_OK; } if (initStatus == IRES_OK) { /* Create a lock for protecting RMAN_data object */ gate = OsalSupport_createGate(ti_sdo_fc_rman_RMAN_ipcKey); if (gate == NULL) { Log_print1(Diags_USER7, "[+7] RMAN_init> Failed to create IPC gate, key = 0x%x", ti_sdo_fc_rman_RMAN_ipcKey); initStatus = IRES_ENOMEM; } } if (initStatus == IRES_OK) { /* * Register the NULL resource. */ resTable.tableSize = RMAN_PARAMS.numRegistries; /* Initialize the registry table and the free index table */ for (i = 0; i < resTable.tableSize; i++) { RMAN_TABLE[i] = NULL; RMAN_FREE_ENTRIES[i] = 0; } resTable.tableIndex = 0; resTable.freeIndex = -1; /* First pre-register the NULL resource */ nullParams.allocFxn = RMAN_PARAMS.allocFxn; nullParams.freeFxn = RMAN_PARAMS.freeFxn; nullParams.size = sizeof(IRESMAN_Params); status = RMAN_register(&IRESMAN_NULLRES, &nullParams); if (status != IRES_OK) { Log_print1(Diags_USER7, "[+7] RMAN_init> Register failed " "on NULL IRESMAN implementation: %d", (IArg)status); initStatus = status; } } if (initStatus == IRES_OK) { /* * In this function, we can populate the RMAN_registryEntries, * RMAN_registeryResmanArgs and fix RMAN_numRegistryEntries */ initStatus = RMAN_autoRegister(); } /* * Static registration of Resource Registry entries */ if ((initStatus == IRES_OK) && (RMAN_registryEntries != NULL)) { Assert_isTrue(RMAN_numRegistryEntries < resTable.tableSize, (Assert_Id)NULL); Log_print0(Diags_USER2, "[+2] RMAN_init> Registering statically " "added resources"); /* * Copy the entries from the static configuration into the resource * table. */ for (i = 0; i < RMAN_numRegistryEntries; i++) { status = RMAN_register(RMAN_registryEntries[i], RMAN_registryResmanArgs[i]); if (status != IRES_OK) { Log_print2(Diags_USER7, "[+7] RMAN_init> Register failed on " "IRESMAN implementation 0x%x, status: %d", (IArg)(RMAN_registryEntries[i]), (IArg)status); initStatus = status; break; } } } getInternalState(); if (NULL == rmanInternalState) { initStatus = IRES_EFAIL; } Log_print1(Diags_EXIT, "[+X] RMAN_init> Exit (status=%d)", (IArg)initStatus); return (initStatus); }