Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EAGLView.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5d01fc5a61cee6aa92ef9c0e850ab66b7c6fda0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>

#import "EAGLView.h"
#import "WindowHandle.h"

#include "../../yg/screen.hpp"
#include "../../yg/texture.hpp"
#include "../../yg/resource_manager.hpp"
#include "../../yg/internal/opengl.hpp"
#include "../../yg/skin.hpp"
#include "IPhonePlatform.hpp"
#include "RenderBuffer.hpp"
#include "RenderContext.hpp"

// A class extension to declare private methods
@interface EAGLView ()

@end

@implementation EAGLView

@synthesize controller;
@synthesize windowHandle;
@synthesize renderContext;
@synthesize resourceManager;

// 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();

    // to avoid grid bug on 3G device
    yg::RtFormat fmt = yg::Rt4Bpp;
    if ([[NSString stringWithFormat:@"%s", glGetString(GL_RENDERER)] hasPrefix:@"PowerVR MBX"])
      fmt = yg::Rt8Bpp;
    
    /// 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];

    int etalonW = 320;
    int scrW = etalonW;

    UIDevice * device = [UIDevice currentDevice];

    float ver = [device.systemVersion floatValue];
    NSLog(@"%@", device.systemVersion);
    /// rounding problems
    if (ver >= 3.199)
    {
      UIScreen * mainScr = [UIScreen mainScreen];
      scrW = mainScr.currentMode.size.width;
      if (scrW == 640)
        self.contentScaleFactor = 2.0;
    }

    frameBuffer = shared_ptr<yg::gl::FrameBuffer>(new yg::gl::FrameBuffer());

    int bigVBSize = pow(2, ceil(log2(15000 * sizeof(yg::gl::Vertex))));
    int bigIBSize = pow(2, ceil(log2(30000 * sizeof(unsigned short))));

    int smallVBSize = pow(2, ceil(log2(1500 * sizeof(yg::gl::Vertex))));
    int smallIBSize = pow(2, ceil(log2(3000 * sizeof(unsigned short))));
    
    int blitVBSize = pow(2, ceil(log2(10 * sizeof(yg::gl::AuxVertex))));
    int blitIBSize = pow(2, ceil(log2(10 * sizeof(unsigned short))));

    NSLog(@"Vendor: %s, Renderer: %s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
    
    Platform & pl = GetPlatform();
    
    resourceManager = shared_ptr<yg::ResourceManager>(new yg::ResourceManager(
          bigVBSize, bigIBSize, 6 * GetPlatform().CpuCores(),
          smallVBSize, smallIBSize, 15 * GetPlatform().CpuCores(),
          blitVBSize, blitIBSize, 15 * GetPlatform().CpuCores(),
          512, 256, 10 * GetPlatform().CpuCores(),
          512, 256, 10 * GetPlatform().CpuCores(),
          GetPlatform().TileSize(),
          GetPlatform().TileSize(),
          GetPlatform().MaxTilesCount(),
					"unicode_blocks.txt",
					"fonts_whitelist.txt",
 					"fonts_blacklist.txt",
          1.5 * 1024 * 1024,
          GetPlatform().CpuCores() + 1,
          fmt,
          !yg::gl::g_isBufferObjectsSupported));
    
    Platform::FilesList fonts;
    pl.GetFontNames(fonts);
		resourceManager->addFonts(fonts);

		DrawerYG::params_t p;
		p.m_resourceManager = resourceManager;
    p.m_frameBuffer = frameBuffer;
    p.m_glyphCacheID = resourceManager->guiThreadGlyphCacheID();

		drawer = shared_ptr<DrawerYG>(new DrawerYG(pl.SkinName(), p));

//		frameBuffer->onSize(renderBuffer->width(), renderBuffer->height());
//		frameBuffer->setRenderTarget(renderBuffer);

		windowHandle = shared_ptr<iphone::WindowHandle>(new iphone::WindowHandle(self));
		windowHandle->setDrawer(drawer);
		windowHandle->setRenderContext(renderContext);
  }

  self.multipleTouchEnabled = YES;

  return self;
}

- (void)onSize:(int)width withHeight:(int)height
{
	/// free old video memory
	frameBuffer->resetRenderTarget();
	renderBuffer.reset();

	/// allocate the new one
	renderBuffer = shared_ptr<iphone::RenderBuffer>(new iphone::RenderBuffer(renderContext, (CAEAGLLayer*)self.layer));
	frameBuffer->setRenderTarget(renderBuffer);
	frameBuffer->onSize(width, height);
	drawer->onSize(width, height);

  
  drawer->screen()->beginFrame();
  drawer->screen()->clear();
  drawer->screen()->endFrame();
  
}

- (void)drawView
{
	[controller onPaint];
	renderBuffer->present();
}

- (void)drawViewThunk:(id)obj
{
	[self drawView];
}

- (void)drawViewOnMainThread
{
	[self performSelectorOnMainThread:@selector(drawViewThunk:) withObject:nil waitUntilDone:NO];
}

- (void)layoutSubviews
{
  CGFloat scaleFactor = 1.0;
  if ([self respondsToSelector:@selector(contentScaleFactor)])
  	scaleFactor = self.contentScaleFactor;

	[[self controller] onResize:self.frame.size.width * scaleFactor withHeight:self.frame.size.height * scaleFactor];
	[self onSize:self.frame.size.width * scaleFactor withHeight:self.frame.size.height * scaleFactor];
	// This crashes on iPad: [self drawView];
}

- (void)dealloc
{
  [EAGLContext setCurrentContext:nil];
  [super dealloc];
}


@end