//TODO: need refine!!! void ctLineBorders::Draw() { //if(!rectDotIndexes) return; //glDisable(GL_DEPTH_TEST); GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, meshVBO); if (posAtribLoc != -1) { GetOpenGLContext()->functions()->glVertexAttribPointer(posAtribLoc, 3, GL_FLOAT, GL_FALSE, (3 * sizeof(GLfloat)), (const GLvoid*)0); GetOpenGLContext()->functions()->glEnableVertexAttribArray(posAtribLoc); } else {qDebug()<<"isShit pos!!!";} m_currentShader->bind(); m_currentShader->setUniformValue(matrixUniform, GetProjectionMatrix().GetMatrix()); m_currentShader->setUniformValue(materialUniform, GetMaterial()->GetRGBA()); m_currentShader->setUniformValue(transformMatrixUniform, GetTransform()->GetGlobalTransformMatrix().GetMatrix()); glDrawElements(GL_LINE_LOOP, m_dots.count(), GL_UNSIGNED_SHORT, planeIndexes); GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, 0); m_currentShader->release(); }
void GLDriver::ShareOpenGLContext(HGLRC contextA, HGLRC contextB) { GLContext * aContext = GetOpenGLContext(contextA); GLContext * bContext = GetOpenGLContext(contextB); //If both contexts were retrieved, assign the context data if(aContext && bContext) { //Share the internal list data if(!aContext->ShareLists(bContext)) { LOGERR(("ShareOpenGLContext - Unable to share internal lists")); } //Flag to the plugin manager that the share has occured if(pluginManager) { pluginManager->OnGLContextShareLists(contextA,contextB); } } else { LOGERR(("ShareOpenGLContext - Unable to get internal contexts")); } }
bool GLDriver::CreateOpenGLContext(HGLRC rcHandle) { //Check the handle if(rcHandle == NULL) { LOGERR(("GLDriver::CreateOpenGLContext - Attempt to create a NULL context")); return false; } //Attempt to find an existing context if(GetOpenGLContext(rcHandle) != NULL) { LOGERR(("GLDriver::CreateOpenGLContext - Attempt to create an existing context %p",rcHandle)); return false; } //Create the new context GLContext *newContext = new GLContext(rcHandle,configData,this,functionTable); //Add the new context to the array glContextArray.push_back(newContext); //Flag the new context to the plugin manager if(pluginManager) { pluginManager->OnGLContextCreate(rcHandle); } return true; }
bool GLDriver::DeleteOpenGLContext(HGLRC rcHandle) { //Attempt to get the context GLContext *delContext = GetOpenGLContext(rcHandle); if(!delContext) { LOGERR(("GLDriver::DeleteOpenGLContext - Attempt to delete unknown context %p",rcHandle)); return false; } //Check if we are deleting the current context if(delContext == glContext) { LOGERR(("GLDriver::DeleteOpenGLContext - Deleting current context %p?",rcHandle)); //Do not perform correct shutdown (as the GL context is not valid) glContext = NULL; } //Remove it from the array for(uint i=0;i<glContextArray.size();i++) { //If the handles match, remove the context if(glContextArray[i]->GetRCHandle() == rcHandle) { glContextArray.erase(glContextArray.begin() + i); break; } } //Delete it delete delContext; //Flag the deleted context to the plugin manager if(pluginManager) { pluginManager->OnGLContextDelete(rcHandle); } return true; }
//TODO: need refine!!! void ctLineBorders::GenerateCompleteBuffer() { int posBuffersSize = 3 * m_dots.count(); float* planePositions = new float[posBuffersSize]; int tmp = 0; for(int i = 0; i < m_dots.count(); ++i) { planePositions[i + (2*i)] = m_dots[i].x(); planePositions[i + 1 + (2*i)] = m_dots[i].y(); planePositions[i + 2 + (2*i)] = m_dots[i].z(); //tmp+=2; } // planePositions[0] = t_AA.x(); // planePositions[1] = t_AA.y(); // planePositions[2] = t_AA.z(); // planePositions[3] = t_BB.x(); // planePositions[4] = t_AA.y(); // planePositions[5] = t_AA.z(); // planePositions[6] = t_BB.x(); // planePositions[7] = t_BB.y(); // planePositions[8] = t_BB.z(); // planePositions[9] = t_AA.x(); // planePositions[10] = t_BB.y(); // planePositions[11] = t_BB.z(); //SetupIndexes if(planeIndexes) delete[] planeIndexes; planeIndexes = new unsigned short[m_dots.count()]; for(int i = 0; i < m_dots.count(); ++i) { planeIndexes[i] = i; } // planeIndexes[0] = 2; // planeIndexes[1] = 1; // planeIndexes[2] = 0; // planeIndexes[3] = 3; // planeIndexes[4] = 2; // planeIndexes[5] = 0; //float* planeTextureCoords = new float[8]; //SetupTextureCoords(); //const int positionsOffset = 12; //const int texCoordOffset = 8; //float * completeBuffer = new float[positionsOffset + texCoordOffset]; // positions count + texture coord count // for(int i = 0; i < positionsOffset; ++i) // { // completeBuffer[i] = planePositions[i]; // } // for(int i = 0; i < texCoordOffset; ++i) // { // completeBuffer[positionsOffset + i] = planeTextureCoords[i]; // } if(meshVBO) GetOpenGLContext()->functions()->glDeleteBuffers(1, &meshVBO); GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, 0); GetOpenGLContext()->functions()->glGenBuffers(1, &meshVBO); GetOpenGLContext()->functions()->glBindBuffer(GL_ARRAY_BUFFER, meshVBO); GetOpenGLContext()->functions()->glBufferData(GL_ARRAY_BUFFER, (posBuffersSize) * sizeof(GLfloat), planePositions, GL_STATIC_DRAW); //delete[] completeBuffer; delete[] planePositions; }
bool GLDriver::SetOpenGLContext(HGLRC rcHandle) { //Check that existing contexts are shut down before enabling the new context. if(glContext && rcHandle) { LOGERR(("GLDriver::SetOpenGLContext - Context should only go from NULL->valid and valid->NULL")); } HGLRC oldContextHandle = NULL; //Shutdown existing context if(glContext) { //If attempting to have multiple rendering contexts active, flag an severe warning if(glContext->GetContextThreadID() != GetActiveThreadID()) { LOGERR(("*WARNING* - Multiple rendering contexts cannot be active at once with the current GLIntercept")); LOGERR(("*WARNING* - GLIntercept is not currently thread safe - crashes may occur")); } //Check when the state change occurs if(internalCallModeCount > 0 || glBeginEndState || glNewListState) { LOGERR(("GLDriver::SetOpenGLContext - Changing context in the middle of a glBegin/glNewList block?")); } //Disable logging glContext->SuspendLoggers(); //Get the render context handle for the old context oldContextHandle = glContext->GetRCHandle(); //Detach the context glContext->SetContextInActive(); glContext = NULL; } //Attempt to get the context if(rcHandle != NULL) { GLContext *newContext = GetOpenGLContext(rcHandle); if(!newContext) { LOGERR(("GLDriver::SetOpenGLContext - Attempt to set unknown context %p?",rcHandle)); return false; } //Assign the new context glContext = newContext; //Assign the thread ID glContext->SetContextActive(GetActiveThreadID()); //If logging is enabled, activate the loggers if(loggingEnabled) { glContext->ActivateLoggers(currLogDir); } } //Flag the changed context to the plugin manager if(pluginManager) { pluginManager->OnGLContextSet(oldContextHandle,rcHandle); } return true; }