void Terrain::Regenerate() { faultFormation->GenerateHeightMap(vertices); faultFormation->ApplyErosionFilter(vertices, 0.4f); GenerateTexture(); ApproximateNormals(); }
bool CreateMotionBlurTexture(cTextureWrapper& tex, int width, int height, int interpolation) { tex.SetTextureWidth(width); tex.SetTextureHeight(height); int filter; GLuint texID = 0; switch(interpolation) { case 0 : filter = GL_LINEAR; break; case 1: filter = GL_NEAREST; break; } GenerateTexture(texID, tex.GetTextureWidth(), tex.GetTextureHeight(), tex.GetBytesPerPixel(), tex.GetTextureFormat(), filter, filter); tex.SetTextureID(texID); return true; }
void GPURaycaster::Init(int screenWidth, int screenHeight) { maxRaySteps = 1000; rayStepSize = 0.005f; gradientStepSize = 0.005f; GenerateTexture(); }
void brush::init() { radius = CHUNKSIZE/2; hardness = 0.5f; iradius = hardness * radius; oradius = radius - iradius; glGenTextures(1, &texID); GenerateTexture(); }
void Brush::init() { radius = 15; hardness = 0.5f; iradius = hardness * radius; oradius = radius - iradius; _texture = new OpenGL::Texture(); GenerateTexture(); }
/** * Zeichnet die Textur. * * @author FloSoft */ void glArchivItem_Bitmap::Draw(short dst_x, short dst_y, short dst_w, short dst_h, short src_x, short src_y, short src_w, short src_h, const unsigned int color, const unsigned int unused) { if(texture == 0) GenerateTexture(); if(texture == 0) return; if(src_w == 0) src_w = width_; if(src_h == 0) src_h = height_; if(dst_w == 0) dst_w = src_w; if(dst_h == 0) dst_h = src_h; VIDEODRIVER.BindTexture(texture); assert(getBobType() != libsiedler2::BOBTYPE_BITMAP_PLAYER); struct GL_T2F_C4UB_V3F_Struct { GLfloat tx, ty; GLubyte r, g, b, a; GLfloat x, y, z; }; GL_T2F_C4UB_V3F_Struct tmp[4]; int x = -nx_ + dst_x; int y = -ny_ + dst_y; tmp[0].x = tmp[1].x = GLfloat(x); tmp[2].x = tmp[3].x = GLfloat(x + dst_w); tmp[0].y = tmp[3].y = GLfloat(y); tmp[1].y = tmp[2].y = GLfloat(y + dst_h); tmp[0].z = tmp[1].z = tmp[2].z = tmp[3].z = 0.0f; tmp[0].tx = tmp[1].tx = (GLfloat)src_x / tex_width_; tmp[2].tx = tmp[3].tx = (GLfloat)(src_x + src_w) / tex_width_; tmp[0].ty = tmp[3].ty = (GLfloat)src_y / tex_height_; tmp[1].ty = tmp[2].ty = (GLfloat)(src_y + src_h) / tex_height_; tmp[0].r = tmp[1].r = tmp[2].r = tmp[3].r = GetRed(color); tmp[0].g = tmp[1].g = tmp[2].g = tmp[3].g = GetGreen(color); tmp[0].b = tmp[1].b = tmp[2].b = tmp[3].b = GetBlue(color); tmp[0].a = tmp[1].a = tmp[2].a = tmp[3].a = GetAlpha(color); glInterleavedArrays(GL_T2F_C4UB_V3F, 0, tmp); glDrawArrays(GL_QUADS, 0, 4); return; }
OpenGLRenderer::OpenGLRenderer(int screenWidth, int screenHeight, VolumeDataset &volume, ShaderManager &shaderManager, Camera &camera) { currTexture3D = GenerateTexture(volume); raycaster = new GPURaycaster(screenWidth, screenHeight, volume); // transferFunction.Init(" ", volume); tfBandWidth = 0.1f; tfBandPos = 0.5f; }
void UILabel::Setup( const std::string& id, const std::string& label, FloatRect position, bool centered, SDL_Color textColor, TTF_Font* font, const std::string& effect, int effectMax ) { m_position = position; m_color = textColor; m_font = font; m_label = label; m_centered = centered; m_effect = effect; m_effectMax = effectMax; GenerateTexture(); }
void VolumeDataset::UpdateTexture() { glDeleteTextures(1, &currTexture3D); currTexture3D = nextTexture3D; if (currentTimestep < timesteps-1) voxelReader.CopyFileToBuffer(memblock3D, currentTimestep+1); else voxelReader.CopyFileToBuffer(memblock3D, 0); nextTexture3D = GenerateTexture(); }
bool GuiRenderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) { FILE *file = fopen(source.CString(), "rb"); fseek(file, 18, SEEK_CUR); unsigned int width; unsigned int height; fread(&width, 4, 1, file); fread(&height, 4, 1, file); short int bpp; short int planes; fread(&bpp, 2, 1, file); fread(&planes, 2, 1, file); fseek(file, 24, SEEK_CUR); long input_size = width * height * 3; unsigned char* contents = new unsigned char[input_size]; fread(contents, input_size, 1, file); long output_size = width * height * 4; unsigned char* texture_data = new unsigned char[output_size]; int i = 0; int j = 0; while (i != output_size) { texture_data[i] = contents[j + 2]; texture_data[i + 1] = contents[j + 1]; texture_data[i + 2] = contents[j]; texture_data[i + 3] = 255; i += 4; j += 3; } fclose(file); texture_dimensions.x = width; texture_dimensions.y = height; bool success = GenerateTexture(texture_handle, texture_data, texture_dimensions); delete[] contents; delete[] texture_data; return success; }
void UITextBox::Setup( const std::string& id, FloatRect position, SDL_Color bgColor, SDL_Color selectedColor, SDL_Color textColor, TTF_Font* font, int maxChars ) { Logger::Out( "Setup " + id, "UITextBox::Setup" ); m_id = id; m_position = position; m_textColor = textColor; m_bgColor = bgColor; m_defaultBgColor = bgColor; m_selectedBgColor = selectedColor; m_font = font; GenerateTexture(); SDL_Rect inputRect = position.ToSDLRect(); SDL_SetTextInputRect( &inputRect ); m_maxChars = maxChars; }
bool RenderInterface::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) { ImageData Data = ImageLoader::GetDataForImage(GameState::GetInstance().GetSkinFile(source.CString())); Data.Filename = GameState::GetInstance().GetSkinFile(source.CString()); texture_dimensions.x = Data.Width; texture_dimensions.y = Data.Height; if (!Data.Data) return false; GenerateTexture(texture_handle, (Rocket::Core::byte*)Data.Data, Rocket::Core::Vector2i(Data.Width, Data.Height)); Image* Ret = (Image*)texture_handle; Ret->fname = Data.Filename; return true; }
// Generate texture routine taken from Full Scene Motion Blur By Stanciu Vlad bool GenerateTexture(GLuint &Texture, int SizeX, int SizeY, int Channels, int Format, int Min_Filter, int Mag_Filter) { bool Status = false; unsigned int memoryRequiredSize = SizeX * SizeY * Channels; unsigned int *memoryBlock = new unsigned int[memoryRequiredSize]; if(memoryBlock == 0) return Status; ZeroMemory(memoryBlock, memoryRequiredSize); Status = GenerateTexture(Texture, SizeX, SizeY, Channels, Format, Min_Filter, Mag_Filter, memoryBlock); delete [] memoryBlock; // int ErrorStatus = glGetError(); // if(ErrorStatus == GL_NO_ERROR) // Status = TRUE; return Status; }
Terrain::Terrain(int width, int depth) { this->width = width; this->depth = depth; heightScale = 0.2f; int numVertices = depth * width; vertices.reserve(numVertices); // fill vector with points for(int i = 0; i < numVertices; ++i) { vertices.push_back(Vector3f((float)(i % width), 0.0f, (float)(int)(i / width))); } // make our terrain using fault formation faultFormation = new FaultFormation(width, depth); faultFormation->GenerateHeightMap(vertices); faultFormation->ApplyErosionFilter(vertices, 0.4f); ApproximateNormals(); GenerateTexture(); }
void glArchivItem_Bitmap_Player::Draw(short dst_x, short dst_y, short dst_w, short dst_h, short src_x, short src_y, short src_w, short src_h, const unsigned int color, const unsigned int player_color) { if(texture == 0) GenerateTexture(); if(texture == 0) return; if(src_w == 0) src_w = width; if(src_h == 0) src_h = height; if(dst_w == 0) dst_w = src_w; if(dst_h == 0) dst_h = src_h; struct GL_T2F_C4UB_V3F_Struct { GLfloat tx, ty; GLubyte r, g, b, a; GLfloat x, y, z; }; GL_T2F_C4UB_V3F_Struct tmp[8]; tmp[0].z = tmp[1].z = tmp[2].z = tmp[3].z = 0.0; int x = -nx + dst_x; int y = -ny + dst_y; tmp[0].x = tmp[1].x = GLfloat(x); tmp[2].x = tmp[3].x = GLfloat(x + dst_w); tmp[0].y = tmp[3].y = GLfloat(y); tmp[1].y = tmp[2].y = GLfloat(y + dst_h); tmp[0].tx = tmp[1].tx = (GLfloat)(src_x) / (GLfloat)tex_width / 2.0f; tmp[2].tx = tmp[3].tx = (GLfloat)(src_x + src_w) / (GLfloat)tex_width / 2.0f; tmp[0].ty = tmp[3].ty = (GLfloat)src_y / tex_height; tmp[1].ty = tmp[2].ty = (GLfloat)(src_y + src_h) / tex_height; tmp[4] = tmp[0]; tmp[5] = tmp[1]; tmp[6] = tmp[2]; tmp[7] = tmp[3]; tmp[4].tx += 0.5; tmp[5].tx += 0.5; tmp[6].tx += 0.5; tmp[7].tx += 0.5; tmp[0].r = tmp[1].r = tmp[2].r = tmp[3].r = GetRed(color); tmp[0].g = tmp[1].g = tmp[2].g = tmp[3].g = GetGreen(color); tmp[0].b = tmp[1].b = tmp[2].b = tmp[3].b = GetBlue(color); tmp[0].a = tmp[1].a = tmp[2].a = tmp[3].a = GetAlpha(color); tmp[4].r = tmp[5].r = tmp[6].r = tmp[7].r = GetRed(player_color); tmp[4].g = tmp[5].g = tmp[6].g = tmp[7].g = GetGreen(player_color); tmp[4].b = tmp[5].b = tmp[6].b = tmp[7].b = GetBlue(player_color); tmp[4].a = tmp[5].a = tmp[6].a = tmp[7].a = GetAlpha(player_color); glInterleavedArrays(GL_T2F_C4UB_V3F, 0, tmp); VideoDriverWrapper::inst().BindTexture(texture); glDrawArrays(GL_QUADS, 0, 8); }
// Called by Rocket when a texture is required by the library. bool Module::GUI::RenderInterface::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) { Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface(); Rocket::Core::FileHandle file_handle = file_interface->Open(source); if (!file_handle) { return false; } file_interface->Seek(file_handle, 0, SEEK_END); size_t buffer_size = file_interface->Tell(file_handle); file_interface->Seek(file_handle, 0, SEEK_SET); char* buffer = new char[buffer_size]; file_interface->Read(buffer, buffer_size, file_handle); file_interface->Close(file_handle); TGAHeader header; memcpy(&header, buffer, sizeof(TGAHeader)); int color_mode = header.bitsPerPixel / 8; int image_size = header.width * header.height * 4; // We always make 32bit textures if (header.dataType != 2) { Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported."); return false; } // Ensure we have at least 3 colors if (color_mode < 3) { Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported"); return false; } const char* image_src = buffer + sizeof(TGAHeader); unsigned char* image_dest = new unsigned char[image_size]; // Targa is BGR, swap to RGB and flip Y axis for (long y = 0; y < header.height; y++) { long read_index = y * header.width * color_mode; long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode; for (long x = 0; x < header.width; x++) { image_dest[write_index] = image_src[read_index+2]; image_dest[write_index+1] = image_src[read_index+1]; image_dest[write_index+2] = image_src[read_index]; if (color_mode == 4) image_dest[write_index+3] = image_src[read_index+3]; else image_dest[write_index+3] = 255; write_index += 4; read_index += color_mode; } } texture_dimensions.x = header.width; texture_dimensions.y = header.height; bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions); delete [] image_dest; delete [] buffer; return success; }
/** * Liefert das GL-Textur-Handle. * * @author FloSoft */ unsigned int glArchivItem_BitmapBase::GetTexture() { if(texture == 0) GenerateTexture(); return texture; }
void UILabel::ChangeText( const std::string& text ) { m_label = text; GenerateTexture(); }
void UITextBox::RemoveLastLetter() { m_label = m_label.substr( 0, m_label.size() - 1 ); GenerateTexture(); }
void UITextBox::AppendText( const std::string& text ) { Logger::Out( "Append \"" + text + "\" to existing label \"" + m_label + "\"", "UITextBox::ValidateText" ); m_label += text; GenerateTexture(); }
void UITextBox::SetText( const std::string& text ) { m_label = text; GenerateTexture(); }
void UILabel::RegenerateTexture() { GenerateTexture(); }
void D3D12SmallResources::CreateTextures() { m_textures.clear(); m_textures.resize(TextureCount); m_textureHeap.Reset(); ThrowIfFailed(m_copyCommandAllocator->Reset()); ThrowIfFailed(m_copyCommandList->Reset(m_copyCommandAllocator.Get(), nullptr)); CD3DX12_RESOURCE_DESC textureDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, TextureWidth, TextureHeight, 1, 1); if (m_usePlacedResources) { // Since we are using small resources we can take advantage of 4KB // resource alignments. As long as the most detailed mip can fit in an // allocation less than 64KB, 4KB alignments can be used. // // When dealing with MSAA textures the rules are similar, but the minimum // alignment is 64KB for a texture whose most detailed mip can fit in an // allocation less than 4MB. textureDesc.Alignment = D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT; D3D12_RESOURCE_ALLOCATION_INFO info = m_device->GetResourceAllocationInfo(0, 1, &textureDesc); if (info.Alignment != D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT) { // If the alignment requested is not granted, then let D3D tell us // the alignment that needs to be used for these resources. textureDesc.Alignment = 0; info = m_device->GetResourceAllocationInfo(0, 1, &textureDesc); } const UINT64 heapSize = TextureCount * info.SizeInBytes; CD3DX12_HEAP_DESC heapDesc(heapSize, D3D12_HEAP_TYPE_DEFAULT, 0, D3D12_HEAP_FLAG_DENY_BUFFERS | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES); ThrowIfFailed(m_device->CreateHeap(&heapDesc, IID_PPV_ARGS(&m_textureHeap))); std::vector<D3D12_RESOURCE_BARRIER> barriers; barriers.resize(TextureCount); for (UINT n = 0; n < TextureCount; n++) { ThrowIfFailed(m_device->CreatePlacedResource( m_textureHeap.Get(), n * info.SizeInBytes, &textureDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&m_textures[n]))); barriers[n] = CD3DX12_RESOURCE_BARRIER::Aliasing(nullptr, m_textures[n].Get()); } m_copyCommandList->ResourceBarrier(static_cast<UINT>(barriers.size()), barriers.data()); } else { for (UINT n = 0; n < TextureCount; n++) { ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &textureDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&m_textures[n]))); } } // Note: ComPtr's are CPU objects but these resources need to stay in scope until // the command list that references them has finished executing on the GPU. // We will flush the GPU at the end of this method to ensure the resources are not // prematurely destroyed. std::vector<ComPtr<ID3D12Resource>> uploadResources; uploadResources.resize(TextureCount); // Colors for textures are randomly generated. Reset the seed so that the colors // don't change when the resource type changes. srand(100); CD3DX12_CPU_DESCRIPTOR_HANDLE cpuHandle(m_srvHeap->GetCPUDescriptorHandleForHeapStart()); for (UINT n = 0; n < TextureCount; n++) { const UINT64 uploadBufferSize = GetRequiredIntermediateSize(m_textures[n].Get(), 0, 1) + D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadResources[n]))); auto texture = GenerateTexture(); // Copy data to the intermediate upload heap and then schedule a copy // from the upload heap to the texture. D3D12_SUBRESOURCE_DATA textureData = {}; textureData.pData = reinterpret_cast<UINT8*>(texture.data()); textureData.RowPitch = TextureWidth * TexturePixelSizeInBytes; textureData.SlicePitch = textureData.RowPitch * TextureHeight; UpdateSubresources<1>(m_copyCommandList.Get(), m_textures[n].Get(), uploadResources[n].Get(), 0, 0, 1, &textureData); NAME_D3D12_OBJECT_INDEXED(m_textures, n); // Describe and create a SRV for the texture. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDesc.Format = textureDesc.Format; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = textureDesc.MipLevels; m_device->CreateShaderResourceView(m_textures[n].Get(), &srvDesc, cpuHandle); cpuHandle.Offset(m_srvDescriptorSize); } ThrowIfFailed(m_copyCommandList->Close()); ID3D12CommandList* ppCommandLists[] = { m_copyCommandList.Get() }; m_copyQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists); // Wait for the copy queue to complete execution of the command list. m_copyQueue->Signal(m_fence.Get(), m_fenceValues[m_frameIndex]); ThrowIfFailed(m_fence->SetEventOnCompletion(m_fenceValues[m_frameIndex], m_fenceEvent)); WaitForSingleObjectEx(m_fenceEvent, INFINITE, FALSE); m_fenceValues[m_frameIndex]++; }