static Serializer* GetSerializerForStream(const Stream& stream) { const String& ext = PathGetFileExtension(stream.path); if(ext == "json") return SerializerCreateJSON(AllocatorGetHeap(), 0); else if(ext == "bin") return SerializerCreateBinary(AllocatorGetHeap(), 0); return SerializerCreateJSON(AllocatorGetHeap(), 0); }
void Particles::createGeometry() { gb = AllocateThis(GeometryBuffer); gb->setBufferAccess(BufferAccess::Write); gb->setBufferUsage(BufferUsage::Dynamic); material = MaterialCreate(AllocatorGetHeap(), "ParticlesMaterial"); Material* pMaterial = material.Resolve(); pMaterial->setDepthWrite(false); pMaterial->setBlending(BlendSource::SourceAlpha, BlendDestination::One); pMaterial->setShader("Tex"); RenderBatchPtr renderable = AllocateHeap(RenderBatch); renderable->setPrimitiveType(PrimitiveType::Points); renderable->setGeometryBuffer(gb); renderable->setMaterial(material); renderable->setRenderLayer(RenderLayer::Transparency); renderable->onPreRender.Bind( this, &Particles::onPreRender ); renderable->onPostRender.Bind( this, &Particles::onPostRender ); addRenderable(renderable); particles.resize(MAX_PARTICLES); }
TextureAtlas::TextureAtlas(uint maxSize, PixelFormat pixelFormat) { atlasMaxSize = maxSize; atlasSize = std::min(maxSize, DefaultSize); rectanglePacker.Init(atlasSize,atlasSize); atlasImageHandle = ImageCreate(AllocatorGetHeap(),atlasSize,atlasSize,pixelFormat); }
Gizmo::Gizmo( const EntityPtr& node, const CameraWeakPtr& camera ) : nodeObject( node ) , weakCamera( camera ) , selectedAxis( GizmoAxis::None ) { assert( node != nullptr ); // Disable the depth testing so the gizmo can be seen behind objects. material = MaterialCreate(AllocatorGetHeap(), "GizmoMaterial"); material.Resolve()->setDepthRange(Vector2(0.0f, 0.1f)); }
// -- Init / Shutdown -- void WorkerThread::Make(WorkerThreadPool * pool, uint32 threadIndex) { //BOOST_LOG( gn_log::get() ) << "(Concurrent) \tWorker[ " << threadIndex << " ] starting up...\n"; LogInfo("WorkerThread[%i] starting up...", threadIndex); Index_ = threadIndex; Pool_ = pool; TaskMutex_.reset( MutexCreate(AllocatorGetHeap()) ); Tasks_.reserve(TaskCapacity); // some random number of tasks if(Index_ != 0) // so long as we're not the main thread... { //Thread_ = boost::thread( boost::bind( &Worker::Run, this ) ); // create the boost::thread to run our shit ThreadFunction runFn = MakeDelegate(this, &WorkerThread::Run); Thread_.reset( ThreadCreate(AllocatorGetHeap()) ); ThreadStart(Thread_, runFn, nullptr); } // TODO: Fix this. else // Set this here, as the Run() function, which sets it otherwise, won't get called. LocalWorkerThread_ = this; //ThisThread_.reset( (const_cast<Worker *>(this)) ); }
EntityPtr SelectionPlugin::createRectangle() { Overlay* overlay = AllocateThis(Overlay); overlay->setPositionMode( PositionMode::Absolute ); overlay->setOpacity(0.3f); overlay->setBorderWidth(1); overlay->setBorderColor( Color::White ); overlay->setBackgroundColor( Color::White ); Entity* dragRectangle = EntityCreate( AllocatorGetHeap() ); dragRectangle->addTransform(); dragRectangle->addComponent(overlay); return dragRectangle; }
NAMESPACE_CORE_BEGIN void HashBase::AllocateBuckets(unsigned size, unsigned numBuckets) { if (this->ptrs) Deallocate(this->ptrs); HashNodeBase** ptrs = static_cast<HashNodeBase**>(AllocatorAllocate(AllocatorGetHeap(), (numBuckets + 2)*sizeof(HashNodeBase*), 0)); unsigned* data = reinterpret_cast<unsigned*>(ptrs); data[0] = size; data[1] = numBuckets; this->ptrs = ptrs; ResetPtrs(); }
RenderBatchPtr Model::createDebugRenderable() const { MaterialHandle handleMaterial = MaterialCreate(AllocatorGetHeap(), "SkeletonDebug"); Material* material = handleMaterial.Resolve(); material->setDepthTest(false); GeometryBuffer* gb = AllocateHeap(GeometryBuffer); RenderBatch* renderable = AllocateHeap(Renderable); renderable->setPrimitiveType(PrimitiveType::Lines); renderable->setGeometryBuffer(gb); renderable->setMaterial(handleMaterial); return renderable; }
void PipelineInit() { ReferenceProcessors(); ReferenceImporters(); Class* klass = ResourceProcessorGetType(); for(auto& child : klass->childs) { auto processor = (ResourceProcessor*) child->createInstance(AllocatorGetHeap()); resourceProcessors.Push(processor); LogInfo("Registering asset handler: %s", child->name); } }
RenderablePtr DebugBuildFrustum( const Frustum& box ) { GeometryBuffer* gb = AllocateHeap(GeometryBuffer); MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "FrustumDebug"); Material* material = materialHandle.Resolve(); material->setBackfaceCulling( false ); Renderable* renderable = AllocateHeap(Renderable); renderable->setPrimitiveType(PrimitiveType::Quads); renderable->setGeometryBuffer(gb); renderable->setMaterial(materialHandle); renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe ); DebugUpdateFrustum(renderable, box); return renderable; }
NAMESPACE_ENGINE_BEGIN //-----------------------------------// BulletDebugDrawer::BulletDebugDrawer() { gb = AllocateThis(GeometryBuffer, BufferUsage::Dynamic, BufferAccess::Write); clearBuffer(); material = MaterialCreate(AllocatorGetHeap(), "PhysicsDebug"); material.Resolve()->setDepthCompare(DepthCompare::LessOrEqual); renderable = AllocateThis(Renderable); renderable->setPrimitiveType(PrimitiveType::Lines); renderable->setGeometryBuffer(gb); renderable->setMaterial(material); }
static bool isUnderVersionControl(const ResourcePtr& res) { #if 0 Stream* stream = StreamCreateFromFile( AllocatorGetHeap(), res->getPath() ); /*, StreamMode::Read );*/ const String& fullPath = PathGetCurrentDir() + PathGetSeparator() + PathGetBase( FileGetFullPath(&file) ) + PathGetSeparator() + ".svn"; FileClose(&file); return wxFileName::DirExists(fullPath); #endif return false; }
RenderablePtr DebugBuildBoundingBox( const BoundingBox& box ) { GeometryBuffer* gb = AllocateHeap(GeometryBuffer); MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "BoundingBoxDebug"); Material* mat = materialHandle.Resolve(); mat->setDepthCompare( DepthCompare::LessOrEqual ); mat->setBackfaceCulling( false ); //mat->setDepthRange( Vector2(0.1f, 0.9f) ); Renderable* renderable = AllocateHeap(Renderable); renderable->setPrimitiveType(PrimitiveType::Quads); renderable->setGeometryBuffer(gb); renderable->setMaterial(materialHandle); renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe ); DebugUpdateBoudingBox(gb, box, Color::White); return renderable; }
RenderablePtr DebugBuildRay( const Ray& pickRay, float length ) { std::vector<Vector3> vertex; vertex.push_back( pickRay.origin ); vertex.push_back( pickRay.getPoint(length) ); std::vector<Vector3> colors( 2, Color::Red ); GeometryBuffer* gb = AllocateHeap(GeometryBuffer); gb->set( VertexAttribute::Position, vertex ); gb->set( VertexAttribute::Color, colors ); MaterialHandle material = MaterialCreate(AllocatorGetHeap(), "RayDebug"); Renderable* renderable = AllocateHeap(Renderable); renderable->setPrimitiveType(PrimitiveType::Lines); renderable->setGeometryBuffer(gb); renderable->setMaterial(material); return renderable; }
ImageHandle FreeTypeFont::createGlyphImage(int codepoint, int fontSize) const { int glyph_index = FT_Get_Char_Index( fontInfo->face, codepoint ); int error = FT_Set_Pixel_Sizes( fontInfo->face, /* handle to face object */ 0, /* pixel_width */ fontSize ); /* pixel_height */ if ( error ) LogError("Error setting font size"); error = FT_Load_Glyph( fontInfo->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD); if ( error ) LogError("Error loading glyph"); FT_Glyph glyph; /* a handle to the glyph image */ error = FT_Get_Glyph( fontInfo->face->glyph, &glyph ); if ( error ) LogError("Error getting glyph"); FT_Vector origin; origin.x = origin.y = 0; error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_LCD, &origin, 1 ); FT_Bitmap bitmap = ((FT_BitmapGlyph) glyph)->bitmap; if (bitmap.width == 0 || bitmap.rows == 0) return HandleInvalid; auto image = ImageCreate(AllocatorGetHeap(), bitmap.width/3, bitmap.rows, PixelFormat::R8G8B8); image.Resolve()->setBuffer(bitmap.buffer, bitmap.pitch); return image; }
bool NetworkInitialize() { gs_NetworkAllocator = AllocatorCreateHeap(AllocatorGetHeap()); AllocatorSetGroup(gs_NetworkAllocator, "Network"); ENetCallbacks callbacks; callbacks.malloc = enet_custom_malloc; callbacks.free = enet_custom_free; int ret = enet_initialize_with_callbacks(ENET_VERSION, &callbacks); if(ret != 0) { LogError("Error initializing ENet"); return false; } LogInfo("Initialized ENet %d.%d.%d networking layer", ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH); return true; }
wxBitmap* ConvertImageToBitmap( Image* image, const Path& fullPath ) { if( !image || !image->isLoaded() ) return nullptr; PixelFormat pf = image->getPixelFormat(); if( pf != PixelFormat::R8G8B8A8 ) { LogDebug("Invalid image format: %s", EnumGetValueName(ReflectionGetType(PixelFormat), (int32)pf)); return nullptr; } //wxBitmap* bmp = new wxBitmap; //bmp->Create(&image->getBuffer(), wxBITMAP_TYPE_ANY, image->getWidth(), image->getHeight(), 4); Stream* stream = StreamCreateFromFile(AllocatorGetHeap(), fullPath, StreamOpenMode::Read); if( !stream ) return nullptr; std::vector<byte> data; StreamRead(stream, data); wxMemoryInputStream mem(&data[0], data.size()); wxImage img(mem); img.Rescale(32, 32); StreamDestroy(stream); #if 0 const wxSize& size = GetSize(); if( img.GetWidth() > size.GetWidth() || img.GetHeight() > size.GetHeight() ) { img.Rescale( size.GetWidth(), size.GetHeight() ); } #endif wxBitmap* bmp = new wxBitmap(img); return bmp; }
void Engine::setupLogger() { stream = StreamCreateFromFile( AllocatorGetHeap(), "Log.html", StreamOpenMode::Write); log = LogCreate( AllocatorGetHeap() ); }
void InputInitialize() { gs_InputAllocator = AllocatorCreateHeap( AllocatorGetHeap() ); AllocatorSetGroup(gs_InputAllocator, "Input"); }
void ResourcesInitialize() { gs_ResourcesAllocator = AllocatorCreateHeap( AllocatorGetHeap() ); AllocatorSetGroup(gs_ResourcesAllocator, "Resources"); }