NzString NzHashDigest::ToHex() const { if (m_digestLength == 0) return NzString(); unsigned int length = m_digestLength*2; char* hexOutput = new char[length+1]; for (unsigned int i = 0; i < m_digestLength; ++i) std::sprintf(hexOutput + i*2, "%02x", m_digest[i]); return NzString(new NzString::SharedString(1, length, length, hexOutput)); }
NzStringStream& NzStringStream::operator<<(unsigned char character) { m_strings.push_back(NzString(static_cast<char>(character))); m_bufferSize++; return *this; }
NzStringStream& NzStringStream::operator<<(char character) { m_strings.push_back(NzString(character)); m_bufferSize++; return *this; }
NzString NzMesh::GetMaterial(unsigned int index) const { #if NAZARA_UTILITY_SAFE if (!m_impl) { NazaraError("Mesh not created"); return NzString(); } if (index >= m_impl->materials.size()) { NazaraError("Material index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->materials.size()) + ')'); return NzString(); } #endif return m_impl->materials[index]; }
bool NzForwardRenderTechnique::Initialize() { try { NzErrorFlags flags(nzErrorFlag_ThrowException, true); s_quadIndexBuffer.Reset(false, s_maxQuads*6, nzDataStorage_Hardware, nzBufferUsage_Static); NzBufferMapper<NzIndexBuffer> mapper(s_quadIndexBuffer, nzBufferAccess_WriteOnly); nzUInt16* indices = static_cast<nzUInt16*>(mapper.GetPointer()); for (unsigned int i = 0; i < s_maxQuads; ++i) { *indices++ = i*4 + 0; *indices++ = i*4 + 2; *indices++ = i*4 + 1; *indices++ = i*4 + 2; *indices++ = i*4 + 3; *indices++ = i*4 + 1; } mapper.Unmap(); // Inutile de garder le buffer ouvert plus longtemps // Quad buffer (utilisé pour l'instancing de billboard et de sprites) //Note: Les UV sont calculés dans le shader s_quadVertexBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_XY), 4, nzDataStorage_Hardware, nzBufferUsage_Static); float vertices[2*4] = { -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, }; s_quadVertexBuffer.FillRaw(vertices, 0, sizeof(vertices)); // Déclaration lors du rendu des billboards par sommet s_billboardVertexDeclaration.EnableComponent(nzVertexComponent_Color, nzComponentType_Color, NzOffsetOf(BillboardPoint, color)); s_billboardVertexDeclaration.EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(BillboardPoint, position)); s_billboardVertexDeclaration.EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(BillboardPoint, uv)); s_billboardVertexDeclaration.EnableComponent(nzVertexComponent_Userdata0, nzComponentType_Float4, NzOffsetOf(BillboardPoint, size)); // Englobe sincos // Declaration utilisée lors du rendu des billboards par instancing // L'avantage ici est la copie directe (std::memcpy) des données de la RenderQueue vers le buffer GPU s_billboardInstanceDeclaration.EnableComponent(nzVertexComponent_InstanceData0, nzComponentType_Float3, NzOffsetOf(NzForwardRenderQueue::BillboardData, center)); s_billboardInstanceDeclaration.EnableComponent(nzVertexComponent_InstanceData1, nzComponentType_Float4, NzOffsetOf(NzForwardRenderQueue::BillboardData, size)); // Englobe sincos s_billboardInstanceDeclaration.EnableComponent(nzVertexComponent_InstanceData2, nzComponentType_Color, NzOffsetOf(NzForwardRenderQueue::BillboardData, color)); } catch (const std::exception& e) { NazaraError("Failed to initialise: " + NzString(e.what())); return false; } return true; }
NzString NzMesh::GetAnimation() const { #if NAZARA_UTILITY_SAFE if (!m_impl) { NazaraError("Mesh not created"); return NzString(); } #endif return m_impl->animationPath; }
NzString NzWindowImpl::GetTitle() const { unsigned int titleSize = GetWindowTextLengthW(m_handle); if (titleSize == 0) return NzString(); titleSize++; // Caractère nul std::unique_ptr<wchar_t[]> wTitle(new wchar_t[titleSize]); GetWindowTextW(m_handle, wTitle.get(), titleSize); return NzString::Unicode(wTitle.get()); }
NzString NzDirectory::GetResultPath() const { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE if (!m_impl) { NazaraError("Directory not opened"); return NzString(); } #endif return m_dirPath + NAZARA_DIRECTORY_SEPARATOR + m_impl->GetResultName(); }
NzString NzShaderStage::GetSource() const { #if NAZARA_RENDERER_SAFE if (!m_id) { NazaraError("Shader stage is not initialized"); return NzString(); } #endif NzString source; GLint length = 0; glGetShaderiv(m_id, GL_SHADER_SOURCE_LENGTH, &length); if (length > 1) // Le caractère de fin compte { source.Set(length - 1, '\0'); // La taille retournée est celle du buffer (Avec caractère de fin) glGetShaderSource(m_id, length, nullptr, &source[0]); } return source; }
NzString NzShader::GetSourceCode(nzShaderStage stage) const { if (!HasStage(stage)) return NzString(); NzContext::EnsureContext(); static const char sep[] = "\n////////////////////////////////////////////////////////////////////////////////\n\n"; unsigned int totalLength = 0; for (unsigned int shader : m_attachedShaders[stage]) { GLint length; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &length); totalLength += length - 1; } totalLength += (m_attachedShaders[stage].size()-1)*(sizeof(sep)/sizeof(char)); NzString source(totalLength, '\0'); unsigned int offset = 0; for (unsigned int shader : m_attachedShaders[stage]) { if (offset > 0) { std::memcpy(&source[offset], sep, sizeof(sep)/sizeof(char)); offset += sizeof(sep)/sizeof(char); } GLint length; glGetShaderSource(shader, totalLength, &length, &source[offset]); offset += length; } return source; }
NzString NzShaderStage::GetLog() const { #if NAZARA_RENDERER_SAFE if (!m_id) { NazaraError("Shader stage is not initialized"); return NzString(); } #endif NzString log; GLint length = 0; glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &length); if (length > 1) // Le caractère de fin faisant partie du compte { log.Set(length - 1, '\0'); // La taille retournée est celle du buffer (Avec caractère de fin) glGetShaderInfoLog(m_id, length, nullptr, &log[0]); } else log = "No log."; return log; }
NzString NzStream::GetDirectory() const { return NzString(); }
NzString NzStream::GetPath() const { return NzString(); }