void glSubImage(int level, Vector2i const &pos, Size const &size, GLPixelFormat const &glFormat, void const *data, CubeFace face = PositiveX) { if(data) glPixelStorei(GL_UNPACK_ALIGNMENT, glFormat.rowAlignment); glTexSubImage2D(isCube()? glFace(face) : texTarget, level, pos.x, pos.y, size.x, size.y, glFormat.format, glFormat.type, data); LIBGUI_ASSERT_GL_OK(); }
void glSubImage(int level, Rectanglei const &rect, Image const &image, CubeFace face = PositiveX) { auto const &glFormat = image.glFormat(); LIBGUI_GL.glPixelStorei(GL_UNPACK_ALIGNMENT, GLint(glFormat.rowAlignment)); LIBGUI_GL.glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.width())); int const bytesPerPixel = image.depth() / 8; LIBGUI_GL.glTexSubImage2D(isCube()? glFace(face) : texTarget, level, rect.left(), rect.top(), rect.width(), rect.height(), glFormat.format, glFormat.type, static_cast<dbyte const *>(image.bits()) + bytesPerPixel * rect.left() + image.stride() * rect.top()); LIBGUI_GL.glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); LIBGUI_ASSERT_GL_OK(); }
void glImage(int level, Size const &size, GLPixelFormat const &glFormat, void const *data, CubeFace face = PositiveX) { /// @todo GLES2: Check for the BGRA extension. // Choose suitable informal format. GLenum const internalFormat = (glFormat.format == GL_BGRA? GL_RGBA : glFormat.format == GL_DEPTH_STENCIL? GL_DEPTH24_STENCIL8 : glFormat.format); /*qDebug() << "glTexImage2D:" << name << (isCube()? glFace(face) : texTarget) << level << internalFormat << size.x << size.y << 0 << glFormat.format << glFormat.type << data;*/ if(data) glPixelStorei(GL_UNPACK_ALIGNMENT, glFormat.rowAlignment); glTexImage2D(isCube()? glFace(face) : texTarget, level, internalFormat, size.x, size.y, 0, glFormat.format, glFormat.type, data); LIBGUI_ASSERT_GL_OK(); }
void CObjectNode::RenderPatch(int nSeedU, int nSeedV, CMultiTexData* pTexData, int nTexData) { CObjectNode* pN1; CObjectNode* pN2; CObjectNode* pN3; CObjectNode* pN4; CNodeData aEdges[4][64]; CNodeData aHLine1[64]; CNodeData aHLine2[64]; CNodeData* pHLine1 = aHLine1; CNodeData* pHLine2 = aHLine2; CNodeData* pTmp; float fU, fV; int nV, nU, nTex; CNodeData cE1, cE2, cE3, cE4, cE; /* calculate edge 1 */ pN2 = pN1 = GetValidLeft(); pN1 = pN1->GetValidUp(); pN3 = pN2->GetValidDown(); pN4 = pN3->GetValidDown(); aEdges[0][0] = pN2->m_cNodeData; for (nV = 1; nV != nSeedV - 1; nV++) { fV = (float)nV / (float)(nSeedV - 1); SInterpolate(aEdges[0][nV], pN1, pN2, pN3, pN4, fV); } aEdges[0][nSeedV - 1] = pN3->m_cNodeData; /* calculate edge 2 */ pN1 = GetValidUp(); pN2 = this; pN3 = GetValidDown(); pN4 = pN3->GetValidDown(); aEdges[1][0] = pN2->m_cNodeData; for (nV = 1; nV != nSeedV - 1; nV++) { fV = (float)nV / (float)(nSeedV - 1); SInterpolate(aEdges[1][nV], pN1, pN2, pN3, pN4, fV); } aEdges[1][nSeedV - 1] = pN3->m_cNodeData; /* calculate edge 3 */ pN2 = pN1 = GetValidRight(); pN1 = pN1->GetValidUp(); pN3 = pN2->GetValidDown(); pN4 = pN3->GetValidDown(); aEdges[2][0] = pN2->m_cNodeData; for (nV = 1; nV != nSeedV - 1; nV++) { fV = (float)nV / (float)(nSeedV - 1); SInterpolate(aEdges[2][nV], pN1, pN2, pN3, pN4, fV); } aEdges[2][nSeedV - 1] = pN3->m_cNodeData; /* calculate edge 4 */ pN2 = pN2->GetValidRight(); pN1 = pN2->GetValidUp(); pN3 = pN2->GetValidDown(); pN4 = pN3->GetValidDown(); aEdges[3][0] = pN2->m_cNodeData; for (nV = 1; nV != nSeedV - 1; nV++) { fV = (float)nV / (float)(nSeedV - 1); SInterpolate(aEdges[3][nV], pN1, pN2, pN3, pN4, fV); } aEdges[3][nSeedV - 1] = pN3->m_cNodeData; /* make faces */ int nWrap; if (m_nWarapUV) nWrap = 1; else if (GetValidLeft()->m_nWarapUV) nWrap = -1; else nWrap = 0; /* if (nWrap == 0) pHLine1[0] = aEdges[1][0]; else if (nWrap > 0) { pHLine1[0] = aEdges[1][0]; pHLine1[0].m_cTexel.fU += 1.0f; } else { pHLine1[0] = aEdges[1][0]; } */ for (nU = 0; nU != nSeedU ; nU++) { fU = (float)nU/(float)(nSeedU - 1); SInterpolate(pHLine1[nU], aEdges[0][0], aEdges[1][0], aEdges[2][0], aEdges[3][0], fU, nWrap); } //pHLine1[nSeedU - 1] = aEdges[2][0]; for (nV = 1; nV != nSeedV; nV++) { //pHLine2[0] = aEdges[1][nV]; for (nU = 0; nU != nSeedU; nU++) { fU = (float)nU/(float)(nSeedU - 1); SInterpolate(pHLine2[nU], aEdges[0][nV], aEdges[1][nV], aEdges[2][nV], aEdges[3][nV], fU, nWrap); } //pHLine2[0] = aEdges[2][nV]; /* oki.. we've got here a strip, so render it */ #ifdef GL_VERSION_ES_CM_1_1 glClientActiveTexture(GL_TEXTURE0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); #endif for (nTex = 0; nTex != nTexData; nTex++) { if (pTexData[nTex].m_nGLTexName) { glBindTexture(GL_TEXTURE_2D, *pTexData[nTex].m_nGLTexName); #ifndef GL_VERSION_ES_CM_1_1 glBegin(GL_TRIANGLES); #endif if (pTexData[nTex].m_nMaterial & 1) { for (nU = 0; nU != nSeedU - 1; nU++) { glFace(pHLine1[nU], pHLine1[nU + 1], pHLine2[nU], pTexData[nTex].m_fAlpha, pTexData[nTex].m_fUShift, pTexData[nTex].m_fVShift); glFace(pHLine1[nU + 1], pHLine2[nU + 1], pHLine2[nU], pTexData[nTex].m_fAlpha, pTexData[nTex].m_fUShift, pTexData[nTex].m_fVShift); } } else if (pTexData[nTex].m_nMaterial & 2) { for (nU = 0; nU != nSeedU - 1; nU++) { glEnv(pHLine1[nU], pHLine1[nU + 1], pHLine2[nU], pTexData[nTex].m_fAlpha); glEnv(pHLine1[nU + 1], pHLine2[nU + 1], pHLine2[nU], pTexData[nTex].m_fAlpha); } } #ifndef GL_VERSION_ES_CM_1_1 glEnd(); #endif } } #ifdef GL_VERSION_ES_CM_1_1 glFaceFlush(); glEnvFlush(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif pTmp = pHLine1; pHLine1 = pHLine2; pHLine2 = pTmp; } }