예제 #1
0
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
int main(int _argc, char** _argv)
{
	EEDesc desc;
	desc.applicationName = L"Emerald";	//窗口名称
	desc.isFullScreen = false;			//是否全屏
	desc.width = 800;					//窗口宽度
	desc.height = 450;					//窗口高度
	desc.isSSAA = true;					//是开启抗锯齿
	desc.isVsync = false;				//是否垂直同步
	EEInitialize();

	EETexture tex0(L"Texture\\etc\\101087.jpg");
	EETexture tex1(L"Texture\\etc\\xmyrz.jpg");
	//EETexture bgTex(L"Texture\\test3.gif");

	//EETexture bgTex(L"Texture\\Project Diva Freedom\\主界面\\默认主题\\背景.jpg");
	EEQuad2D quad(Rect_Float(0, 0, (float)EEGetWidth(), (float)EEGetHeight()), tex1);
	EEContrastAndBrightC cb(tex1);
	cb.SetContrast(200.f);
	cb.SetBright(0.1f);

	while (EERun())
	{
		EEBeginScene(EEColor::BLACK);

		quad.Process();

		printf("%d ", EEGetFPS());
		EEEndScene();
	}

	EEShutdown();
	return 0;
}
예제 #2
0
/*
=============
  GetTextureCoords
  Загрузка текстуры, размещение в атласе, выдача реальных текстурных координат
=============
*/
Vec4 Texture::Atlas::GetTextureCoords( const std::string& textureFileName, const Vec4& textureCoords )
{
  //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => textureFileName['%s'] textureCoords[%3.3f; %3.3f]-[%3.3f; %3.3f]", textureFileName.c_str(), textureCoords.x, textureCoords.y, textureCoords.z, textureCoords.w );
  Texture::Atlas::Item *item = this->IsTextureLoaded( textureFileName );
  if( item )
  {
    Vec3 leftTop, rightBottom;
    leftTop = Vec3( textureCoords.x, textureCoords.y, 0.0f ) * item->matTransform;
    rightBottom = Vec3( textureCoords.z, textureCoords.w, 0.0f ) * item->matTransform;
    //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => existing texture['%s'] t0[%3.5f; %3.5f] t1[%3.5f; %3.5f]", textureFileName.c_str(), leftTop.x, leftTop.y, rightBottom.x, rightBottom.y );
    return Vec4( leftTop.x, leftTop.y, rightBottom.x, rightBottom.y );
  }
  else
  {
    Texture::Atlas::Item *item = this->LoadTexture( textureFileName );
    if( !item ) {
      __log.PrintInfo( Filelevel_ERROR, "Texture::Atlas::GetTextureCoords => LoadTexture('%s') => failed", textureFileName.c_str() );
      return Vec4( 0.0f, 0.0f, 1.0f, 1.0f );
    }
    Vec3 tex0( textureCoords.x, textureCoords.y, 0 ), tex1( textureCoords.z, textureCoords.w, 0 );
    tex0 *= item->matTransform;
    tex1 *= item->matTransform;
    //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => loaded texture['%s'] t0[%3.5f; %3.5f] t1[%3.5f; %3.5f]", textureFileName.c_str(), tex0.x, tex0.y, tex1.x, tex1.y );
    return Vec4( tex0.x, tex0.y, tex1.x, tex1.y );
  }
}//GetTextureCoords
예제 #3
0
void GlobeView::drawLocalClient(){
	if(!mEarth) return;

	ci::gl::ScopedFaceCulling cull(true, GL_BACK);
	ci::gl::ScopedTextureBind tex0(mTexDiffuse, 0);
	ci::gl::ScopedTextureBind tex1(mTexNormal, 1);
	ci::gl::ScopedTextureBind tex2(mTexMask, 2);

	mEarth->draw();
}
예제 #4
0
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
int main(int _argc, char** _argv)
{
	EEDesc desc;
	desc.applicationName = L"Emerald";	//窗口名称
	desc.isFullScreen = false;			//是否全屏
	desc.width = 800;					//窗口宽度
	desc.height = 450;					//窗口高度
	desc.isSSAA = true;					//是开启抗锯齿
	desc.isVsync = false;				//是否垂直同步
	EEInitialize();

	// EETexture tex0(L"Texture\\etc\\101087.jpg");
	EETexture tex1(L"Texture/etc/xmyrz.jpg");
	EETexture tex1_gray = tex1.Clone();
	EEGrayC gray(tex1_gray);
	gray.Process();

	EEQuad2D quad(Rect_Float(0, 0, (float)EEGetWidth(), (float)EEGetHeight()), tex1);
	EEDilateC dilate(tex1, tex1_gray, INT2(2, 2));
	dilate.Process();
	EEErodeC erode(tex1, tex1_gray, INT2(2, 2));
	erode.Process();
	

	while (EERun())
	{
		EEBeginScene(EEColor::BLACK);

		quad.Process();

		printf("%d ", EEGetFPS());
		EEEndScene();
	}

	EEShutdown();
	return 0;
}
예제 #5
0
void DOFFilter::drawFullscreen() {
  mGlslProg->uniform("uRenderedTexture", 0);
  mGlslProg->uniform("uDepthTexture", 1);
  mGlslProg->uniform("uFocalDepth", mManualFocalDepth);
  mGlslProg->uniform("uMaxBlur", mMaxBlur * displayScale());
#ifdef ADVANCED_SHADER
  mGlslProg->uniform("uRenderedTextureWidth", (float)mSceneFBO->getWidth());
  mGlslProg->uniform("uRenderedTextureHeight", (float)mSceneFBO->getHeight());
  mGlslProg->uniform("uUseAutofocus", mUseAutofocus);
  mGlslProg->uniform("uAutofocusCenter", mAutofocusCenter);
  mGlslProg->uniform("uNumRings", mNumRings);
  mGlslProg->uniform("uNumSamples", mNumSamples);
  mGlslProg->uniform("uHighlightThreshold", mHighlightThreshold);
  mGlslProg->uniform("uHighlightGain", mHighlightGain);
  mGlslProg->uniform("uBokehEdgeBias", mBokehEdgeBias);
  mGlslProg->uniform("uBokehFringe", mBokehFringe);
  mGlslProg->uniform("uAperture", mAperture / displayScale());
#else
  mGlslProg->uniform("uAspectRatio", getWindowAspectRatio());
  mGlslProg->uniform("uAperture", mAperture / displayScale() / 15);
#endif

  gl::ScopedTextureBind tex0(mSceneFBO->getColorTexture(), 0);
  gl::ScopedTextureBind tex1(mSceneFBO->getDepthTexture(), 1);
  
  const gl::ScopedViewport scopedViewport(ivec2(0), toPixels(getWindowSize()));
  const gl::ScopedMatrices scopedMatrices;
  gl::setMatricesWindow(toPixels(getWindowSize()));
  gl::translate(toPixels(getWindowSize() / 2));
  gl::scale(toPixels(getWindowSize()));
  
  gl::disableDepthRead();
  gl::disableDepthWrite();

  gl::clear(Color::black());
  mQuadBatch->draw();
}
예제 #6
0
int main(int argc, const char * argv[]) {
  CommonSettings Settings;
  
  GLFWwindow *window = Settings.CreateWindow("EX_GS_T_1");
  if (window == nullptr) {
    std::cout << "Create window failed" << std::endl;
    glfwTerminate();
    return -1;
  }

  glfwSetKeyCallback(window, key_callback);
  glfwSetCursorPosCallback(window, mouse_callback);
  glfwSetScrollCallback(window, scroll_callback);

  cam.setFPS(GL_TRUE);
  
  GLfloat vertices[] = {
    0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
    0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
    -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
    0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
    -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
    -0.5f, 0.5f, 0.5f, 0.0f, 1.0f,

    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
    0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
    0.5f, 0.5f, 0.5f, 0.0f, 1.0f,

    -0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    -0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
    0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    -0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    0.5f, 0.5f, -0.5f, 0.0f, 1.0f,

    -0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
    -0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    -0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,

    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
    -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
    -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
    -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,

    0.5f, -0.5f, 0.5f, 1.0f, 1.0f,
    0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    0.5f, -0.5f, 0.5f, 1.0f, 1.0f,
    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
    -0.5f, -0.5f, 0.5f, 0.0f, 1.0f,
  };

  GLuint VAO, VBO, EBO;
  glGenVertexArrays(1, &VAO);
  glGenBuffers(1, &VBO);
  glGenBuffers(1, &EBO);
  
  glBindVertexArray(VAO);
  
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
  
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
  glEnableVertexAttribArray(1);
  
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glBindVertexArray(0);
  
#ifdef __APPLE__
  string path = "/Camera/1/";
#else
  string path = "\\Camera\\1\\";
#endif
  
  ShaderReader shader(Settings.CCExercisesPath(path + "EX_GS_C_1_Vertex.shader").c_str(), Settings.CCExercisesPath(path + "EX_GS_C_1_Fragment.shader").c_str());
  
  GLuint textures[2];
  TextureReader tex1(Settings.CCResourcesPath("container.jpg").c_str());
  textures[0] = tex1.getTexture();
  TextureReader tex2(Settings.CCResourcesPath("awesomeface.png").c_str());
  textures[1] = tex2.getTexture();

  glm::vec3 cubePositions[] = {
    glm::vec3(0.0f, 0.0f, 0.0f),
    glm::vec3(2.0f, 5.0f, -15.0f),
    glm::vec3(-1.5f, -2.2f, -2.5f),
    glm::vec3(-3.8f, -2.0f, -12.3f),
    glm::vec3(2.4f, -0.4f, -3.5f),
    glm::vec3(-1.7f, 3.0f, -7.5f),
    glm::vec3(1.3f, -2.0f, -2.5f),
    glm::vec3(1.5f, 2.0f, -2.5f),
    glm::vec3(1.5f, 0.2f, -1.5f),
    glm::vec3(-1.3f, 1.0f, -1.5f)
  };
  glm::mat4 modelMat;
  glm::mat4 viewMat;
  glm::mat4 projMat;

  GLint width, height;
  glfwGetFramebufferSize(window, &width, &height);

  shader.Use();
  GLint modelLoc = glGetUniformLocation(shader.GetProgram(), "modelMat");
  GLint viewLoc = glGetUniformLocation(shader.GetProgram(), "viewMat");
  GLint projLoc = glGetUniformLocation(shader.GetProgram(), "projMat");

  glEnable(GL_DEPTH_TEST);
  
  const GLchar* names[] = {
    "tex1", "tex2",
  };
  GLint texLocs[2];
  for (int i = 0; i < 2; i++) {
    texLocs[i] = glGetUniformLocation(shader.GetProgram(), names[i]);
  }
  
  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();
    
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    GLfloat currentTime = glfwGetTime();
    deltaTime = currentTime - lastTime;
    lastTime = currentTime;
    do_movement();

    shader.Use();
    for (int i = 0; i < 2; i++) {
      glActiveTexture(GL_TEXTURE0 + i);
      glBindTexture(GL_TEXTURE_2D, textures[i]);
      glUniform1i(texLocs[i], i);
    }

    glBindVertexArray(VAO);
    viewMat = cam.getViewMatrix();
    projMat = glm::perspective(cam.getZoom(), (GLfloat)width / height, 0.1f, 100.0f);
    for (int i = 0; i < 10; i++) {
      modelMat = glm::mat4();
      modelMat = glm::translate(modelMat, cubePositions[i]);
      modelMat = glm::rotate(modelMat, glm::radians(currentTime * -90.0f), glm::vec3(0.5f, 1.0f, -0.5f));
      glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(modelMat));
      glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(viewMat));
      glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projMat));
      glDrawArrays(GL_TRIANGLES, 0, 36);
    }

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindVertexArray(0);
    
    glfwSwapBuffers(window);
  }
  
  return 0;
}
예제 #7
0
int main(int argc, const char * argv[]) {
  CommonSettings Settings;
  
  GLFWwindow *window = Settings.CreateWindow("EX_GS_T_1");
  if (window == nullptr) {
    std::cout << "Create window failed" << std::endl;
    glfwTerminate();
    return -1;
  }
  
  GLfloat vertices[] = {
    0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
    0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
    -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
    -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
  };
  GLuint indices[] = {
    0, 1, 2,
    0, 2, 3,
  };
  GLuint VAO, VBO, EBO;
  glGenVertexArrays(1, &VAO);
  glGenBuffers(1, &VBO);
  glGenBuffers(1, &EBO);
  
  glBindVertexArray(VAO);
  
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
  
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
  glEnableVertexAttribArray(1);
  
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
  
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glBindVertexArray(0);

  
#ifdef __APPLE__
  string path = "/Transformations/2/";
#else
  string path = "\\Transformations\\2\\";
#endif
  
  ShaderReader shader(Settings.CCExercisesPath(path + "EX_GS_T_2_Vertex.shader").c_str(), Settings.CCExercisesPath(path + "EX_GS_T_2_Fragment.shader").c_str());
  
  GLuint textures[2];
  TextureReader tex1(Settings.CCResourcesPath("container.jpg").c_str());
  textures[0] = tex1.getTexture();
  TextureReader tex2(Settings.CCResourcesPath("awesomeface.png").c_str());
  textures[1] = tex2.getTexture();
  
  const GLchar* names[] = {
    "tex1", "tex2",
  };
  
  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();
    
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    
    for (int i = 0; i < 2; i++) {
      glActiveTexture(GL_TEXTURE0 + i);
      glBindTexture(GL_TEXTURE_2D, textures[i]);
      glUniform1i(glGetUniformLocation(shader.GetProgram(), names[i]), i);
      
    }

    shader.Use();

    glm::mat4 trans;
    trans = glm::translate(trans, glm::vec3(-0.5f, 0.5f, 0.0f));
    trans = glm::scale(trans, glm::vec3(sin(glfwGetTime()), sin(glfwGetTime()), 1.0f));
    glUniformMatrix4fv(glGetUniformLocation(shader.GetProgram(), "transform"), 1, GL_FALSE, glm::value_ptr(trans));
    
    glBindVertexArray(VAO);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
    
    trans = glm::mat4();
    trans = glm::translate(trans, glm::vec3(0.5f, -0.5f, 0.0f));
    trans = glm::rotate(trans, glm::radians((float)glfwGetTime() * 90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
    glUniformMatrix4fv(glGetUniformLocation(shader.GetProgram(), "transform"), 1, GL_FALSE, glm::value_ptr(trans));
    
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
    
    glBindTexture(GL_TEXTURE_2D, 0);
    glBindVertexArray(0);
    
    glfwSwapBuffers(window);
  }
  
  return 0;
}
예제 #8
0
   bool corpus_tester::test(const char* pCmd_line)
   {
      console::printf("Command line:\n\"%s\"", pCmd_line);

      static const command_line_params::param_desc param_desc_array[] = 
      {
         { "corpus_test", 0, false },
         { "in", 1, true },
         { "deep", 0, false },
         { "alpha", 0, false },
         { "nomips", 0, false },
         { "perceptual", 0, false },
         { "endpointcaching", 0, false },
         { "multithreaded", 0, false },
         { "writehybrid", 0, false },
         { "nobadblocks", 0, false },
      };

      command_line_params cmd_line_params;
      if (!cmd_line_params.parse(pCmd_line, CRNLIB_ARRAY_SIZE(param_desc_array), param_desc_array, true))
         return false;

      double total_time1 = 0, total_time2 = 0;

      command_line_params::param_map_const_iterator it = cmd_line_params.begin();
      for ( ; it != cmd_line_params.end(); ++it)
      {
         if (it->first != "in")
            continue;
         if (it->second.m_values.empty())
         {
            console::error("Must follow /in parameter with a filename!\n");
            return false;
         }

         for (uint in_value_index = 0; in_value_index < it->second.m_values.size(); in_value_index++)
         {
            const dynamic_string& filespec = it->second.m_values[in_value_index];

            find_files file_finder;
            if (!file_finder.find(filespec.get_ptr(), find_files::cFlagAllowFiles | (cmd_line_params.has_key("deep") ? find_files::cFlagRecursive : 0)))
            {
               console::warning("Failed finding files: %s", filespec.get_ptr());
               continue;
            }

            if (file_finder.get_files().empty())
            {
               console::warning("No files found: %s", filespec.get_ptr());
               return false;
            }

            const find_files::file_desc_vec& files = file_finder.get_files();

            image_u8 o(4, 4), a(4, 4), b(4, 4);

            uint first_channel = 0;
            uint num_channels = 3;
            bool perceptual = cmd_line_params.get_value_as_bool("perceptual", false);
            if (perceptual)
            {
               first_channel = 0;
               num_channels = 0;
            }
            console::printf("Perceptual mode: %u", perceptual);

            for (uint file_index = 0; file_index < files.size(); file_index++)
            {
               const find_files::file_desc& file_desc = files[file_index];

               console::printf("-------- Loading image: %s", file_desc.m_fullname.get_ptr());

               image_u8 img;
               if (!image_utils::read_from_file(img, file_desc.m_fullname.get_ptr(), 0))
               {
                  console::warning("Failed loading image file: %s", file_desc.m_fullname.get_ptr());
                  continue;
               }

               if ((!cmd_line_params.has_key("alpha")) && img.is_component_valid(3))
               {
                  for (uint y = 0; y < img.get_height(); y++)
                     for (uint x = 0; x < img.get_width(); x++)
                        img(x, y).a = 255;

                  img.set_component_valid(3, false);
               }

               mipmapped_texture orig_tex;
               orig_tex.assign(crnlib_new<image_u8>(img));

               if (!cmd_line_params.has_key("nomips"))
               {
                  mipmapped_texture::generate_mipmap_params genmip_params;
                  genmip_params.m_srgb = true;

                  console::printf("Generating mipmaps");

                  if (!orig_tex.generate_mipmaps(genmip_params, false))
                  {
                     console::error("Mipmap generation failed!");
                     return false;
                  }
               }               

               console::printf("Compress 1");

               mipmapped_texture tex1(orig_tex);
               dxt_image::pack_params convert_params;
               convert_params.m_endpoint_caching = cmd_line_params.get_value_as_bool("endpointcaching", 0, false);
               convert_params.m_compressor = cCRNDXTCompressorCRN;
               convert_params.m_quality = cCRNDXTQualityNormal;
               convert_params.m_perceptual = perceptual;
               convert_params.m_num_helper_threads = cmd_line_params.get_value_as_bool("multithreaded", 0, true) ? (g_number_of_processors - 1) : 0;
               convert_params.m_pProgress_callback = progress_callback;
               timer t;
               t.start();
               if (!tex1.convert(PIXEL_FMT_ETC1, false, convert_params))
               {
                  console::error("Texture conversion failed!");
                  return false;
               }
               double time1 = t.get_elapsed_secs();
               total_time1 += time1;
               console::printf("Elapsed time: %3.3f", time1);

               console::printf("Compress 2");

               mipmapped_texture tex2(orig_tex);
               convert_params.m_endpoint_caching = false;
               convert_params.m_compressor = cCRNDXTCompressorCRN;
               convert_params.m_quality = cCRNDXTQualitySuperFast;
               t.start();
               if (!tex2.convert(PIXEL_FMT_ETC1, false, convert_params))
               {
                  console::error("Texture conversion failed!");
                  return false;
               }
               double time2 = t.get_elapsed_secs();
               total_time2 += time2;
               console::printf("Elapsed time: %3.3f", time2);

               image_u8 hybrid_img(img.get_width(), img.get_height());

               for (uint l = 0; l < orig_tex.get_num_levels(); l++)
               {
                  image_u8 orig_img, img1, img2;

                  image_u8* pOrig = orig_tex.get_level(0, l)->get_unpacked_image(orig_img, cUnpackFlagUncook | cUnpackFlagUnflip);
                  image_u8* pImg1 = tex1.get_level(0, l)->get_unpacked_image(img1, cUnpackFlagUncook | cUnpackFlagUnflip);
                  image_u8* pImg2 = tex2.get_level(0, l)->get_unpacked_image(img2, cUnpackFlagUncook | cUnpackFlagUnflip);

                  const uint num_blocks_x = pOrig->get_block_width(4);
                  const uint num_blocks_y = pOrig->get_block_height(4);

                  crnlib::vector<image_utils::error_metrics> metrics[2];

                  for (uint by = 0; by < num_blocks_y; by++)
                  {
                     for (uint bx = 0; bx < num_blocks_x; bx++)
                     {
                        pOrig->extract_block(o.get_ptr(), bx * 4, by * 4, 4, 4);
                        pImg1->extract_block(a.get_ptr(), bx * 4, by * 4, 4, 4);
                        pImg2->extract_block(b.get_ptr(), bx * 4, by * 4, 4, 4);

                        image_utils::error_metrics em1;
                        em1.compute(o, a, first_channel, num_channels);

                        image_utils::error_metrics em2;
                        em2.compute(o, b, first_channel, num_channels);

                        metrics[0].push_back(em1);
                        metrics[1].push_back(em2);

                        if (em1.mPeakSNR < em2.mPeakSNR)
                        {
                           add_bad_block(o);

                           hybrid_img.blit(bx * 4, by * 4, b);
                        }
                        else
                        {
                           hybrid_img.blit(bx * 4, by * 4, a);
                        }
                     }
                  }

                  if (cmd_line_params.has_key("writehybrid"))
                     image_utils::write_to_file("hybrid.tga", hybrid_img, image_utils::cWriteFlagIgnoreAlpha);

                  console::printf("---- Mip level: %u, Total blocks: %ux%u, %u", l, num_blocks_x, num_blocks_y, num_blocks_x * num_blocks_y);

                  console::printf("Compressor 1:");
                  print_metric_stats(metrics[0], num_blocks_x, num_blocks_y);

                  console::printf("Compressor 2:");
                  print_metric_stats(metrics[1], num_blocks_x, num_blocks_y);

                  console::printf("Compressor 1 vs. 2:");
                  print_comparative_metric_stats(cmd_line_params, metrics[0], metrics[1], num_blocks_x, num_blocks_y);

                  image_utils::error_metrics em;

                  em.compute(*pOrig, *pImg1, 0, perceptual ? 0 : 3);
                  em.print("Compressor 1: ");

                  em.compute(*pOrig, *pImg2, 0, perceptual ? 0 : 3);
                  em.print("Compressor 2: ");

                  em.compute(*pOrig, hybrid_img, 0, perceptual ? 0 : 3);
                  em.print("Best of Both: ");
               }
            }

         }  // file_index
      } 

      flush_bad_blocks();

      console::printf("Total times: %4.3f vs. %4.3f", total_time1, total_time2);

      return true;
   }
예제 #9
0
C3DOTextureHandler::C3DOTextureHandler()
{
	std::vector<TexFile*> texfiles = LoadTexFiles();

	// TODO: make this use TextureAtlas directly
	CTextureAtlas atlas;
	atlas.SetName("3DOModelTextureAtlas");

	IAtlasAllocator* atlasAlloc = atlas.GetAllocator();

	// NOTE: most Intels report maxTextureSize=2048, some even 1024 (!)
	atlasAlloc->SetNonPowerOfTwo(globalRendering->supportNPOTs);
	atlasAlloc->SetMaxSize(std::min(globalRendering->maxTextureSize, 2048), std::min(globalRendering->maxTextureSize, 2048));

	// default for 3DO primitives that point to non-existing textures
	textures["___dummy___"] = UnitTexture(0.0f, 0.0f, 1.0f, 1.0f);

	for (std::vector<TexFile*>::iterator it = texfiles.begin(); it != texfiles.end(); ++it) {
		atlasAlloc->AddEntry((*it)->name, int2((*it)->tex.xsize, (*it)->tex.ysize));
	}

	const bool allocated = atlasAlloc->Allocate();
	const int2 curAtlasSize = atlasAlloc->GetAtlasSize();
	const int2 maxAtlasSize = atlasAlloc->GetMaxSize();

	if (!allocated) {
		// either the algorithm simply failed to fit all
		// textures or the textures would really not fit
		LOG_L(L_WARNING,
			"[%s] failed to allocate 3DO texture-atlas memory (size=%dx%d max=%dx%d)",
			__FUNCTION__,
			curAtlasSize.x, curAtlasSize.y,
			maxAtlasSize.x, maxAtlasSize.y
		);
		return;
	} else {
		assert(curAtlasSize.x <= maxAtlasSize.x);
		assert(curAtlasSize.y <= maxAtlasSize.y);
	}

	unsigned char* bigtex1 = new unsigned char[curAtlasSize.x * curAtlasSize.y * 4];
	unsigned char* bigtex2 = new unsigned char[curAtlasSize.x * curAtlasSize.y * 4];

	for (int a = 0; a < (curAtlasSize.x * curAtlasSize.y); ++a) {
		bigtex1[a*4 + 0] = 128;
		bigtex1[a*4 + 1] = 128;
		bigtex1[a*4 + 2] = 128;
		bigtex1[a*4 + 3] = 0;

		bigtex2[a*4 + 0] = 0;
		bigtex2[a*4 + 1] = 128;
		bigtex2[a*4 + 2] = 0;
		bigtex2[a*4 + 3] = 255;
	}

	for (std::vector<TexFile*>::iterator it = texfiles.begin(); it != texfiles.end(); ++it) {
		CBitmap& curtex1 = (*it)->tex;
		CBitmap& curtex2 = (*it)->tex2;

		const size_t foundx = atlasAlloc->GetEntry((*it)->name).x;
		const size_t foundy = atlasAlloc->GetEntry((*it)->name).y;
		const float4 texCoords = atlasAlloc->GetTexCoords((*it)->name);

		for (int y = 0; y < curtex1.ysize; ++y) {
			for (int x = 0; x < curtex1.xsize; ++x) {
				for (int col = 0; col < 4; ++col) {
					bigtex1[(((foundy + y) * curAtlasSize.x + (foundx + x)) * 4) + col] = curtex1.mem[(((y * curtex1.xsize) + x) * 4) + col];
					bigtex2[(((foundy + y) * curAtlasSize.x + (foundx + x)) * 4) + col] = curtex2.mem[(((y * curtex1.xsize) + x) * 4) + col];
				}
			}
		}

		textures[(*it)->name] = UnitTexture(texCoords);

		delete (*it);
	}

	const int maxMipMaps = atlasAlloc->GetMaxMipMaps();

	{
		glGenTextures(1, &atlas3do1);
		glBindTexture(GL_TEXTURE_2D, atlas3do1);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (maxMipMaps > 0) ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,  maxMipMaps);
		if (maxMipMaps > 0) {
			glBuildMipmaps(GL_TEXTURE_2D, GL_RGBA8, curAtlasSize.x, curAtlasSize.y, GL_RGBA, GL_UNSIGNED_BYTE, bigtex1); //FIXME disable texcompression
		} else {
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, curAtlasSize.x, curAtlasSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bigtex1);
		}
	}
	{
		glGenTextures(1, &atlas3do2);
		glBindTexture(GL_TEXTURE_2D, atlas3do2);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (maxMipMaps > 0) ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,  maxMipMaps);
		if (maxMipMaps > 0) {
			glBuildMipmaps(GL_TEXTURE_2D, GL_RGBA8, curAtlasSize.x, curAtlasSize.y, GL_RGBA, GL_UNSIGNED_BYTE, bigtex2); //FIXME disable texcompression
		} else {
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, curAtlasSize.x, curAtlasSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bigtex2);
		}
	}

	if (CTextureAtlas::GetDebug()) {
		CBitmap tex1(bigtex1, curAtlasSize.x, curAtlasSize.y);
		CBitmap tex2(bigtex2, curAtlasSize.x, curAtlasSize.y);

		tex1.Save(atlas.GetName() + "-1-" + IntToString(curAtlasSize.x) + "x" + IntToString(curAtlasSize.y) + ".png");
		tex2.Save(atlas.GetName() + "-2-" + IntToString(curAtlasSize.x) + "x" + IntToString(curAtlasSize.y) + ".png");
	}

	delete[] bigtex1;
	delete[] bigtex2;
}