Skip to content

Commit

Permalink
feat: add BSGraphics::Utility
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed May 26, 2024
1 parent 2887e34 commit 1b8f62b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CommonLibF4/include/RE/Bethesda/BSGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,12 @@ namespace RE
{
return ((desc >> 44) & a_flag) != 0;
}

void SetFlag(Vertex::Flags a_flag)
{
desc |= (static_cast<uint64_t>(a_flag) << 44);
}

void ClearFlag(Vertex::Flags a_flag)
{
desc &= ~(static_cast<uint64_t>(a_flag) << 44);
Expand All @@ -411,6 +413,7 @@ namespace RE
{
return (desc >> (4 * static_cast<uint8_t>(a_attribute) + 2)) & 0x3C;
}

void SetAttributeOffset(Vertex::Attribute a_attribute, std::uint32_t a_offset)
{
if (a_attribute != Vertex::Attribute::VA_POSITION) {
Expand All @@ -420,6 +423,7 @@ namespace RE
desc = lhs | rhs;
}
}

void ClearAttributeOffsets()
{
desc &= Vertex::Masks::DESC_MASK_OFFSET;
Expand All @@ -429,6 +433,7 @@ namespace RE
{
return static_cast<Vertex::Flags>((desc & Vertex::Masks::DESC_MASK_OFFSET) >> 44);
}

void SetFlags(Vertex::Flags a_flags)
{
desc |= (static_cast<uint64_t>(a_flags) << 44) | (desc & Vertex::Masks::DESC_MASK_FLAGS);
Expand All @@ -439,7 +444,6 @@ namespace RE
return (desc & 0xF) * 4;
}

private:
// members
std::uint64_t desc; // 00
};
Expand Down
60 changes: 60 additions & 0 deletions CommonLibF4/include/RE/Bethesda/BSGraphicsUtility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

namespace RE
{
class NiPoint2;
class NiPoint3;
class NiColorA;
}

namespace RE::BSGraphics::Utility
{
inline std::uint64_t PackVertexData(
std::uint32_t a_numVertices,
NiPoint3* a_positions,
NiPoint2* a_texCoords0,
NiColorA* a_texCoords1,
NiPoint3* a_normals,
NiPoint3* a_binormals,
NiPoint3* a_tangents,
NiColorA* a_colors,
NiColorA* a_skinBoneWeights,
std::uint8_t* a_skinBoneIndices,
NiColorA* a_landscapeData1,
NiColorA* a_landscapeData2,
float* a_eyeData,
void* a_buffer,
std::uint32_t* a_bufferSize,
std::uint16_t* a_vertexMap,
std::uint32_t a_dynamicFlags,
std::uint16_t* a_tangentXBuffer,
std::uint32_t a_tangentXBufferStride)
{
using func_t = decltype(&PackVertexData);
static REL::Relocation<func_t> func{ REL::ID(2277106) };
return func(a_numVertices, a_positions, a_texCoords0, a_texCoords1, a_normals, a_binormals, a_tangents, a_colors, a_skinBoneWeights, a_skinBoneIndices, a_landscapeData1, a_landscapeData2, a_eyeData, a_buffer, a_bufferSize, a_vertexMap, a_dynamicFlags, a_tangentXBuffer, a_tangentXBufferStride);

}

inline void UnpackVertexData(
const std::uint8_t* a_vertices,
const std::uint16_t a_index,
const std::uint64_t a_vertexDesc,
NiPoint3* a_position,
NiPoint2* a_texCoord0,
NiPoint2* a_texCoord1,
NiPoint3* a_normal,
NiPoint3* a_binormal,
NiPoint3* a_tangent,
NiColorA* a_color,
NiColorA* a_skinBoneWeights,
std::uint8_t* a_boneIndex0,
std::uint8_t* a_boneIndex1,
std::uint8_t* a_boneIndex2,
std::uint8_t* a_boneIndex3)
{
using func_t = decltype(&UnpackVertexData);
static REL::Relocation<func_t> func{ REL::ID(2277129) };
func(a_vertices, a_index, a_vertexDesc, a_position, a_texCoord0, a_texCoord1, a_normal, a_binormal, a_tangent, a_color, a_skinBoneWeights, a_boneIndex0, a_boneIndex1, a_boneIndex2, a_boneIndex3);
}
}
1 change: 1 addition & 0 deletions CommonLibF4/include/RE/Fallout.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "RE/Bethesda/BSFixedString.h"
#include "RE/Bethesda/BSGeometry.h"
#include "RE/Bethesda/BSGraphics.h"
#include "RE/Bethesda/BSGraphicsUtility.h"
#include "RE/Bethesda/BSHavok.h"
#include "RE/Bethesda/BSInputDeviceManager.h"
#include "RE/Bethesda/BSInputEventReceiver.h"
Expand Down

0 comments on commit 1b8f62b

Please sign in to comment.