add LoadImage wrapper in CKTexture
This commit is contained in:
parent
812f32bfca
commit
754a281655
|
@ -357,14 +357,14 @@ bool BM3dEntity_SetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, L
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BM3dEntity_GetVisivility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
bool BM3dEntity_GetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid) {
|
||||||
auto obj = CheckCK3dObject(bmfile, objid);
|
auto obj = CheckCK3dObject(bmfile, objid);
|
||||||
if (obj == nullptr) return false;
|
if (obj == nullptr) return false;
|
||||||
|
|
||||||
return obj->IsVisible();
|
return obj->IsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BM3dEntity_SetVisivility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, bool is_visible) {
|
bool BM3dEntity_SetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, bool is_visible) {
|
||||||
auto obj = CheckCK3dObject(bmfile, objid);
|
auto obj = CheckCK3dObject(bmfile, objid);
|
||||||
if (obj == nullptr) return false;
|
if (obj == nullptr) return false;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,14 @@ Design Note:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// some macro to help export function define.
|
||||||
|
|
||||||
|
#define BMPARAM_FILE_DECL BMap::BMFile* bmfile
|
||||||
|
#define BMPARAM_MESHTRANS_DECL BMap::BMMeshTransition* trans
|
||||||
|
#define BMPARAM_OBJECT_DECL BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid
|
||||||
|
#define BMPARAM_IN(_t, _name) _t _name
|
||||||
|
#define BMPARAM_OUT(_t, _name) _t* _name
|
||||||
|
|
||||||
#pragma region Init / Dispose
|
#pragma region Init / Dispose
|
||||||
|
|
||||||
LIBCMO_EXPORT void BMInit();
|
LIBCMO_EXPORT void BMInit();
|
||||||
|
@ -87,6 +95,13 @@ LIBCMO_EXPORT LibCmo::CK2::CK_ID BMGroup_GetObject(BMap::BMFile* bmfile, LibCmo:
|
||||||
|
|
||||||
#pragma region CKTexture
|
#pragma region CKTexture
|
||||||
|
|
||||||
|
LIBCMO_EXPORT bool BMTexture_PrepareSlotCount();
|
||||||
|
LIBCMO_EXPORT LibCmo::CKSTRING BMTexture_GetSlotFileName();
|
||||||
|
LIBCMO_EXPORT bool BMTexture_LoadImage(LibCmo::CKSTRING filename);
|
||||||
|
LIBCMO_EXPORT bool BMTexture_SaveImage(LibCmo::CKSTRING filename);
|
||||||
|
LIBCMO_EXPORT LibCmo::CK2::CK_TEXTURE_SAVEOPTIONS BMTexture_GetSaveOptions();
|
||||||
|
LIBCMO_EXPORT bool BMTexture_SetSaveOptions(LibCmo::CK2::CK_TEXTURE_SAVEOPTIONS saveopt);
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region CKMaterial
|
#pragma region CKMaterial
|
||||||
|
@ -114,7 +129,7 @@ LIBCMO_EXPORT CStyleVxMatrix BM3dEntity_GetWorldMatrix(BMap::BMFile* bmfile, Lib
|
||||||
LIBCMO_EXPORT bool BM3dEntity_SetWorldMatrix(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, CStyleVxMatrix mat);
|
LIBCMO_EXPORT bool BM3dEntity_SetWorldMatrix(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, CStyleVxMatrix mat);
|
||||||
LIBCMO_EXPORT LibCmo::CK2::CK_ID BM3dEntity_GetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid);
|
LIBCMO_EXPORT LibCmo::CK2::CK_ID BM3dEntity_GetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid);
|
||||||
LIBCMO_EXPORT bool BM3dEntity_SetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CK2::CK_ID meshid);
|
LIBCMO_EXPORT bool BM3dEntity_SetCurrentMesh(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, LibCmo::CK2::CK_ID meshid);
|
||||||
LIBCMO_EXPORT bool BM3dEntity_GetVisivility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid);
|
LIBCMO_EXPORT bool BM3dEntity_GetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid);
|
||||||
LIBCMO_EXPORT bool BM3dEntity_SetVisivility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, bool is_visible);
|
LIBCMO_EXPORT bool BM3dEntity_SetVisibility(BMap::BMFile* bmfile, LibCmo::CK2::CK_ID objid, bool is_visible);
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
|
@ -560,7 +560,10 @@ namespace LibCmo::CK2 {
|
||||||
// get extension of file. then get corresponding reader
|
// get extension of file. then get corresponding reader
|
||||||
XContainer::XString ext(filename);
|
XContainer::XString ext(filename);
|
||||||
m_Context->GetPathManager()->GetExtension(ext);
|
m_Context->GetPathManager()->GetExtension(ext);
|
||||||
auto reader = DataHandlers::CKBitmapHandler::GetBitmapHandlerWrapper(CKFileExtension(ext.c_str()), CKGUID());
|
auto reader = DataHandlers::CKBitmapHandler::GetBitmapHandlerWrapper(
|
||||||
|
CKFileExtension(ext.c_str()),
|
||||||
|
CKGUID()
|
||||||
|
);
|
||||||
if (reader == nullptr) return false;
|
if (reader == nullptr) return false;
|
||||||
|
|
||||||
// get desc and read data
|
// get desc and read data
|
||||||
|
@ -621,9 +624,9 @@ namespace LibCmo::CK2 {
|
||||||
|
|
||||||
CKSTRING CKBitmapData::GetSlotFileName(CKDWORD slot) const {
|
CKSTRING CKBitmapData::GetSlotFileName(CKDWORD slot) const {
|
||||||
if (slot >= m_Slots.size()) return nullptr;
|
if (slot >= m_Slots.size()) return nullptr;
|
||||||
// return nullptr if no corresponding filename
|
|
||||||
if (m_Slots[slot].m_FileName.empty()) return nullptr;
|
// return nullptr if corresponding filename is empty to indicate there is no binding filename
|
||||||
else return m_Slots[slot].m_FileName.c_str();
|
return XContainer::NSXString::ToCKSTRING(m_Slots[slot].m_FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CKDWORD CKBitmapData::GetWidth() const {
|
CKDWORD CKBitmapData::GetWidth() const {
|
||||||
|
|
|
@ -270,6 +270,8 @@ namespace LibCmo::CK2 {
|
||||||
|
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
|
|
||||||
|
// use c_str(), not XContainer::NSXString::ToCKSTRING because we want make sure this paramter is not nullptr.
|
||||||
|
// we always output a valid C style string, even if no chars need to write.
|
||||||
m_OutputCallback(result.c_str());
|
m_OutputCallback(result.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "CKTexture.hpp"
|
#include "CKTexture.hpp"
|
||||||
#include "../CKStateChunk.hpp"
|
#include "../CKStateChunk.hpp"
|
||||||
|
#include "../CKContext.hpp"
|
||||||
|
#include "../MgrImpls/CKPathManager.hpp"
|
||||||
|
|
||||||
namespace LibCmo::CK2::ObjImpls {
|
namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
|
@ -330,6 +332,24 @@ namespace LibCmo::CK2::ObjImpls {
|
||||||
return m_ImageHost;
|
return m_ImageHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CKTexture::LoadImage(CKSTRING filename, CKDWORD slot) {
|
||||||
|
// check file name
|
||||||
|
if (filename == nullptr) return false;
|
||||||
|
// check slot
|
||||||
|
if (slot >= m_ImageHost.GetSlotCount()) return false;
|
||||||
|
|
||||||
|
// resolve file name first
|
||||||
|
XContainer::XString filepath;
|
||||||
|
XContainer::NSXString::FromCKSTRING(filepath, filename);
|
||||||
|
if (!m_Context->GetPathManager()->ResolveFileName(filepath)) return false;
|
||||||
|
|
||||||
|
// try loading image
|
||||||
|
if (!m_ImageHost.LoadImage(XContainer::NSXString::ToCKSTRING(filepath), slot)) return false;
|
||||||
|
|
||||||
|
// sync file name
|
||||||
|
return m_ImageHost.SetSlotFileName(slot, XContainer::NSXString::ToCKSTRING(filepath));
|
||||||
|
}
|
||||||
|
|
||||||
bool CKTexture::IsUseMipmap() const {
|
bool CKTexture::IsUseMipmap() const {
|
||||||
return m_UseMipMap;
|
return m_UseMipMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,14 @@ namespace LibCmo::CK2::ObjImpls {
|
||||||
|
|
||||||
CKBitmapData& GetUnderlyingData();
|
CKBitmapData& GetUnderlyingData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A wrapper of underlying CKBitmapData::LoadImage. Not only load image, but also set file name.
|
||||||
|
* @param filename[in] File name of loading image.
|
||||||
|
* @param slot[in] The slot that image will be loaded into.
|
||||||
|
* @return True if success.
|
||||||
|
*/
|
||||||
|
bool LoadImage(CKSTRING filename, CKDWORD slot);
|
||||||
|
|
||||||
bool IsUseMipmap() const;
|
bool IsUseMipmap() const;
|
||||||
void UseMipmap(bool isUse);
|
void UseMipmap(bool isUse);
|
||||||
CKDWORD GetMipmapLevel() const;
|
CKDWORD GetMipmapLevel() const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user