| 57 | |
| 58 | |
| 59 | uint Identify::ObjectInRectangle(const Box &rectangle, |
| 60 | uint *handlePtr, |
| 61 | uint *characterPtr, |
| 62 | uint *childPtr, |
| 63 | uint *parentPtr) |
| 64 | // ---------------------------------------------------------------------------- |
| 65 | // Find the top-most object in the given box, return # of objects |
| 66 | // ---------------------------------------------------------------------------- |
| 67 | { |
| 68 | // Create the select buffer and switch to select mode |
| 69 | GLuint capacity = widget->selectionCapacity(); |
| 70 | GLuint selected = 0; |
| 71 | GLuint handleId = 0; |
| 72 | GLuint charSelected = 0; |
| 73 | GLuint childSelected = 0; |
| 74 | GLuint parentId = 0; |
| 75 | int hits = 0; |
| 76 | |
| 77 | widget->stats.begin(Statistics::SELECT); |
| 78 | |
| 79 | GLuint *buffer = new GLuint[capacity]; |
| 80 | memset(buffer, 0, capacity * sizeof(GLuint)); |
| 81 | GL.SelectBuffer(capacity, buffer); |
| 82 | GL.RenderMode(GL_SELECT); |
| 83 | |
| 84 | // Adjust viewport for rendering |
| 85 | widget->setup(widget->width(), widget->height(), &rectangle); |
| 86 | |
| 87 | // Initialize names |
| 88 | GL.InitNames(); |
| 89 | |
| 90 | // Draw the items in "Identity" mode (simplified drawing) |
| 91 | widget->identifySelection(); |
| 92 | |
| 93 | // Get number of hits and extract selection |
| 94 | // Each record is as follows: |
| 95 | // [0]: Depth of the name stack |
| 96 | // [1]: Minimum depth |
| 97 | // [2]: Maximum depth |
| 98 | // [3..3+[0]-1]: List of names |
| 99 | |
| 100 | hits = GL.RenderMode(GL_RENDER); |
| 101 | if (hits > 0) |
| 102 | { |
| 103 | GLuint depth = ~0U; |
| 104 | GLuint *ptr = buffer; |
| 105 | for (int i = 0; i < hits && !handleId; i++) |
| 106 | { |
| 107 | uint size = ptr[0]; |
| 108 | GLuint *selPtr = ptr + 3; |
| 109 | GLuint *selNext = selPtr + size; |
| 110 | |
| 111 | if ((*selPtr & Widget::SELECTION_MASK) && ptr[1] <= depth) |
| 112 | { |
| 113 | depth = ptr[1]; |
| 114 | childSelected = false; |
| 115 | |
| 116 | IFTRACE(selection) |
nothing calls this directly
no test coverage detected