<commit_before>#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>

#import "EAGLView.h"

#include "../../yg/screen.hpp"
#include "../../yg/texture.hpp"
#include "../../yg/resource_manager.hpp"
#include "../../yg/internal/opengl.hpp"
#include "../../yg/skin.hpp"
#include "../../map/render_policy.hpp"
#include "../../platform/platform.hpp"
#include "../../platform/video_timer.hpp"
#include "RenderBuffer.hpp"
#include "RenderContext.hpp"
#include "Framework.h"

@implementation EAGLView

@synthesize videoTimer;
@synthesize frameBuffer;
@synthesize renderContext;
@synthesize renderBuffer;
@synthesize renderPolicy;

// You must implement this method
+ (Class)layerClass
{
  return [CAEAGLLayer class];
}

// The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder
{
  if ((self = [super initWithCoder:coder]))
  {
    // Setup Layer Properties
    CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer;

    eaglLayer.opaque = YES;

    renderContext = shared_ptr<iphone::RenderContext>(new iphone::RenderContext());

    if (!renderContext.get())
    {
      [self release];
      return nil;
    }
    
    renderContext->makeCurrent();
    
    // ColorFormat : RGB565
    // Backbuffer : YES, (to prevent from loosing content when mixing with ordinary layers).
    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:NO],
                                    kEAGLDrawablePropertyRetainedBacking,
                                    kEAGLColorFormatRGB565,
                                    kEAGLDrawablePropertyColorFormat,
                                    nil];
    // Correct retina display support in opengl renderbuffer
    self.contentScaleFactor = [[UIScreen mainScreen] scale];
  }
  
  return self;
}

- (void)initRenderPolicy
{
  // to avoid grid bug on 3G device
  yg::DataFormat rtFmt = yg::Data4Bpp;
  yg::DataFormat texFmt = yg::Data4Bpp;
  if ([[NSString stringWithFormat:@"%s", glGetString(GL_RENDERER)] hasPrefix:@"PowerVR MBX"])
    rtFmt = yg::Data8Bpp;
  
  typedef void (*drawFrameFn)(id, SEL);
  SEL drawFrameSel = @selector(drawFrame);
  drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel];

  videoTimer = CreateIOSVideoTimer(bind(drawFrameImpl, self, drawFrameSel));
  
  yg::ResourceManager::Params rmParams;
  rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit();
  rmParams.m_rtFormat = rtFmt;
  rmParams.m_texFormat = texFmt;
  
  RenderPolicy::Params rpParams;
  
  CGRect screenRect = [[UIScreen mainScreen] bounds];
    
  rpParams.m_screenWidth = screenRect.size.width;
  rpParams.m_screenHeight = screenRect.size.height;
    
  rpParams.m_visualScale = [[UIScreen mainScreen] scale];
  if (rpParams.m_visualScale > 1.0)<commit_msg>correct support for retina displays.<commit_after>#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>

#import "EAGLView.h"

#include "../../yg/screen.hpp"
#include "../../yg/texture.hpp"
#include "../../yg/resource_manager.hpp"
#include "../../yg/internal/opengl.hpp"
#include "../../yg/skin.hpp"
#include "../../map/render_policy.hpp"
#include "../../platform/platform.hpp"
#include "../../platform/video_timer.hpp"
#include "RenderBuffer.hpp"
#include "RenderContext.hpp"
#include "Framework.h"

@implementation EAGLView

@synthesize videoTimer;
@synthesize frameBuffer;
@synthesize renderContext;
@synthesize renderBuffer;
@synthesize renderPolicy;

// You must implement this method
+ (Class)layerClass
{
  return [CAEAGLLayer class];
}

// The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder
{
  if ((self = [super initWithCoder:coder]))
  {
    // Setup Layer Properties
    CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer;

    eaglLayer.opaque = YES;

    renderContext = shared_ptr<iphone::RenderContext>(new iphone::RenderContext());

    if (!renderContext.get())
    {
      [self release];
      return nil;
    }
    
    renderContext->makeCurrent();
    
    // ColorFormat : RGB565
    // Backbuffer : YES, (to prevent from loosing content when mixing with ordinary layers).
    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:NO],
                                    kEAGLDrawablePropertyRetainedBacking,
                                    kEAGLColorFormatRGB565,
                                    kEAGLDrawablePropertyColorFormat,
                                    nil];
    // Correct retina display support in opengl renderbuffer
    self.contentScaleFactor = [[UIScreen mainScreen] scale];
  }
  
  return self;
}

- (void)initRenderPolicy
{
  // to avoid grid bug on 3G device
  yg::DataFormat rtFmt = yg::Data4Bpp;
  yg::DataFormat texFmt = yg::Data4Bpp;
  if ([[NSString stringWithFormat:@"%s", glGetString(GL_RENDERER)] hasPrefix:@"PowerVR MBX"])
    rtFmt = yg::Data8Bpp;
  
  typedef void (*drawFrameFn)(id, SEL);
  SEL drawFrameSel = @selector(drawFrame);
  drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel];

  videoTimer = CreateIOSVideoTimer(bind(drawFrameImpl, self, drawFrameSel));
  
  yg::ResourceManager::Params rmParams;
  rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit();
  rmParams.m_rtFormat = rtFmt;
  rmParams.m_texFormat = texFmt;
  
  RenderPolicy::Params rpParams;
  
  CGRect screenRect = [[UIScreen mainScreen] bounds];
  
  rpParams.m_visualScale = [[UIScreen mainScreen] scale];
    
  rpParams.m_screenWidth = screenRect.size.width * rpParams.m_visualScale;
  rpParams.m_screenHeight = screenRect.size.height * rpParams.m_visualScale;
  
  if (rpParams.m_visualScale > 1.0)
{'fraction_non_alphanumeric': 0.1230267673301304, 'fraction_numerical': 0.004118050789293068, 'mean_word_length': 3.25164113785558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7565559', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1835, 'n_words': 379}