/*!**************************************************************************** @Function DrawSceneWithShadow @Input viewMat The view matrix to use for rendering @Description Draws the scene with the shadow ******************************************************************************/ void OGLES2ShadowMapping::DrawSceneWithShadow(PVRTMat4 viewMat) { for (unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i) { if(i == 1) continue; SPODNode& Node = m_Scene.pNode[i]; PVRTMat4 mWorld, mModelView; m_Scene.GetWorldMatrix(mWorld, Node); PVRTMatrixMultiply(mModelView, mWorld, viewMat); glUniformMatrix4fv(m_ShadowShaderProgram.uiModelViewMatrixLoc, 1, GL_FALSE, mModelView.f); // Calculate the light direction for the diffuse lighting PVRTVec4 vLightDir; PVRTTransformBack(&vLightDir, &m_vLightDirection, &mWorld); PVRTVec3 vLightDirModel = *(PVRTVec3*)&vLightDir; PVRTMatrixVec3Normalize(vLightDirModel, vLightDirModel); glUniform3fv(m_ShadowShaderProgram.uiLightDirLoc, 1, &vLightDirModel.x); // Load the correct texture using our texture lookup table GLuint uiTex = 0; if (Node.nIdxMaterial != -1) uiTex = m_puiTextureIDs[Node.nIdxMaterial]; glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, uiTex); DrawMesh(i); } }
/*!**************************************************************************** @Function DrawScene @Input viewMat The view matrix to use for rendering @Description Draws the scene ******************************************************************************/ void OGLES2ShadowMapping::DrawScene(PVRTMat4 viewMat) { for (unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i) { if(i == 1) continue; SPODNode& Node = m_Scene.pNode[i]; PVRTMat4 mWorld, mModelView; m_Scene.GetWorldMatrix(mWorld, Node); PVRTMatrixMultiply(mModelView, mWorld, viewMat); glUniformMatrix4fv(m_SimpleShaderProgram.uiModelViewMatrixLoc, 1, GL_FALSE, mModelView.f); DrawMesh(i); } }
void RudeSkinnedMesh::Render() { RUDE_PERF_START(kPerfRudeSkinMeshRender); //int numbonemats; //glGetIntegerv(GL_MAX_PALETTE_MATRICES_OES, &numbonemats); //printf("bonemats %d\n", numbonemats); glMatrixMode(GL_MODELVIEW); PVRTMATRIX viewmat; glGetFloatv(GL_MODELVIEW_MATRIX, viewmat.f); RGL.Enable(kBackfaceCull, true); glCullFace(GL_FRONT); glFrontFace(GL_CW); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); RGL.EnableClient(kVertexArray, true); RGL.EnableClient(kTextureCoordArray, true); //glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); if(m_animate) { glEnable(GL_MATRIX_PALETTE_OES); glEnableClientState(GL_MATRIX_INDEX_ARRAY_OES); glEnableClientState(GL_WEIGHT_ARRAY_OES); } //glScalef(m_scale.x(), m_scale.y(), m_scale.z()); for(int i = 0; i < m_model.nNumNode; i++) { SPODNode *node = &m_model.pNode[i]; if(!node->pszName) continue; if(node->pszName[0] != 'M') continue; SPODMaterial *material = &m_model.pMaterial[node->nIdxMaterial]; SPODMesh *mesh = &m_model.pMesh[node->nIdx]; if(m_animate) { glMatrixIndexPointerOES(mesh->sBoneIdx.n, GL_UNSIGNED_BYTE, mesh->sBoneIdx.nStride, mesh->pInterleaved + (long) mesh->sBoneIdx.pData); glWeightPointerOES(mesh->sBoneWeight.n, GL_FLOAT, mesh->sBoneWeight.nStride, mesh->pInterleaved + (long) mesh->sBoneWeight.pData); } int textureid = material->nIdxTexDiffuse; if(textureid >= 0) RudeTextureManager::GetInstance()->SetTexture(m_textures[textureid]); unsigned short *indices = (unsigned short*) mesh->sFaces.pData; glVertexPointer(3, GL_FLOAT, mesh->sVertex.nStride, mesh->pInterleaved + (long)mesh->sVertex.pData); glTexCoordPointer(2, GL_FLOAT, mesh->psUVW->nStride, mesh->pInterleaved + (long)mesh->psUVW->pData); if((mesh->sVtxColours.n > 0) && (mesh->sVtxColours.eType == EPODDataRGBA)) { RGL.EnableClient(kColorArray, true); glColorPointer(4, GL_UNSIGNED_BYTE, mesh->sVtxColours.nStride, mesh->pInterleaved + (long)mesh->sVtxColours.pData); } else RGL.EnableClient(kColorArray, false); int totalbatchcnt = 0; for(int b = 0; b < mesh->sBoneBatches.nBatchCnt; b++) { int batchcnt = mesh->sBoneBatches.pnBatchBoneCnt[b]; if(m_animate) { glMatrixMode(GL_MATRIX_PALETTE_OES); for(int j = 0; j < batchcnt; ++j) { glCurrentPaletteMatrixOES(j); // Generates the world matrix for the given bone in this batch. PVRTMATRIX mBoneWorld; int i32NodeID = mesh->sBoneBatches.pnBatches[j + totalbatchcnt]; m_model.GetBoneWorldMatrix(mBoneWorld, *node, m_model.pNode[i32NodeID]); // Multiply the bone's world matrix by the view matrix to put it in view space PVRTMatrixMultiply(mBoneWorld, mBoneWorld, viewmat); // Load the bone matrix into the current palette matrix. glLoadMatrixf(mBoneWorld.f); } } totalbatchcnt += batchcnt; int offset = mesh->sBoneBatches.pnBatchOffset[b] * 3; int end = mesh->sBoneBatches.pnBatchOffset[b+1] * 3; if(b == (mesh->sBoneBatches.nBatchCnt - 1)) end = mesh->nNumFaces*3; int numidx = (end - offset); glDrawElements(GL_TRIANGLES, numidx, GL_UNSIGNED_SHORT, &indices[offset]); } } glDisable(GL_MATRIX_PALETTE_OES); glDisableClientState(GL_MATRIX_INDEX_ARRAY_OES); glDisableClientState(GL_WEIGHT_ARRAY_OES); RUDE_PERF_STOP(kPerfRudeSkinMeshRender); }
/*!*************************************************************************** @Function APIDrawLogo @Description *****************************************************************************/ void CPVRTPrint3D::APIDrawLogo(const EPVRTPrint3DLogo uLogoToDisplay, const int ePos) { GLuint tex = 0; float fScale = 1.0f; if(m_ui32ScreenDim[1] >= 720) fScale = 2.0f; SPVRTPrint3DAPI::SInstanceData& Data = (m_pAPI->m_pInstanceData ? *m_pAPI->m_pInstanceData : SPVRTPrint3DAPI::s_InstanceData); switch(uLogoToDisplay) { case ePVRTPrint3DLogoIMG: tex = Data.uTextureIMGLogo; break; case ePVRTPrint3DLogoPowerVR: tex = Data.uTexturePowerVRLogo; break; default: return; // Logo not recognised } const float fLogoXSizeHalf = (128.0f / m_ui32ScreenDim[0]); const float fLogoYSizeHalf = (64.0f / m_ui32ScreenDim[1]); const float fLogoXShift = 0.035f / fScale; const float fLogoYShift = 0.035f / fScale; const float fLogoSizeXHalfShifted = fLogoXSizeHalf + fLogoXShift; const float fLogoSizeYHalfShifted = fLogoYSizeHalf + fLogoYShift; static float Vertices[] = { -fLogoXSizeHalf, fLogoYSizeHalf , 0.5f, -fLogoXSizeHalf, -fLogoYSizeHalf, 0.5f, fLogoXSizeHalf , fLogoYSizeHalf , 0.5f, fLogoXSizeHalf , -fLogoYSizeHalf, 0.5f }; static float UVs[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; float *pVertices = ( (float*)&Vertices ); float *pUV = ( (float*)&UVs ); // Matrices PVRTMATRIX matModelView; PVRTMATRIX matTransform; PVRTMatrixIdentity(matModelView); PVRTMatrixScaling(matTransform, f2vt(fScale), f2vt(fScale), f2vt(1.0f)); PVRTMatrixMultiply(matModelView, matModelView, matTransform); int nXPos = (ePos & eLeft) ? -1 : 1; int nYPos = (ePos & eTop) ? 1 : -1; PVRTMatrixTranslation(matTransform, nXPos - (fLogoSizeXHalfShifted * fScale * nXPos), nYPos - (fLogoSizeYHalfShifted * fScale * nYPos), 0.0f); PVRTMatrixMultiply(matModelView, matModelView, matTransform); if(m_bRotate) { PVRTMatrixRotationZ(matTransform, -90.0f*PVRT_PI/180.0f); PVRTMatrixMultiply(matModelView, matModelView, matTransform); } _ASSERT(Data.uProgramLogo != UNDEFINED_HANDLE); glUseProgram(Data.uProgramLogo); // Bind the model-view-projection to the shader glUniformMatrix4fv(Data.mvpLocationLogo, 1, GL_FALSE, matModelView.f); // Render states glActiveTexture(GL_TEXTURE0); _ASSERT(tex != UNDEFINED_HANDLE); glBindTexture(GL_TEXTURE_2D, tex); // Vertices glEnableVertexAttribArray(VERTEX_ARRAY); glEnableVertexAttribArray(UV_ARRAY); glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, (const void*)pVertices); glVertexAttribPointer(UV_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, (const void*)pUV); glDrawArrays(GL_TRIANGLE_STRIP,0,4); glDisableVertexAttribArray(VERTEX_ARRAY); glDisableVertexAttribArray(UV_ARRAY); }