View.mm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #import "View.h"
  16. /*
  17. ================================================
  18. idView
  19. Standard Objective C UIView Class
  20. ================================================
  21. */
  22. idView * gMainView; // global openGL View.
  23. @implementation idView
  24. /*
  25. ==================================
  26. idView::layerClass
  27. ==================================
  28. */
  29. + (Class) layerClass
  30. {
  31. return [CAEAGLLayer class];
  32. }
  33. /*
  34. ==================================
  35. idView::initWithCoder
  36. ==================================
  37. */
  38. - (id) initWithCoder:(NSCoder *)aCoder{
  39. if ( ( self = [super initWithCoder:aCoder] ) ) {
  40. [self Initialize];
  41. }
  42. return self;
  43. }
  44. /*
  45. ==================================
  46. idView::initWithFrame
  47. ==================================
  48. */
  49. - (id) initWithFrame:(CGRect)rect{
  50. if ( ( self = [super initWithFrame:rect] ) ) {
  51. [self Initialize];
  52. }
  53. return self;
  54. }
  55. /*
  56. ==================================
  57. idView::handleTouches
  58. ==================================
  59. */
  60. - (void) handleTouches:(UIEvent*)event {
  61. (void)event;
  62. }
  63. /*
  64. ==================================
  65. idView::touchesBegan
  66. ==================================
  67. */
  68. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
  69. (void)touches;
  70. [self handleTouches:event];
  71. }
  72. /*
  73. ==================================
  74. idView::touchesMoved
  75. ==================================
  76. */
  77. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  78. (void)touches;
  79. [self handleTouches:event];
  80. }
  81. /*
  82. ==================================
  83. idView::touchesEnded
  84. ==================================
  85. */
  86. - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
  87. (void)touches;
  88. [self handleTouches:event];
  89. }
  90. /*
  91. ==================================
  92. idView::touchesCancelled
  93. ==================================
  94. */
  95. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  96. (void)touches;
  97. [self handleTouches:event];
  98. }
  99. /*
  100. ==================================
  101. idView::Initialize
  102. ==================================
  103. */
  104. - (void) Initialize {
  105. self.multipleTouchEnabled = YES;
  106. gMainView = self;
  107. // Double the resolution on iPhone 4.
  108. [self setContentScaleFactor:[UIScreen mainScreen].scale];
  109. // Get the layer for this view
  110. CAEAGLLayer *glLayer = (CAEAGLLayer *)self.layer;
  111. glLayer.opaque = TRUE;
  112. glLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
  113. [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
  114. kEAGLColorFormatRGB565,
  115. kEAGLDrawablePropertyColorFormat, nil];
  116. // Create Our Render Context.
  117. mRenderContext.Initialize( kEAGLRenderingAPIOpenGLES1, NULL );
  118. // Create our Frame Buffers.
  119. mRenderContext.InitFrameBuffer( glLayer );
  120. }
  121. /*
  122. ==================================
  123. idView::EndFrame
  124. ==================================
  125. */
  126. - (void) EndFrame {
  127. mRenderContext.SwapBuffers();
  128. }
  129. @end