void GrManager::getTextureVolumeUploadInfo(TexturePtr tex, const TextureVolumeInfo& vol, PtrSize& allocationSize) { const TextureImpl& impl = *tex->m_impl; impl.checkVolume(vol); U width = impl.m_width >> vol.m_level; U height = impl.m_height >> vol.m_level; U depth = impl.m_depth >> vol.m_level; if(!impl.m_workarounds) { allocationSize = computeVolumeSize(width, height, depth, impl.m_format); } else if(!!(impl.m_workarounds & TextureImplWorkaround::R8G8B8_TO_R8G8B8A8)) { // Extra size for staging buffer allocationSize = computeVolumeSize(width, height, depth, PixelFormat(ComponentFormat::R8G8B8, TransformFormat::UNORM)); alignRoundUp(16, allocationSize); allocationSize += computeVolumeSize(width, height, depth, PixelFormat(ComponentFormat::R8G8B8A8, TransformFormat::UNORM)); } else { ANKI_ASSERT(0); } }
PixelFormatList getListOfPixelFormats() { PixelFormatList list; for (int i=0; i< int(NUMBER_OF_PIXEL_FORMAT); i++) { list.push_back(PixelFormat(i)); } return list; }
RenderTarget::RenderTarget (void) : m_width (0) , m_height (0) , m_pixelFormat (PixelFormat(0, 0, 0, 0)) , m_depthBits (0) , m_stencilBits (0) , m_numSamples (0) { }
RageDisplay::PixelFormat RageDisplay::FindPixelFormat( int bpp, unsigned Rmask, unsigned Gmask, unsigned Bmask, unsigned Amask, bool realtime ) { PixelFormatDesc tmp = { bpp, { Rmask, Gmask, Bmask, Amask } }; for(int pixfmt = 0; pixfmt < NUM_PIX_FORMATS; ++pixfmt) { const PixelFormatDesc *pf = GetPixelFormatDesc(PixelFormat(pixfmt)); if(!SupportsTextureFormat( PixelFormat(pixfmt), realtime )) continue; if(memcmp(pf, &tmp, sizeof(tmp))) continue; return PixelFormat(pixfmt); } return NUM_PIX_FORMATS; }
bool Layer::getOpacityForFormat(uint32_t format) { if (HARDWARE_IS_DEVICE_FORMAT(format)) { return true; } PixelFormatInfo info; status_t err = getPixelFormatInfo(PixelFormat(format), &info); // in case of error (unknown format), we assume no blending return (err || info.h_alpha <= info.l_alpha); }
void RageDisplay_D3D::UpdateTexture( unsigned uTexHandle, RageSurface* img, int xoffset, int yoffset, int width, int height ) { IDirect3DTexture8* pTex = (IDirect3DTexture8*)uTexHandle; ASSERT( pTex != NULL ); RECT rect; rect.left = xoffset; rect.top = yoffset; rect.right = width - xoffset; rect.bottom = height - yoffset; D3DLOCKED_RECT lr; pTex->LockRect( 0, &lr, &rect, 0 ); D3DSURFACE_DESC desc; pTex->GetLevelDesc(0, &desc); ASSERT( xoffset+width <= int(desc.Width) ); ASSERT( yoffset+height <= int(desc.Height) ); // // Copy bits // #if defined(XBOX) // Xbox textures need to be swizzled XGSwizzleRect( img->pixels, // pSource, img->pitch, // Pitch, NULL, // pRect, lr.pBits, // pDest, img->w, // Width, img->h, // Height, NULL, // pPoint, img->format->BytesPerPixel ); //BytesPerPixel #else int texpixfmt; for(texpixfmt = 0; texpixfmt < NUM_PIX_FORMATS; ++texpixfmt) if(D3DFORMATS[texpixfmt] == desc.Format) break; ASSERT( texpixfmt != NUM_PIX_FORMATS ); RageSurface *Texture = CreateSurfaceFromPixfmt(PixelFormat(texpixfmt), lr.pBits, width, height, lr.Pitch); ASSERT( Texture ); RageSurfaceUtils::Blit( img, Texture, width, height ); delete Texture; #endif pTex->UnlockRect( 0 ); }
void TextureData3D :: Upload ( GLenum target ) { glTexImage3D ( target /* the target texture */, 0 /* the level-of-detail number */, InternalFormat ( ) /* the number of color components */, Width ( ) /* the width of the texture with border */, Height ( ) /* the height of the texture with border */, Depth ( ) /* the depth of the texture with border */, 0 /* the width of the border */, PixelFormat ( ) /* the format of the pixel data */, Type ( ) /* the data type of the pixel data */, fPixels /* a pointer to the image data */ ); }
// // I_BuildPixelFormatFromSDLSurface // // Helper function that extracts information about the pixel format // from an SDL_Surface and uses it to initialize a PixelFormat object. // Note: the SDL_Surface should be locked prior to calling this. // static void I_BuildPixelFormatFromSDLSurface(const SDL_Surface* sdlsurface, PixelFormat* format) { const SDL_PixelFormat* sdlformat = sdlsurface->format; uint8_t bpp = sdlformat->BitsPerPixel; // handle SDL not reporting correct Ashift/Aloss uint8_t aloss = bpp == 32 ? 0 : 8; uint8_t ashift = bpp == 32 ? 48 - sdlformat->Rshift - sdlformat->Gshift - sdlformat->Bshift : 0; // Create the PixelFormat specification *format = PixelFormat( bpp, 8 - aloss, 8 - sdlformat->Rloss, 8 - sdlformat->Gloss, 8 - sdlformat->Bloss, ashift, sdlformat->Rshift, sdlformat->Gshift, sdlformat->Bshift); }
iePImage ieImage::CreateCopy(bool bCopyAllFrames, bool bDraw, bool bText, iePixelFormat eType) const { if (eType == iePixelFormat::Count) eType = PixelFormat(); iePImage pim = Create(eType, WH(), bDraw, bText); if (!pim) return nullptr; if (ieFailed(pim->CopyFrom(this, bCopyAllFrames))) { pim->Release(); return nullptr; } return pim; }
PixelFormat GL3PlusPixelUtil::getClosestOGREFormat(GLenum format) { switch(format) { case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT32: case GL_DEPTH_COMPONENT32F: case GL_DEPTH_COMPONENT: return PF_DEPTH; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return PF_DXT1; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return PF_DXT3; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return PF_DXT5; case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB: return PF_BC7_UNORM; case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: return PixelFormat(int(PF_ASTC_RGBA_4X4_LDR) + (format - GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR)); case GL_SRGB8: case GL_RGB8: // prefer native endian byte format return PF_BYTE_RGB; case GL_SRGB8_ALPHA8: case GL_RGBA8: // prefer native endian byte format return PF_BYTE_RGBA; }; for(int pf = 0; pf < PF_COUNT; pf++) { if(_pixelFormats[pf].internalFormat == format) return (PixelFormat)pf; } return PF_BYTE_RGBA; }
//============================================================================== Error BlurringRenderingPass::initBlurring( Renderer& r, U width, U height, U samples, F32 blurringDistance) { Array<StringAuto, 2> pps = {{getAllocator(), getAllocator()}}; pps[1].sprintf( "#define HPASS\n" "#define COL_RGB\n" "#define BLURRING_DIST float(%f)\n" "#define IMG_DIMENSION %u\n" "#define SAMPLES %u\n", blurringDistance, height, samples); pps[0].sprintf( "#define VPASS\n" "#define COL_RGB\n" "#define BLURRING_DIST float(%f)\n" "#define IMG_DIMENSION %u\n" "#define SAMPLES %u\n", blurringDistance, width, samples); for(U i = 0; i < 2; i++) { Direction& dir = m_dirs[i]; r.createRenderTarget(width, height, PixelFormat(ComponentFormat::R8G8B8, TransformFormat::UNORM), 1, SamplingFilter::LINEAR, 1, dir.m_rt); // Create FB FramebufferPtr::Initializer fbInit; fbInit.m_colorAttachmentsCount = 1; fbInit.m_colorAttachments[0].m_texture = dir.m_rt; fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE; dir.m_fb.create(&getGrManager(), fbInit); ANKI_CHECK(dir.m_frag.loadToCache(&getResourceManager(), "shaders/VariableSamplingBlurGeneric.frag.glsl", pps[i].toCString(), "r_")); ANKI_CHECK(r.createDrawQuadPipeline( dir.m_frag->getGrShader(), dir.m_ppline)); } return ErrorCode::NONE; }
Error Pps::run(RenderingContext& ctx) { CommandBufferPtr& cmdb = ctx.m_commandBuffer; // Get the drawing parameters Bool drawToDefaultFb = ctx.m_outFb.isCreated(); Bool dbgEnabled = m_r->getDbg().getEnabled(); // Get or create the ppline PipelinePtr& ppline = m_ppline[drawToDefaultFb][dbgEnabled]; if(!ppline) { // Need to create it ShaderResourcePtr& frag = m_frag[drawToDefaultFb][dbgEnabled]; if(!frag) { StringAuto pps(ctx.m_tempAllocator); pps.sprintf("#define BLOOM_ENABLED %u\n" "#define SHARPEN_ENABLED %u\n" "#define FBO_WIDTH %u\n" "#define FBO_HEIGHT %u\n" "#define LUT_SIZE %u.0\n" "#define DBG_ENABLED %u\n" "#define DRAW_TO_DEFAULT %u\n" "#define SMAA_ENABLED 1\n" "#define SMAA_RT_METRICS vec4(%f, %f, %f, %f)\n" "#define SMAA_PRESET_%s\n", true, m_sharpenEnabled, m_r->getWidth(), m_r->getHeight(), LUT_SIZE, dbgEnabled, drawToDefaultFb, 1.0 / m_r->getWidth(), 1.0 / m_r->getHeight(), F32(m_r->getWidth()), F32(m_r->getHeight()), &m_r->getSmaa().m_qualityPerset[0]); ANKI_CHECK(getResourceManager().loadResourceToCache(frag, "shaders/Pps.frag.glsl", pps.toCString(), "r_")); } if(!m_vert) { StringAuto pps(ctx.m_tempAllocator); pps.sprintf("#define SMAA_ENABLED 1\n" "#define SMAA_RT_METRICS vec4(%f, %f, %f, %f)\n" "#define SMAA_PRESET_%s\n", 1.0 / m_r->getWidth(), 1.0 / m_r->getHeight(), F32(m_r->getWidth()), F32(m_r->getHeight()), &m_r->getSmaa().m_qualityPerset[0]); ANKI_CHECK( getResourceManager().loadResourceToCache(m_vert, "shaders/Pps.vert.glsl", pps.toCString(), "r_")); } PixelFormat pfs = (drawToDefaultFb) ? PixelFormat(ComponentFormat::DEFAULT_FRAMEBUFFER, TransformFormat::NONE) : RT_PIXEL_FORMAT; PipelineInitInfo ppinit; ppinit.m_inputAssembler.m_topology = PrimitiveTopology::TRIANGLE_STRIP; ppinit.m_depthStencil.m_depthWriteEnabled = false; ppinit.m_depthStencil.m_depthCompareFunction = CompareOperation::ALWAYS; ppinit.m_color.m_attachmentCount = 1; ppinit.m_color.m_attachments[0].m_format = pfs; ppinit.m_shaders[ShaderType::VERTEX] = m_vert->getGrShader(); ppinit.m_shaders[ShaderType::FRAGMENT] = frag->getGrShader(); ppline = m_r->getGrManager().newInstance<Pipeline>(ppinit); } // Get or create the resource group ResourceGroupPtr& rsrc = m_rcGroup[dbgEnabled]; if(!rsrc || m_lutDirty) { ResourceGroupInitInfo rcInit; rcInit.m_textures[0].m_texture = m_r->getIs().getRt(); rcInit.m_textures[1].m_texture = m_r->getBloom().m_upscale.m_rt; rcInit.m_textures[2].m_texture = m_lut->getGrTexture(); rcInit.m_textures[3].m_texture = m_r->getSmaa().m_weights.m_rt; if(dbgEnabled) { rcInit.m_textures[4].m_texture = m_r->getDbg().getRt(); } rcInit.m_storageBuffers[0].m_buffer = m_r->getTm().getAverageLuminanceBuffer(); rcInit.m_storageBuffers[0].m_usage = BufferUsageBit::STORAGE_FRAGMENT_READ; rsrc = getGrManager().newInstance<ResourceGroup>(rcInit); m_lutDirty = false; } // Get or create FB FramebufferPtr* fb = nullptr; U width, height; if(drawToDefaultFb) { fb = &ctx.m_outFb; width = ctx.m_outFbWidth; height = ctx.m_outFbHeight; } else { width = m_r->getWidth(); height = m_r->getHeight(); fb = &m_fb; } cmdb->beginRenderPass(*fb); cmdb->setViewport(0, 0, width, height); cmdb->bindPipeline(ppline); cmdb->bindResourceGroup(rsrc, 0, nullptr); m_r->drawQuad(cmdb); cmdb->endRenderPass(); if(!drawToDefaultFb) { cmdb->setTextureSurfaceBarrier(m_rt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE, TextureUsageBit::SAMPLED_FRAGMENT, TextureSurfaceInfo(0, 0, 0, 0)); } return ErrorCode::NONE; }
// Shaders ShaderPtr vert = gr->newInstance<Shader>(ShaderType::VERTEX, VERT_INP_SRC); ShaderPtr frag = gr->newInstance<Shader>(ShaderType::FRAGMENT, FRAG_INP_SRC); // Ppline PipelineInitInfo init; init.m_shaders[ShaderType::VERTEX] = vert; init.m_shaders[ShaderType::FRAGMENT] = frag; init.m_color.m_attachments[0].m_format.m_components = ComponentFormat::DEFAULT_FRAMEBUFFER; init.m_color.m_attachmentCount = 1; init.m_depthStencil.m_depthWriteEnabled = false; init.m_depthStencil.m_depthCompareFunction = CompareOperation::ALWAYS; init.m_vertex.m_attributeCount = 3; init.m_vertex.m_attributes[0].m_format = PixelFormat(ComponentFormat::R32G32B32, TransformFormat::FLOAT); init.m_vertex.m_attributes[1].m_format = PixelFormat(ComponentFormat::R8G8B8, TransformFormat::UNORM); init.m_vertex.m_attributes[1].m_offset = sizeof(Vec3); init.m_vertex.m_attributes[2].m_format = PixelFormat(ComponentFormat::R32G32B32, TransformFormat::FLOAT); init.m_vertex.m_attributes[2].m_binding = 1; init.m_vertex.m_bindingCount = 2; init.m_vertex.m_bindings[0].m_stride = sizeof(Vert); init.m_vertex.m_bindings[1].m_stride = sizeof(Vec3); PipelinePtr ppline = gr->newInstance<Pipeline>(init); // FB FramebufferPtr fb = createDefaultFb(*gr); U iterations = 100;
void Surface::free() { ::free(pixels); pixels = 0; w = h = pitch = 0; format = PixelFormat(); }
ieResult ieImage::CopyFrom(iePCImage pimSrc, bool bCopyAllFrames) { if (!IsEqualSize(pimSrc)) return IE_E_INVALIDPARAM; if (Frame.pimNext) { Frame.pimNext->FrameParams().pimPrev = nullptr; Frame.pimNext->Release(); Frame.pimNext = nullptr; } ieResult res; switch (PixelFormat()) { case iePixelFormat::BGRA: res = ie_CopyX2BGRA(this, pimSrc, gie_pClrOptions->bDitherWide); break; case iePixelFormat::CLUT: res = ie_CopyX2CLUT(this, pimSrc, *gie_pClrOptions); break; case iePixelFormat::L: res = ie_CopyX2L(this, pimSrc, gie_pClrOptions->bDitherWide, gie_pClrOptions->bColorimetricRGB2L); break; case iePixelFormat::wBGRA: res = ie_CopyX2wBGRA(this, pimSrc); break; case iePixelFormat::wL: res = ie_CopyX2wL(this, pimSrc, gie_pClrOptions->bColorimetricRGB2L); break; case iePixelFormat::fBGRA: res = ie_CopyX2fBGRA(this, pimSrc); break; case iePixelFormat::fL: res = ie_CopyX2fL(this, pimSrc, gie_pClrOptions->bColorimetricRGB2L); break; default: res = IE_E_INVALIDCLRFORMAT; } if (ieFailed(res)) return res; Frame = iePImage(pimSrc)->FrameParams(); Frame.pimPrev = nullptr; Frame.pimNext = nullptr; Frame.pimRest = nullptr; if (bCopyAllFrames) { iePImage pimNext = const_cast<iePImage>(pimSrc)->FrameParams().pimNext; if (pimNext) Frame.pimNext = pimNext->ieImage::CreateCopy(true, pimNext->Draw(), pimNext->Text(), PixelFormat()); } else { Frame.msDisplayTime = 0; } return res; }
//+------------------------------------------------------------------------ // // Member: COffScreenContext::CreateDDSurface // // Synopsis: Create a DD surface with the specified dimensions and palette. // //------------------------------------------------------------------------- BOOL COffScreenContext::CreateDDSurface(long width, long height, HPALETTE hpal) { HRESULT hr = InitSurface(); if(FAILED(hr)) { return FALSE; } DDPIXELFORMAT* pPF = PixelFormat(_hdcWnd, _cBitsPixel); if(!pPF) { return FALSE; } DDSURFACEDESC ddsd; ddsd.dwSize = sizeof(ddsd); ddsd.ddpfPixelFormat = *pPF; ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_DATAEXCHANGE|DDSCAPS_OWNDC; if(_fUse3D) { ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE; } ddsd.dwWidth = width; ddsd.dwHeight = height; hr = g_pDirectDraw->CreateSurface(&ddsd, &_pDDSurface, NULL); if(FAILED(hr)) { return FALSE; } // set color table if(_cBitsPixel <= 8) { IDirectDrawPalette* pDDPal; PALETTEENTRY* pPal; PALETTEENTRY pal256[256]; long cEntries; DWORD pcaps; if(_cBitsPixel == 8) { cEntries = GetPaletteEntries(hpal, 0, 256, pal256); pPal = pal256; pcaps = DDPCAPS_8BIT; } else if(_cBitsPixel == 4) { cEntries = 16; pPal = g_pal16; pcaps = DDPCAPS_4BIT; } else if(_cBitsPixel == 1) { cEntries = 2; pPal = g_pal2; pcaps = DDPCAPS_1BIT; } else { Assert(0 && "invalid cBitsPerPixel"); return FALSE; } // create and initialize a new DD palette hr = g_pDirectDraw->CreatePalette(pcaps|DDPCAPS_INITIALIZE, pPal, &pDDPal, NULL); if(SUCCEEDED(hr)) { // attach the DD palette to the DD surface hr = _pDDSurface->SetPalette(pDDPal); pDDPal->Release(); } if(FAILED(hr)) { return FALSE; } } hr = _pDDSurface->GetDC(&_hdcMem); return SUCCEEDED(hr); }
bool TGADecoder::readHeader(Common::SeekableReadStream &tga, byte &imageType, byte &pixelDepth) { if (!tga.seek(0)) { warning("Failed reading TGA-file"); return false; } // TGAs have an optional "id" string in the header uint32 idLength = tga.readByte(); // Number of colors in the color map / palette int hasColorMap = tga.readByte(); // Image type. See header for numeric constants imageType = tga.readByte(); switch (imageType) { case TYPE_CMAP: case TYPE_TRUECOLOR: case TYPE_BW: case TYPE_RLE_CMAP: case TYPE_RLE_TRUECOLOR: case TYPE_RLE_BW: break; default: warning("Unsupported image type: %d", imageType); return false; } // Color map specifications if (hasColorMap == 0) { tga.skip(5); } else { _colorMapOrigin = tga.readUint16LE(); _colorMapLength = tga.readUint16LE(); _colorMapEntryLength = tga.readByte(); } // Origin-defintions tga.skip(2 + 2); // Image dimensions _surface.w = tga.readUint16LE(); _surface.h = tga.readUint16LE(); // Bits per pixel pixelDepth = tga.readByte(); _surface.format.bytesPerPixel = pixelDepth / 8; // Image descriptor byte imgDesc = tga.readByte(); int attributeBits = imgDesc & 0x0F; assert((imgDesc & 0x10) == 0); _originTop = (imgDesc & 0x20); // Interleaving is not handled at this point //int interleave = (imgDesc & 0xC); if (imageType == TYPE_CMAP || imageType == TYPE_RLE_CMAP) { if (pixelDepth == 8) { _format = PixelFormat::createFormatCLUT8(); } else { warning("Unsupported index-depth: %d", pixelDepth); return false; } } else if (imageType == TYPE_TRUECOLOR || imageType == TYPE_RLE_TRUECOLOR) { if (pixelDepth == 24) { _format = PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0); } else if (pixelDepth == 32) { // HACK: According to the spec, attributeBits should determine the amount // of alpha-bits, however, as the game files that use this decoder seems // to ignore that fact, we force the amount to 8 for 32bpp files for now. _format = PixelFormat(4, 8, 8, 8, /* attributeBits */ 8, 16, 8, 0, 24); } else if (pixelDepth == 16 && imageType == TYPE_TRUECOLOR) { // 16bpp TGA is ARGB1555 _format = PixelFormat(2, 5, 5, 5, attributeBits, 10, 5, 0, 15); } else { warning("Unsupported pixel depth: %d, %d", imageType, pixelDepth); return false; } } else if (imageType == TYPE_BW || TYPE_RLE_BW) { if (pixelDepth == 8) { _format = PixelFormat(4, 8, 8, 8, 0, 16, 8, 0, 0); } else { warning("Unsupported pixel depth: %d, %d", imageType, pixelDepth); return false; } } else { warning("Unsupported image type: %d", imageType); return false; } // Skip the id string tga.skip(idLength); if (hasColorMap) { return readColorMap(tga, imageType, pixelDepth); } return true; }
void PipelineImpl::initVertexState() { for(U i = 0; i < m_in.m_vertex.m_attributeCount; ++i) { const VertexAttributeBinding& binding = m_in.m_vertex.m_attributes[i]; Attribute& cache = m_cache.m_attribs[i]; // Component count if(binding.m_format == PixelFormat(ComponentFormat::R32, TransformFormat::FLOAT)) { cache.m_compCount = 1; cache.m_type = GL_FLOAT; cache.m_normalized = false; } else if(binding.m_format == PixelFormat(ComponentFormat::R32G32, TransformFormat::FLOAT)) { cache.m_compCount = 2; cache.m_type = GL_FLOAT; cache.m_normalized = false; } else if(binding.m_format == PixelFormat(ComponentFormat::R32G32B32, TransformFormat::FLOAT)) { cache.m_compCount = 3; cache.m_type = GL_FLOAT; cache.m_normalized = false; } else if(binding.m_format == PixelFormat(ComponentFormat::R32G32B32A32, TransformFormat::FLOAT)) { cache.m_compCount = 4; cache.m_type = GL_FLOAT; cache.m_normalized = false; } else if(binding.m_format == PixelFormat(ComponentFormat::R16G16, TransformFormat::FLOAT)) { cache.m_compCount = 2; cache.m_type = GL_HALF_FLOAT; cache.m_normalized = false; } else if(binding.m_format == PixelFormat(ComponentFormat::R16G16, TransformFormat::UNORM)) { cache.m_compCount = 2; cache.m_type = GL_UNSIGNED_SHORT; cache.m_normalized = true; } else if(binding.m_format == PixelFormat(ComponentFormat::R10G10B10A2, TransformFormat::SNORM)) { cache.m_compCount = 4; cache.m_type = GL_INT_2_10_10_10_REV; cache.m_normalized = true; } else if(binding.m_format == PixelFormat(ComponentFormat::R8G8B8A8, TransformFormat::UNORM)) { cache.m_compCount = 4; cache.m_type = GL_UNSIGNED_BYTE; cache.m_normalized = true; } else if(binding.m_format == PixelFormat(ComponentFormat::R8G8B8, TransformFormat::UNORM)) { cache.m_compCount = 3; cache.m_type = GL_UNSIGNED_BYTE; cache.m_normalized = true; } else { ANKI_ASSERT(0 && "TODO"); } } m_hashes.m_vertex = computeHash(&m_in.m_vertex, sizeof(m_in.m_vertex)); }
Error Is::initInternal(const ConfigSet& config) { m_maxLightIds = config.getNumber("is.maxLightsPerCluster"); if(m_maxLightIds == 0) { ANKI_LOGE("Incorrect number of max light indices"); return ErrorCode::USER_DATA; } m_rtMipCount = computeMaxMipmapCount2d(m_r->getWidth(), m_r->getHeight(), 32); ANKI_ASSERT(m_rtMipCount); U clusterCount = m_r->getTileCountXY().x() * m_r->getTileCountXY().y() * config.getNumber("clusterSizeZ"); m_clusterCount = clusterCount; m_maxLightIds *= clusterCount; m_lightBin = getAllocator().newInstance<LightBin>(getAllocator(), m_r->getTileCountXY().x(), m_r->getTileCountXY().y(), config.getNumber("clusterSizeZ"), &m_r->getThreadPool(), &getGrManager()); // // Load the programs // StringAuto pps(getAllocator()); pps.sprintf("\n#define TILE_COUNT_X %u\n" "#define TILE_COUNT_Y %u\n" "#define CLUSTER_COUNT %u\n" "#define RENDERER_WIDTH %u\n" "#define RENDERER_HEIGHT %u\n" "#define MAX_LIGHT_INDICES %u\n" "#define POISSON %u\n" "#define INDIRECT_ENABLED %u\n" "#define IR_MIPMAP_COUNT %u\n", m_r->getTileCountXY().x(), m_r->getTileCountXY().y(), clusterCount, m_r->getWidth(), m_r->getHeight(), m_maxLightIds, m_r->getSm().getPoissonEnabled(), 1, m_r->getIr().getReflectionTextureMipmapCount()); // point light ANKI_CHECK(getResourceManager().loadResourceToCache(m_lightVert, "shaders/Is.vert.glsl", pps.toCString(), "r_")); ANKI_CHECK(getResourceManager().loadResourceToCache(m_lightFrag, "shaders/Is.frag.glsl", pps.toCString(), "r_")); PipelineInitInfo init; init.m_inputAssembler.m_topology = PrimitiveTopology::TRIANGLE_STRIP; init.m_depthStencil.m_depthWriteEnabled = false; init.m_depthStencil.m_depthCompareFunction = CompareOperation::ALWAYS; init.m_color.m_attachmentCount = 1; init.m_color.m_attachments[0].m_format = IS_COLOR_ATTACHMENT_PIXEL_FORMAT; init.m_shaders[U(ShaderType::VERTEX)] = m_lightVert->getGrShader(); init.m_shaders[U(ShaderType::FRAGMENT)] = m_lightFrag->getGrShader(); m_lightPpline = getGrManager().newInstance<Pipeline>(init); // // Create framebuffer // m_r->createRenderTarget(m_r->getWidth(), m_r->getHeight(), IS_COLOR_ATTACHMENT_PIXEL_FORMAT, TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE | TextureUsageBit::SAMPLED_COMPUTE, SamplingFilter::LINEAR, m_rtMipCount, m_rt); FramebufferInitInfo fbInit; fbInit.m_colorAttachmentCount = 1; fbInit.m_colorAttachments[0].m_texture = m_rt; fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE; fbInit.m_colorAttachments[0].m_usageInsideRenderPass = TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE; m_fb = getGrManager().newInstance<Framebuffer>(fbInit); // // Create resource group // { ResourceGroupInitInfo init; init.m_textures[0].m_texture = m_r->getMs().m_rt0; init.m_textures[1].m_texture = m_r->getMs().m_rt1; init.m_textures[2].m_texture = m_r->getMs().m_rt2; init.m_textures[3].m_texture = m_r->getMs().m_depthRt; init.m_textures[3].m_usage = TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ; init.m_textures[4].m_texture = m_r->getSm().getSpotTextureArray(); init.m_textures[5].m_texture = m_r->getSm().getOmniTextureArray(); init.m_textures[6].m_texture = m_r->getIr().getReflectionTexture(); init.m_textures[7].m_texture = m_r->getIr().getIrradianceTexture(); init.m_textures[8].m_texture = m_r->getIr().getIntegrationLut(); init.m_textures[8].m_sampler = m_r->getIr().getIntegrationLutSampler(); init.m_uniformBuffers[0].m_uploadedMemory = true; init.m_uniformBuffers[0].m_usage = BufferUsageBit::UNIFORM_FRAGMENT | BufferUsageBit::UNIFORM_VERTEX; init.m_uniformBuffers[1].m_uploadedMemory = true; init.m_uniformBuffers[1].m_usage = BufferUsageBit::UNIFORM_FRAGMENT | BufferUsageBit::UNIFORM_VERTEX; init.m_uniformBuffers[2].m_uploadedMemory = true; init.m_uniformBuffers[2].m_usage = BufferUsageBit::UNIFORM_FRAGMENT | BufferUsageBit::UNIFORM_VERTEX; init.m_uniformBuffers[3].m_uploadedMemory = true; init.m_uniformBuffers[3].m_usage = BufferUsageBit::UNIFORM_FRAGMENT | BufferUsageBit::UNIFORM_VERTEX; init.m_uniformBuffers[4].m_uploadedMemory = true; init.m_uniformBuffers[4].m_usage = BufferUsageBit::UNIFORM_FRAGMENT | BufferUsageBit::UNIFORM_VERTEX; init.m_storageBuffers[0].m_uploadedMemory = true; init.m_storageBuffers[0].m_usage = BufferUsageBit::STORAGE_FRAGMENT_READ | BufferUsageBit::STORAGE_VERTEX_READ; init.m_storageBuffers[1].m_uploadedMemory = true; init.m_storageBuffers[1].m_usage = BufferUsageBit::STORAGE_FRAGMENT_READ | BufferUsageBit::STORAGE_VERTEX_READ; m_rcGroup = getGrManager().newInstance<ResourceGroup>(init); } TextureInitInfo texinit; texinit.m_width = texinit.m_height = 4; texinit.m_usage = TextureUsageBit::SAMPLED_FRAGMENT; texinit.m_format = PixelFormat(ComponentFormat::R8G8B8A8, TransformFormat::UNORM); m_dummyTex = getGrManager().newInstance<Texture>(texinit); return ErrorCode::NONE; }
//typedef std::map<PixmapFormat::PixelFormat,unsigned int>::value_type value_type; void PixmapFormat::init_depth_table(void) { typedef std::map<PixelFormat,unsigned int>::value_type value_type; depth_table.insert(value_type(PixelFormat(PIXFMT_NONE), 0)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB15_LE), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB16_LE), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB15_BE), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB16_BE), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_BGR24), 24)); depth_table.insert(value_type(PixelFormat(PIXFMT_BGR32), 32)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB24), 24)); depth_table.insert(value_type(PixelFormat(PIXFMT_RGB32), 32)); depth_table.insert(value_type(PixelFormat(PIXFMT_YUYV), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_YUV422P), 16)); depth_table.insert(value_type(PixelFormat(PIXFMT_YUV420P),12)); depth_table.insert(value_type(PixelFormat(PIXFMT_UYVY), 16)); depth_table_initialized = true; /* depth_table[PIXFMT_NONE] = 0; depth_table[PIXFMT_RGB15_LE] = 16; depth_table[PIXFMT_RGB16_LE] = 16; depth_table[PIXFMT_RGB15_BE] = 16; depth_table[PIXFMT_RGB16_BE] = 16; depth_table[PIXFMT_BGR24] = 24; depth_table[PIXFMT_BGR32] = 32; depth_table[PIXFMT_RGB24] = 24; depth_table[PIXFMT_RGB32] = 32; depth_table[PIXFMT_YUYV] = 16; depth_table[PIXFMT_YUV422P] = 16; depth_table[PIXFMT_YUV420P] = 12; depth_table[PIXFMT_UYVY] = 16; */ }